mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-03 01:09:39 +01:00
188fce6c9b
Changes: - Add connectNow() public method to trigger a connection immediately. - Remove the "skipping" when no data to send. - Change the default interval to 60 sec. - Fix resetting the next connection time when changing the interval. See #25073. Built from https://develop.svn.wordpress.org/trunk@26169 git-svn-id: http://core.svn.wordpress.org/trunk@26078 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
function array_unique_noempty(a){var b=[];return jQuery.each(a,function(a,c){c=jQuery.trim(c),c&&-1==jQuery.inArray(c,b)&&b.push(c)}),b}var tagBox,commentsBox,editPermalink,makeSlugeditClickable,WPSetThumbnailHTML,WPSetThumbnailID,WPRemoveThumbnail,wptitlehint;!function(a){tagBox={clean:function(a){var b=postL10n.comma;return","!==b&&(a=a.replace(new RegExp(b,"g"),",")),a=a.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,""),","!==b&&(a=a.replace(/,/g,b)),a},parseTags:function(b){var c=b.id,d=c.split("-check-num-")[1],e=a(b).closest(".tagsdiv"),f=e.find(".the-tags"),g=postL10n.comma,h=f.val().split(g),i=[];return delete h[d],a.each(h,function(b,c){c=a.trim(c),c&&i.push(c)}),f.val(this.clean(i.join(g))),this.quickClicks(e),!1},quickClicks:function(b){var c,d,e=a(".the-tags",b),f=a(".tagchecklist",b),g=a(b).attr("id");e.length&&(d=e.prop("disabled"),c=e.val().split(postL10n.comma),f.empty(),a.each(c,function(b,c){var e,h;c=a.trim(c),c&&(e=a("<span />").text(c),d||(h=a('<a id="'+g+"-check-num-"+b+'" class="ntdelbutton">X</a>'),h.click(function(){tagBox.parseTags(this)}),e.prepend(" ").prepend(h)),f.append(e))}))},flushTags:function(b,c,d){c=c||!1;var e,f,g=a(".the-tags",b),h=a("input.newtag",b),i=postL10n.comma;return f=c?a(c).text():h.val(),tagsval=g.val(),e=tagsval?tagsval+i+f:f,e=this.clean(e),e=array_unique_noempty(e.split(i)).join(i),g.val(e),this.quickClicks(b),c||h.val(""),"undefined"==typeof d&&h.focus(),!1},get:function(b){var c=b.substr(b.indexOf("-")+1);a.post(ajaxurl,{action:"get-tagcloud",tax:c},function(d,e){(0==d||"success"!=e)&&(d=wpAjax.broken),d=a('<p id="tagcloud-'+c+'" class="the-tagcloud">'+d+"</p>"),a("a",d).click(function(){return tagBox.flushTags(a(this).closest(".inside").children(".tagsdiv"),this),!1}),a("#"+b).after(d)})},init:function(){var b=this,c=a("div.ajaxtag");a(".tagsdiv").each(function(){tagBox.quickClicks(this)}),a("input.tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))}),a("div.taghint",c).click(function(){a(this).css("visibility","hidden").parent().siblings(".newtag").focus()}),a("input.newtag",c).blur(function(){""==this.value&&a(this).parent().siblings(".taghint").css("visibility","")}).focus(function(){a(this).parent().siblings(".taghint").css("visibility","hidden")}).keyup(function(b){return 13==b.which?(tagBox.flushTags(a(this).closest(".tagsdiv")),!1):void 0}).keypress(function(a){return 13==a.which?(a.preventDefault(),!1):void 0}).each(function(){var b=a(this).closest("div.tagsdiv").attr("id");a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:!0,multipleSep:postL10n.comma+" "})}),a("#post").submit(function(){a("div.tagsdiv").each(function(){tagBox.flushTags(this,!1,1)})}),a("a.tagcloud-link").click(function(){return tagBox.get(a(this).attr("id")),a(this).unbind().click(function(){return a(this).siblings(".the-tagcloud").toggle(),!1}),!1})}},commentsBox={st:0,get:function(b,c){var d,e=this.st;return c||(c=20),this.st+=c,this.total=b,a("#commentsdiv .spinner").show(),d={action:"get-comments",mode:"single",_ajax_nonce:a("#add_comment_nonce").val(),p:a("#post_ID").val(),start:e,number:c},a.post(ajaxurl,d,function(b){return b=wpAjax.parseAjaxResponse(b),a("#commentsdiv .widefat").show(),a("#commentsdiv .spinner").hide(),"object"==typeof b&&b.responses[0]?(a("#the-comment-list").append(b.responses[0].data),theList=theExtraList=null,a("a[className*=':']").unbind(),commentsBox.st>commentsBox.total?a("#show-comments").hide():a("#show-comments").show().children("a").html(postL10n.showcomm),void 0):1==b?(a("#show-comments").html(postL10n.endcomm),void 0):(a("#the-comment-list").append('<tr><td colspan="2">'+wpAjax.broken+"</td></tr>"),void 0)}),!1}},WPSetThumbnailHTML=function(b){a(".inside","#postimagediv").html(b)},WPSetThumbnailID=function(b){var c=a('input[value="_thumbnail_id"]',"#list-table");c.size()>0&&a("#meta\\["+c.attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(b)},WPRemoveThumbnail=function(b){a.post(ajaxurl,{action:"set-post-thumbnail",post_id:a("#post_ID").val(),thumbnail_id:-1,_ajax_nonce:b,cookie:encodeURIComponent(document.cookie)},function(a){"0"==a?alert(setPostThumbnailL10n.error):WPSetThumbnailHTML(a)})},a(document).on("heartbeat-send.refresh-lock",function(b,c){var d=a("#active_post_lock").val(),e=a("#post_ID").val(),f={};e&&a("#post-lock-dialog").length&&(f.post_id=e,d&&(f.lock=d),c["wp-refresh-post-lock"]=f)}),a(document).on("heartbeat-tick.refresh-lock",function(b,c){var d,e,f;c["wp-refresh-post-lock"]&&(d=c["wp-refresh-post-lock"],d.lock_error?(e=a("#post-lock-dialog"),e.length&&!e.is(":visible")&&("function"==typeof autosave&&(a(document).on("autosave-disable-buttons.post-lock",function(){e.addClass("saving")}).on("autosave-enable-buttons.post-lock",function(){e.removeClass("saving").addClass("saved"),window.onbeforeunload=null}),autosave()||(window.onbeforeunload=null),autosave=function(){}),d.lock_error.avatar_src&&(f=a('<img class="avatar avatar-64 photo" width="64" height="64" />').attr("src",d.lock_error.avatar_src.replace(/&/g,"&")),e.find("div.post-locked-avatar").empty().append(f)),e.show().find(".currently-editing").text(d.lock_error.text),e.find(".wp-tab-first").focus())):d.new_lock&&a("#active_post_lock").val(d.new_lock))})}(jQuery),function(a){function b(){c=!1,window.clearTimeout(d),d=window.setTimeout(function(){c=!0},3e5)}var c,d;a(document).on("heartbeat-send.wp-refresh-nonces",function(b,d){var e,f;c&&(f=a("#post_ID").val())&&(e=a("#_wpnonce").val())&&(d["wp-refresh-post-nonces"]={post_id:f,post_nonce:e})}).on("heartbeat-tick.wp-refresh-nonces",function(c,d){var e=d["wp-refresh-post-nonces"];e&&(b(),e.replace&&a.each(e.replace,function(b,c){a("#"+b).val(c)}),e.heartbeatNonce&&(window.heartbeatSettings.nonce=e.heartbeatNonce))}).ready(function(){b()})}(jQuery),jQuery(document).ready(function(a){function b(){var b=a("#post-visibility-select");"public"!=a("input:radio:checked",b).val()?(a("#sticky").prop("checked",!1),a("#sticky-span").hide()):a("#sticky-span").show(),"password"!=a("input:radio:checked",b).val()?a("#password-span").hide():a("#password-span").show()}function c(){if(!a("#timestampdiv").length)return!0;var b,c,e,f,g=a("#post_status"),h=a('option[value="publish"]',g),i=a("#aa").val(),j=a("#mm").val(),k=a("#jj").val(),l=a("#hh").val(),m=a("#mn").val();return b=new Date(i,j-1,k,l,m),c=new Date(a("#hidden_aa").val(),a("#hidden_mm").val()-1,a("#hidden_jj").val(),a("#hidden_hh").val(),a("#hidden_mn").val()),e=new Date(a("#cur_aa").val(),a("#cur_mm").val()-1,a("#cur_jj").val(),a("#cur_hh").val(),a("#cur_mn").val()),b.getFullYear()!=i||1+b.getMonth()!=j||b.getDate()!=k||b.getMinutes()!=m?(a(".timestamp-wrap","#timestampdiv").addClass("form-invalid"),!1):(a(".timestamp-wrap","#timestampdiv").removeClass("form-invalid"),b>e&&"future"!=a("#original_post_status").val()?(f=postL10n.publishOnFuture,a("#publish").val(postL10n.schedule)):e>=b&&"publish"!=a("#original_post_status").val()?(f=postL10n.publishOn,a("#publish").val(postL10n.publish)):(f=postL10n.publishOnPast,a("#publish").val(postL10n.update)),c.toUTCString()==b.toUTCString()?a("#timestamp").html(d):a("#timestamp").html(f+" <b>"+postL10n.dateFormat.replace("%1$s",a('option[value="'+a("#mm").val()+'"]',"#mm").text()).replace("%2$s",k).replace("%3$s",i).replace("%4$s",l).replace("%5$s",m)+"</b> "),"private"==a("input:radio:checked","#post-visibility-select").val()?(a("#publish").val(postL10n.update),0==h.length?g.append('<option value="publish">'+postL10n.privatelyPublished+"</option>"):h.html(postL10n.privatelyPublished),a('option[value="publish"]',g).prop("selected",!0),a(".edit-post-status","#misc-publishing-actions").hide()):("future"==a("#original_post_status").val()||"draft"==a("#original_post_status").val()?h.length&&(h.remove(),g.val(a("#hidden_post_status").val())):h.html(postL10n.published),g.is(":hidden")&&a(".edit-post-status","#misc-publishing-actions").show()),a("#post-status-display").html(a("option:selected",g).text()),"private"==a("option:selected",g).val()||"publish"==a("option:selected",g).val()?a("#save-post").hide():(a("#save-post").show(),"pending"==a("option:selected",g).val()?a("#save-post").show().val(postL10n.savePending):a("#save-post").show().val(postL10n.saveDraft)),!0)}var d,e,f="",g=0,h=a("#content");postboxes.add_postbox_toggles(pagenow),a("#post-lock-dialog .notification-dialog").on("keydown",function(b){if(9==b.which){var c=a(b.target);c.hasClass("wp-tab-first")&&b.shiftKey?(a(this).find(".wp-tab-last").focus(),b.preventDefault()):c.hasClass("wp-tab-last")&&!b.shiftKey&&(a(this).find(".wp-tab-first").focus(),b.preventDefault())}}).filter(":visible").find(".wp-tab-first").focus(),"undefined"!=typeof wp&&wp.heartbeat&&a("#post-lock-dialog").length&&wp.heartbeat.setInterval(15),a("#tagsdiv-post_tag").length?tagBox.init():a("#side-sortables, #normal-sortables, #advanced-sortables").children("div.postbox").each(function(){return 0===this.id.indexOf("tagsdiv-")?(tagBox.init(),!1):void 0}),a(".categorydiv").each(function(){var b,c,d,e,f,g=a(this).attr("id");d=g.split("-"),d.shift(),e=d.join("-"),f=e+"_tab","category"==e&&(f="cats"),a("a","#"+e+"-tabs").click(function(){var b=a(this).attr("href");return a(this).parent().addClass("tabs").siblings("li").removeClass("tabs"),a("#"+e+"-tabs").siblings(".tabs-panel").hide(),a(b).show(),"#"+e+"-all"==b?deleteUserSetting(f):setUserSetting(f,"pop"),!1}),getUserSetting(f)&&a('a[href="#'+e+'-pop"]',"#"+e+"-tabs").click(),a("#new"+e).one("focus",function(){a(this).val("").removeClass("form-input-tip")}),a("#new"+e).keypress(function(b){13===b.keyCode&&(b.preventDefault(),a("#"+e+"-add-submit").click())}),a("#"+e+"-add-submit").click(function(){a("#new"+e).focus()}),b=function(b){return a("#new"+e).val()?(b.data+="&"+a(":checked","#"+e+"checklist").serialize(),a("#"+e+"-add-submit").prop("disabled",!0),b):!1},c=function(b,c){var d,f=a("#new"+e+"_parent");a("#"+e+"-add-submit").prop("disabled",!1),"undefined"!=c.parsed.responses[0]&&(d=c.parsed.responses[0].supplemental.newcat_parent)&&(f.before(d),f.remove())},a("#"+e+"checklist").wpList({alt:"",response:e+"-ajax-response",addBefore:b,addAfter:c}),a("#"+e+"-add-toggle").click(function(){return a("#"+e+"-adder").toggleClass("wp-hidden-children"),a('a[href="#'+e+'-all"]',"#"+e+"-tabs").click(),a("#new"+e).focus(),!1}),a("#"+e+"checklist, #"+e+"checklist-pop").on("click",'li.popular-category > label input[type="checkbox"]',function(){var b=a(this),c=b.is(":checked"),d=b.val();d&&b.parents("#taxonomy-"+e).length&&a("#in-"+e+"-"+d+", #in-popular-"+e+"-"+d).prop("checked",c)})}),a("#postcustom").length&&a("#the-list").wpList({addAfter:function(){a("table#list-table").show()},addBefore:function(b){return b.data+="&post_id="+a("#post_ID").val(),b}}),a("#submitdiv").length&&(d=a("#timestamp").html(),e=a("#post-visibility-display").html(),a(".edit-visibility","#visibility").click(function(){return a("#post-visibility-select").is(":hidden")&&(b(),a("#post-visibility-select").slideDown("fast"),a(this).hide()),!1}),a(".cancel-post-visibility","#post-visibility-select").click(function(){return a("#post-visibility-select").slideUp("fast"),a("#visibility-radio-"+a("#hidden-post-visibility").val()).prop("checked",!0),a("#post_password").val(a("#hidden-post-password").val()),a("#sticky").prop("checked",a("#hidden-post-sticky").prop("checked")),a("#post-visibility-display").html(e),a(".edit-visibility","#visibility").show(),c(),!1}),a(".save-post-visibility","#post-visibility-select").click(function(){var b=a("#post-visibility-select");return b.slideUp("fast"),a(".edit-visibility","#visibility").show(),c(),"public"!=a("input:radio:checked",b).val()&&a("#sticky").prop("checked",!1),f=1==a("#sticky").prop("checked")?"Sticky":"",a("#post-visibility-display").html(postL10n[a("input:radio:checked",b).val()+f]),!1}),a("input:radio","#post-visibility-select").change(function(){b()}),a("#timestampdiv").siblings("a.edit-timestamp").click(function(){return a("#timestampdiv").is(":hidden")&&(a("#timestampdiv").slideDown("fast"),a("#mm").focus(),a(this).hide()),!1}),a(".cancel-timestamp","#timestampdiv").click(function(){return a("#timestampdiv").slideUp("fast"),a("#mm").val(a("#hidden_mm").val()),a("#jj").val(a("#hidden_jj").val()),a("#aa").val(a("#hidden_aa").val()),a("#hh").val(a("#hidden_hh").val()),a("#mn").val(a("#hidden_mn").val()),a("#timestampdiv").siblings("a.edit-timestamp").show(),c(),!1}),a(".save-timestamp","#timestampdiv").click(function(){return c()&&(a("#timestampdiv").slideUp("fast"),a("#timestampdiv").siblings("a.edit-timestamp").show()),!1}),a("#post").on("submit",function(b){return c()?void 0:(b.preventDefault(),a("#timestampdiv").show(),a("#publishing-action .spinner").hide(),a("#publish").prop("disabled",!1).removeClass("button-primary-disabled"),!1)}),a("#post-status-select").siblings("a.edit-post-status").click(function(){return a("#post-status-select").is(":hidden")&&(a("#post-status-select").slideDown("fast"),a(this).hide()),!1}),a(".save-post-status","#post-status-select").click(function(){return a("#post-status-select").slideUp("fast"),a("#post-status-select").siblings("a.edit-post-status").show(),c(),!1}),a(".cancel-post-status","#post-status-select").click(function(){return a("#post-status-select").slideUp("fast"),a("#post_status").val(a("#hidden_post_status").val()),a("#post-status-select").siblings("a.edit-post-status").show(),c(),!1})),a("#edit-slug-box").length&&(editPermalink=function(b){var c,d=0,e=a("#editable-post-name"),f=e.html(),g=a("#post_name"),h=g.val(),i=a("#edit-slug-buttons"),j=i.html(),k=a("#editable-post-name-full").html();for(a("#view-post-btn").hide(),i.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+"</a>"),i.children(".save").click(function(){var c=e.children("input").val();return c==a("#editable-post-name-full").text()?a(".cancel","#edit-slug-buttons").click():(a.post(ajaxurl,{action:"sample-permalink",post_id:b,new_slug:c,new_title:a("#title").val(),samplepermalinknonce:a("#samplepermalinknonce").val()},function(b){var d=a("#edit-slug-box");d.html(b),d.hasClass("hidden")&&d.fadeIn("fast",function(){d.removeClass("hidden")}),i.html(j),g.val(c),makeSlugeditClickable(),a("#view-post-btn").show()}),!1)}),a(".cancel","#edit-slug-buttons").click(function(){return a("#view-post-btn").show(),e.html(f),i.html(j),g.val(h),!1}),c=0;c<k.length;++c)"%"==k.charAt(c)&&d++;slug_value=d>k.length/4?"":k,e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children("input").keypress(function(a){var b=a.keyCode||0;return 13==b?(i.children(".save").click(),!1):27==b?(i.children(".cancel").click(),!1):void 0}).keyup(function(){g.val(this.value)}).focus()},makeSlugeditClickable=function(){a("#editable-post-name").click(function(){a("#edit-slug-buttons").children(".edit-slug").click()})},makeSlugeditClickable()),"undefined"!=typeof wpWordCount&&(a(document).triggerHandler("wpcountwords",[h.val()]),h.keyup(function(b){var c=b.keyCode||b.charCode;return c==g?!0:((13==c||8==g||46==g)&&a(document).triggerHandler("wpcountwords",[h.val()]),g=c,!0)})),wptitlehint=function(b){b=b||"title";var c=a("#"+b),d=a("#"+b+"-prompt-text");""==c.val()&&d.removeClass("screen-reader-text"),d.click(function(){a(this).addClass("screen-reader-text"),c.focus()}),c.blur(function(){""==this.value&&d.removeClass("screen-reader-text")}).focus(function(){d.addClass("screen-reader-text")}).keydown(function(b){d.addClass("screen-reader-text"),a(this).unbind(b)})},wptitlehint(),function(){function b(a){return e.height(Math.max(50,f+a.pageY)+"px"),!1}function c(){var d;e.focus(),a(document).unbind("mousemove",b).unbind("mouseup",c),d=parseInt(e.css("height"),10),d&&d>50&&5e3>d&&setUserSetting("ed_size",d)}var d,e=a("textarea#content"),f=null;!e.length||"ontouchstart"in window||(e.css("resize","none"),d=a('<div id="content-resize-handle"><br></div>'),a("#wp-content-wrap").append(d),d.on("mousedown",function(d){return f=e.height()-d.pageY,e.blur(),a(document).mousemove(b).mouseup(c),!1}))}(),"undefined"!=typeof tinymce&&(tinymce.onAddEditor.add(function(b,c){function d(){var b,c=document.getElementById("content_ifr"),d=c?parseInt(c.style.height,10):0,e=a("#content_tbl tr.mceFirst").height();return d&&e?(b=d+e+21,b-=33):!1}"content"!=c.id||tinymce.isIOS5||(c.onLoadContent.add(function(){var b,c=document.getElementById("content"),d=c?parseInt(c.style.height,10):0,e=a("#content_tbl tr.mceFirst").height()||33;(!d||50>d||d>5e3)&&(d=360),getUserSetting("ed_size")>5e3&&setUserSetting("ed_size",360),b=d-e+12,b>50&&5e3>b&&(a("#content_tbl").css("height",""),a("#content_ifr").css("height",b+"px"))}),c.onSaveContent.add(function(){var b=d();!b||50>b||b>5e3||a("textarea#content").css("height",b+"px")}),c.onPostRender.add(function(){a("#content_resize").on("mousedown.wp-mce-resize",function(){a(document).on("mouseup.wp-mce-resize",function(){var b;a(document).off("mouseup.wp-mce-resize"),b=d(),b&&b>50&&5e3>b&&setUserSetting("ed_size",b)})})}))}),a("#post-formats-select input.post-format").on("change.set-editor-class",function(){var b,c,d=this.id;d&&a(this).prop("checked")&&(b=tinymce.get("content"),b&&(c=b.getBody(),c.className=c.className.replace(/\bpost-format-[^ ]+/,""),b.dom.addClass(c,"post-format-0"==d?"post-format-standard":d)))}))}); |