WordPress/wp-admin/js/press-this.min.js

1 line
11 KiB
JavaScript

!function(a,b){var c=function(){function c(a){return a&&b.pressThisL10n?b.pressThisL10n[a]||a:a||""}function d(a){return a=a||"",a.replace(/<!--[\s\S]*?(-->|$)/g,"").replace(/<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/gi,"").replace(/<\/?[a-z][\s\S]*?(>|$)/gi,"")}function e(a){var b=d(a);try{O.innerHTML=b,b=d(O.value)}catch(c){}return b}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(){a(".spinner").addClass("is-active"),a(".post-actions button").attr("disabled","disabled")}function h(){a(".spinner").removeClass("is-active"),a(".post-actions button").removeAttr("disabled")}function i(a){var c,d;(!I||I.isHidden())&&(a="reset"===a||aa&&aa>$.value.length,d=$.style.height,a?(c=b.pageYOffset,$.style.height="auto",$.style.height=Math.max($.scrollHeight,_)+"px",b.scrollTo(b.pageXOffset,c)):parseInt($.style.height,10)<$.scrollHeight&&($.style.height=$.scrollHeight+"px"),aa=$.value.length)}function j(){if(!I)return!1;var a,b,c,d=I.selection.getNode();if(I.wp&&I.wp.getView&&(b=I.wp.getView(d)))c=b.getBoundingClientRect();else{a=I.selection.getRng();try{c=a.getClientRects()[0]}catch(e){}c||(c=d.getBoundingClientRect())}return c.height?c:!1}function k(a){var c=b.tinymce.util.VK,d=a.keyCode;47>=d&&d!==c.SPACEBAR&&d!==c.ENTER&&d!==c.DELETE&&d!==c.BACKSPACE&&d!==c.UP&&d!==c.LEFT&&d!==c.DOWN&&d!==c.UP||d>=91&&93>=d||d>=112&&123>=d||144===d||145===d||l(d)}function l(a){var c,d,e,f=j(),g=50,h=65,i=b.tinymce.util.VK;f&&(c=f.top+I.iframeElement.getBoundingClientRect().top,d=c+f.height,c-=g,d+=h,e=L.height(),e<f.height||(0>c&&(a===i.UP||a===i.LEFT||a===i.BACKSPACE)?b.scrollTo(b.pageXOffset,c+b.pageYOffset):d>e&&b.scrollTo(b.pageXOffset,d+b.pageYOffset-e)))}function m(){var b=a("#title-container");return b.find("img.emoji").each(function(){var b=a(this);b.replaceWith(a("<span>").text(b.attr("alt")))}),e(b.text())}function n(){var c=a("#pressthis-form"),d=a('<input type="hidden" name="post_category[]" value="">');I&&I.save(),a("#post_title").val(m()),b.tagBox&&a("div.tagsdiv").each(function(){b.tagBox.flushTags(this,!1,1)}),a(".categories-select .category").each(function(b,e){var f=a(e);f.hasClass("selected")&&c.append(d.clone().val(f.attr("data-term-id")||""))})}function o(d){var e;N=!1,g(),"publish"===d&&a("#post_status").val("publish"),n(),e=a("#pressthis-form").serialize(),a.ajax({type:"post",url:b.ajaxurl,data:e}).always(function(){h(),u(),a(".publish-button").removeClass("is-saving")}).done(function(a){if(a.success){if(a.data.redirect)if(b.opener&&(Q.redirInParent||a.data.force))try{b.opener.location.href=a.data.redirect,b.setTimeout(function(){b.self.close()},200)}catch(c){b.location.href=a.data.redirect}else b.location.href=a.data.redirect}else t(a.data.errorMessage)}).fail(function(){t(c("serverError"))})}function p(a){var c,d,e="";c=f(a.attr("data-wp-src")||""),d=f(R.u),a.hasClass("is-image")?(d||(d=c),e='<a href="'+d+'"><img class="alignnone size-full" src="'+c+'" alt="" /></a>'):e="[embed]"+c+"[/embed]",I&&!I.isHidden()?T?I.execCommand("mceInsertContent",!1,e):I.setContent("<p>"+e+"</p>"+I.getContent()):b.QTags&&b.QTags.insertContent(e)}function q(){var c,d=a("#new-category").val();d&&(c={action:"press-this-add-category",post_id:a("#post_ID").val()||0,name:d,new_cat_nonce:a("#_ajax_nonce-add-category").val()||"",parent:a("#new-category-parent").val()||0},a.post(b.ajaxurl,c,function(b){if(b.success){var c,d,e=a("ul.categories-select");a.each(b.data,function(b,f){var g=a("<li>").append(a('<div class="category selected" tabindex="0" role="checkbox" aria-checked="true">').attr("data-term-id",f.term_id).text(f.name));f.parent?(d&&d.length||(c=e.find('div[data-term-id="'+f.parent+'"]').parent(),d=c.find("ul.children:first"),d.length||(d=a('<ul class="children">').appendTo(c))),d.prepend(g)):e.prepend(g),g.focus()}),H()}else t(b.data.errorMessage)}))}function r(){R.hasData&&a("#scanbar").hide()}function s(b,c){var d=a(".editor-wrapper div.alerts"),e=c?"is-error":"is-notice";d.append(a('<p class="alert '+e+'">').text(b))}function t(a){s(a,!0)}function u(){a("div.alerts").empty()}function v(){R.errors&&a.each(R.errors,function(a,b){t(b)})}function w(a,b,d){var e=K.clone().addClass("is-image");e.attr("data-wp-src",a).css("background-image","url("+b+")").find("span").text(c("suggestedImgAlt").replace("%d",d+1)),J.append(e)}function x(){var b=0;J=a("ul.media-list"),K=a('<li class="suggested-media-thumbnail" tabindex="0"><span class="screen-reader-text"></span></li>'),R._embeds&&a.each(R._embeds,function(a,d){var e="",g="",h=K.clone().addClass("is-embed");d=f(d),d.indexOf("youtube.com/")>-1?(e="https://i.ytimg.com/vi/"+d.replace(/.+v=([^&]+).*/,"$1")+"/hqdefault.jpg",g+=" is-video"):d.indexOf("youtu.be/")>-1?(e="https://i.ytimg.com/vi/"+d.replace(/\/([^\/])$/,"$1")+"/hqdefault.jpg",g+=" is-video"):d.indexOf("dailymotion.com")>-1?(e=d.replace("/video/","/thumbnail/video/"),g+=" is-video"):g+=d.indexOf("soundcloud.com")>-1?" is-audio":d.indexOf("twitter.com")>-1?" is-tweet":" is-video",h.attr("data-wp-src",d).find("span").text(c("suggestedEmbedAlt").replace("%d",a+1)),e&&h.css("background-image","url("+e+")"),J.append(h),b++}),R._images&&a.each(R._images,function(a,c){var d,e=new Image;c=f(c),d=c.replace(/^(http[^\?]+)(\?.*)?$/,"$1"),d=c.indexOf("files.wordpress.com/")>-1?d.replace(/\?.*$/,"")+"?w="+S:c.indexOf("gravatar.com/")>-1?d.replace(/\?.*$/,"")+"?s="+S:c,e.onload=function(){e.width&&e.width<256||e.height&&e.height<128||w(c,d,a)},e.src=c,b++}),b&&a(".media-list-container").addClass("has-media")}function y(){var b=a(".post-options"),c=a(".post-option"),d=a(".setting-modal"),e=a(".modal-close");c.on("click",function(){var c=a(this).index(),e=d.eq(c);b.addClass(V).one(ba,function(){a(this).addClass(W)}),e.removeClass(X).one(ba,function(){a(this).find(".modal-close").focus()})}),e.on("click",function(){var d=a(this).parent(),e=d.index();b.removeClass(X),d.addClass(V),ba?d.one(ba,function(){a(this).addClass(W),c.eq(e-1).focus()}):setTimeout(function(){d.addClass(W),c.eq(e-1).focus()},350)})}function z(){P=!0,a(".options").removeClass("closed").addClass("open"),a(".press-this-actions, #scanbar").addClass(W),a(".options-panel-back").removeClass(W),a(".options-panel").removeClass(X).one(ba,function(){a(".post-option:first").focus()})}function A(){P=!1,a(".options").removeClass("open").addClass("closed"),a(".options-panel-back").addClass(W),a(".press-this-actions, #scanbar").removeClass(W),a(".options-panel").addClass(V).one(ba,function(){a(this).addClass(W),a(".post-options").removeClass(X),a(".setting-modal").addClass(X)})}function B(){var c=a("#title-container"),d=a(".post-title-placeholder");c.on("focus",function(){d.addClass("is-hidden")}).on("blur",function(){c.text()||c.html()||d.removeClass("is-hidden")}).on("keyup",function(){N=!0}).on("paste",function(d){var e,f,g=d.originalEvent.clipboardData||b.clipboardData;if(g){try{e=g.getData("Text")||g.getData("text/plain"),e&&(e=a.trim(e.replace(/\s+/g," ")),b.getSelection?(f=b.getSelection().getRangeAt(0),f&&(f.collapsed||f.deleteContents(),f.insertNode(document.createTextNode(e)))):document.selection&&(f=document.selection.createRange(),f&&(f.text=e)))}catch(h){}d.preventDefault()}N=!0,setTimeout(function(){c.text(m())},50)}),(c.text()||c.html())&&d.addClass("is-hidden")}function C(a){a.hasClass("selected")?a.removeClass("selected").attr("aria-checked","false"):a.addClass("selected").attr("aria-checked","true")}function D(){a(".categories-select").on("click.press-this keydown.press-this",function(b){var c=a(b.target);if(c.is("div.category")){if("keydown"===b.type&&32!==b.keyCode)return;C(c),b.preventDefault()}})}function E(){a(".split-button").removeClass("is-open"),a(".split-button-toggle").attr("aria-expanded","false")}function F(){r(),x(),v(),b.tagBox&&b.tagBox.init(),Y&&a(document.body).css("cursor","pointer")}function G(){var d=a(".split-button");return M.on("tinymce-editor-init",function(a,b){I=b,I.on("nodechange",function(){T=!0}),I.on("focus",function(){E()}),I.on("show",function(){setTimeout(function(){I.execCommand("wpAutoResize")},300)}),I.on("hide",function(){setTimeout(function(){i("reset")},100)}),I.on("keyup",k),I.on("undo redo",l)}).on("click.press-this keypress.press-this",".suggested-media-thumbnail",function(b){("click"===b.type||13===b.keyCode)&&p(a(this))}).on("click.press-this",function(b){a(b.target).closest("button").hasClass("split-button-toggle")||E()}),a(".post-actions").on("click.press-this",function(c){var e,f=a(c.target),g=f.closest("button");g.length&&(g.hasClass("draft-button")?(a(".publish-button").addClass("is-saving"),o("draft")):g.hasClass("publish-button")?(g.addClass("is-saving"),b.history.replaceState&&(e=b.location.href,e+=-1!==e.indexOf("?")?"&":"?",e+="wp-press-this-reload=true",b.history.replaceState(null,null,e)),o("publish")):g.hasClass("preview-button")?(n(),b.opener&&b.opener.focus(),a("#wp-preview").val("dopreview"),a("#pressthis-form").attr("target","_blank").submit().attr("target",""),a("#wp-preview").val("")):g.hasClass("standard-editor-button")?(a(".publish-button").addClass("is-saving"),a("#pt-force-redirect").val("true"),o("draft")):g.hasClass("split-button-toggle")&&(d.hasClass("is-open")?(d.removeClass("is-open"),g.attr("aria-expanded","false")):(d.addClass("is-open"),g.attr("aria-expanded","true"))))}),y(),B(),D(),a(".options").on("click.press-this",function(){a(this).hasClass("open")?A():z()}),a(".options-panel, .options-panel-back").on("focusout.press-this",function(){setTimeout(function(){var b=document.activeElement,c=a(b);!P||!b||c.hasClass("options-panel-back")||"BODY"!==b.nodeName&&(c.closest(".options-panel").length||c.closest(".options").length)||A()},50)}),a("#post-formats-select input").on("change",function(){var b=a(this);b.is(":checked")&&a("#post-option-post-format").text(a('label[for="'+b.attr("id")+'"]').text()||"")}),L.on("beforeunload.press-this",function(){return N||I&&I.isDirty()?c("saveAlert"):void 0}).on("resize.press-this",function(){(!I||I.isHidden())&&i("reset")}),a("button.add-cat-toggle").on("click.press-this",function(){var b=a(this);b.toggleClass("is-toggled"),b.attr("aria-expanded","false"===b.attr("aria-expanded")?"true":"false"),a(".setting-modal .add-category, .categories-search-wrapper").toggleClass("is-hidden")}),a("button.add-cat-submit").on("click.press-this",q),a(".categories-search").on("keyup.press-this",function(){var b=a(this).val().toLowerCase()||"";/[\x20-\xFF]+/.test(b)&&b.length<2||(a.each(U,function(a,b){b.node.removeClass("is-hidden searched-parent")}),b&&a.each(U,function(a,c){-1===c.text.indexOf(b)?c.node.addClass("is-hidden"):c.parents.addClass("searched-parent")}))}),Z.on("focus.press-this input.press-this propertychange.press-this",i),!0}function H(){a(".categories-select").find("li").each(function(){var b=a(this);U.push({node:b,parents:b.parents("li"),text:b.children(".category").text().toLowerCase()})})}var I,J,K,L=a(b),M=a(document),N=!1,O=document.createElement("textarea"),P=!1,Q=b.wpPressThisConfig||{},R=b.wpPressThisData||{},S=128,T=!1,U=[],V="is-off-screen",W="is-hidden",X=V+" "+W,Y=/iPad|iPod|iPhone/.test(b.navigator.userAgent),Z=a("#pressthis"),$=Z[0],_=600,aa=0,ba=function(){var a=document.documentElement.style;return"undefined"!=typeof a.transition?"transitionend":"undefined"!=typeof a.WebkitTransition?"webkitTransitionEnd":!1}();return M.ready(function(){F(),G(),H()}),{renderNotice:s,renderError:t}};b.wp=b.wp||{},b.wp.pressThis=new c}(jQuery,window);