WordPress/wp-admin/js/post.min.js

1 line
19 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,WPSetThumbnailHTML,WPSetThumbnailID,WPRemoveThumbnail,wptitlehint;makeSlugeditClickable=editPermalink=function(){},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("&nbsp;").prepend(h)),f.append(e))}))},flushTags:function(b,c,d){var e,f,g,h=a(".the-tags",b),i=a("input.newtag",b),j=postL10n.comma;return c=c||!1,g=c?a(c).text():i.val(),e=h.val(),f=e?e+j+g:g,f=this.clean(f),f=array_unique_noempty(f.split(j)).join(j),h.val(f),this.quickClicks(b),c||i.val(""),"undefined"==typeof d&&i.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)}).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")&&("undefined"!=typeof wp&&wp.autosave&&(a(document).one("heartbeat-tick",function(){wp.autosave.server.disable(),e.removeClass("saving").addClass("saved"),a(window).off("beforeunload.edit-post")}),e.addClass("saving"),wp.autosave.server.triggerSave()),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(/&amp;/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))}).on("after-autosave.update-post-slug",function(){a("#edit-slug-box > *").length||a.post(ajaxurl,{action:"sample-permalink",post_id:a("#post_ID").val(),new_title:"undefined"!=typeof fullscreen&&fullscreen.settings.visible?a("#wp-fullscreen-title").val():a("#title").val(),samplepermalinknonce:a("#samplepermalinknonce").val()},function(b){"-1"!=b&&a("#edit-slug-box").html(b)})})}(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,c=0,d=a("#editable-post-name"),e=d.html(),f=a("#post_name"),g=f.val(),h=a("#edit-slug-buttons"),i=h.html(),k=a("#editable-post-name-full").html();for(a("#view-post-btn").hide(),h.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+"</a>"),h.children(".save").click(function(){var b=d.children("input").val();return b==a("#editable-post-name-full").text()?a("#edit-slug-buttons .cancel").click():(a.post(ajaxurl,{action:"sample-permalink",post_id:j,new_slug:b,new_title:a("#title").val(),samplepermalinknonce:a("#samplepermalinknonce").val()},function(c){var d=a("#edit-slug-box");d.html(c),d.hasClass("hidden")&&d.fadeIn("fast",function(){d.removeClass("hidden")}),h.html(i),f.val(b),a("#view-post-btn").show()}),!1)}),a("#edit-slug-buttons .cancel").click(function(){return a("#view-post-btn").show(),d.html(e),h.html(i),f.val(g),!1}),b=0;b<k.length;++b)"%"==k.charAt(b)&&c++;slug_value=c>k.length/4?"":k,d.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children("input").keypress(function(a){var b=a.keyCode||0;return 13==b?(h.children(".save").click(),!1):27==b?(h.children(".cancel").click(),!1):void 0}).keyup(function(){f.val(this.value)}).focus()}var c,d,e,f="",g=0,h=a("#content"),i=a("#edit-slug-box"),j=a("#post_ID").val()||0,k=a("#submitpost"),l=!0;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.interval(15),e=k.find(":button, :submit, a.submitdelete, #post-preview").on("click.edit-post",function(b){var c=a(this);return c.prop("disabled")?(b.preventDefault(),void 0):(c.hasClass("submitdelete")||c.is("#post-preview")||a("form#post").off("submit.edit-post").on("submit.edit-post",function(b){b.isDefaultPrevented()||("undefined"!=typeof wp&&wp.autosave&&wp.autosave.server.disable(),l=!1,a(window).off("beforeunload.edit-post"),e.prop("disabled",!0).addClass("button-disabled"),"publish"===c.attr("id")?k.find("#major-publishing-actions .spinner").show():k.find("#minor-publishing .spinner").show())}),void 0)}),a("#post-preview").on("click.post-preview",function(b){var c=a(this),d=a("form#post"),e=a("input#wp-preview"),f=c.attr("target")||"wp-preview",g=navigator.userAgent.toLowerCase();b.preventDefault(),c.prop("disabled")||("undefined"!=typeof wp&&wp.autosave&&wp.autosave.server.tempBlockSave(),e.val("dopreview"),d.attr("target",f).submit().attr("target",""),-1!==g.indexOf("safari")&&-1===g.indexOf("chrome")&&d.attr("action",function(a,b){return b+"?t="+(new Date).getTime()}),e.val(""))}),a("#title").on("keydown.editor-focus",function(b){var c;9!==b.keyCode||b.ctrlKey||b.altKey||b.shiftKey||(c="undefined"!=typeof tinymce&&tinymce.get("content"),c&&!c.isHidden()?c.focus():a("#content").focus(),b.preventDefault())}),a("#auto_draft").val()&&a("#title").blur(function(){this.value&&"1"===a("#auto_draft").val()&&"undefined"!=typeof wp&&wp.autosave&&wp.autosave.server.triggerSave()}),a(document).on("autosave-disable-buttons.edit-post",function(){e.prop("disabled",!0).addClass("button-disabled")}).on("autosave-enable-buttons.edit-post",function(){window.wp&&window.wp.heartbeat&&window.wp.heartbeat.hasConnectionError()||e.prop("disabled",!1).removeClass("button-disabled")}),a(window).on("beforeunload.edit-post",function(){var a="undefined"!=typeof tinymce&&tinymce.get("content");return a&&!a.isHidden()&&a.isDirty()||"undefined"!=typeof wp&&wp.autosave&&wp.autosave.server.postChanged()?autosaveL10n.saveAlert:void 0}).on("unload.edit-post",function(b){l&&(b.target&&"#document"!=b.target.nodeName||a.ajax({type:"POST",url:ajaxurl,async:!1,data:{action:"wp-remove-post-lock",_wpnonce:a("#_wpnonce").val(),post_ID:a("#post_ID").val(),active_post_lock:a("#active_post_lock").val()}}))}),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&&(c=a("#timestamp").html(),d=a("#post-visibility-display").html(),updateVisibility=function(){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()},updateText=function(){if(!a("#timestampdiv").length)return!0;var b,d,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),d=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)),d.toUTCString()==b.toUTCString()?a("#timestamp").html(c):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)},a(".edit-visibility","#visibility").click(function(){return a("#post-visibility-select").is(":hidden")&&(updateVisibility(),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(d),a(".edit-visibility","#visibility").show(),updateText(),!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(),updateText(),"public"!=a("input:radio:checked",b).val()&&a("#sticky").prop("checked",!1),f=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(){updateVisibility()}),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(),updateText(),!1}),a(".save-timestamp","#timestampdiv").click(function(){return updateText()&&(a("#timestampdiv").slideUp("fast"),a("#timestampdiv").siblings("a.edit-timestamp").show()),!1}),a("#post").on("submit",function(b){return updateText()?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(),updateText(),!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(),updateText(),!1})),i.length&&i.on("click",function(c){var d=a(c.target);(d.is("#editable-post-name")||d.hasClass("edit-slug"))&&b()}),"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){f?d.theme.resizeTo(null,e+a.pageY):h.height(Math.max(50,e+a.pageY)),a.preventDefault()}function c(){var b,c;f?(d.focus(),c=a("#wp-content-editor-container .mce-toolbar-grp").height(),b=parseInt(a("#content_ifr").css("height"),10)+c-28):(h.focus(),b=parseInt(h.css("height"),10)),g.off("mousemove.wp-editor-resize mouseup.wp-editor-resize"),b&&b>50&&5e3>b&&setUserSetting("ed_size",b)}var d,e,f,g=a(document),h=a("textarea#content"),i=a("#post-status-info");!h.length||"ontouchstart"in window||(h.css("resize","none"),i.on("mousedown.wp-editor-resize",function(i){"undefined"!=typeof tinymce&&(d=tinymce.get("content")),d&&!d.isHidden()?(f=!0,e=a("#content_ifr").height()-i.pageY):(f=!1,e=h.height()-i.pageY,h.blur()),g.on("mousemove.wp-editor-resize",b).on("mouseup.wp-editor-resize",c),i.preventDefault()}))}(),"undefined"!=typeof tinymce&&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)))})});