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

1 line
9.6 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){return a=d(a),I.innerHTML=a,d(I.value)}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(){var a="";return L._links&&L._links.canonical&&(a=L._links.canonical),!a&&L.u&&(a=L.u),!a&&L._meta&&(L._meta["twitter:url"]?a=L._meta["twitter:url"]:L._meta["og:url"]&&(a=L._meta["og:url"])),f(decodeURI(a))}function h(){var a="";return L._meta&&(L._meta["og:site_name"]?a=L._meta["og:site_name"]:L._meta["application-name"]&&(a=L._meta["application-name"])),e(a)}function i(){var a="";return L.t&&(a=L.t),!a&&L._meta&&(L._meta["twitter:title"]?a=L._meta["twitter:title"]:L._meta["og:title"]?a=L._meta["og:title"]:L._meta.title&&(a=L._meta.title)),a||(a=c("newPost"),P=!0),e(a)}function j(){var a="",b="",d=i(),f=g(),j=h();return L.s?b=L.s:L._meta&&(L._meta["twitter:description"]?b=L._meta["twitter:description"]:L._meta["og:description"]?b=L._meta["og:description"]:L._meta.description&&(b=L._meta.description)),b&&K.html.quote&&(a=K.html.quote.replace(/%1\$s/g,e(b))),f&&K.html.link&&(d&&c("newPost")!==d||j)&&(a+=K.html.link.replace(/%1\$s/g,encodeURI(f)).replace(/%2\$s/g,d||j)),a||""}function k(){var b=L._embed||[],c=[],d=[];return b.length&&a.each(b,function(b,e){if(e){var f=e.replace(/^https?:/,"");a.inArray(f,d)>-1||(c.push(e),d.push(f))}}),c}function l(b){var c=b._img||[],d=[],e=[];return c.length&&a.each(c,function(a,b){if(b=b.replace(/http:\/\/[\d]+\.gravatar\.com\//,"https://secure.gravatar.com/"),b=f(b)){var c=b.replace(/^https?:/,"");Array.prototype.indexOf&&e.indexOf(c)>-1||b.indexOf("avatar")>-1&&d.length>=15||(d.push(b),e.push(c))}}),d}function m(){a("#spinner").addClass("show"),a(".post-actions button").each(function(){a(this).attr("disabled","disabled")})}function n(){a("#spinner").removeClass("show"),a(".post-actions button").each(function(){a(this).removeAttr("disabled")})}function o(){G&&G.save(),a("#post_title").val(e(a("#title-container").text())),b.tagBox&&a("div.tagsdiv").each(function(){b.tagBox.flushTags(this,!1,1)})}function p(c){var d;H=!1,m(),"publish"===c&&a("#post_status").val("publish"),o(),d=a("#pressthis-form").serialize(),a.ajax({type:"post",url:b.ajaxurl,data:d,success:function(a){if(a.success){if(a.data.redirect)if(b.opener&&K.redirInParent){try{b.opener.location.href=a.data.redirect}catch(c){}b.self.close()}else b.location.href=a.data.redirect}else u(a.data.errorMessage),n()}})}function q(a,b,c){var d="";G&&(b=f(b),c=f(c),"img"===a?(c||(c=b),d='<a href="'+c+'"><img class="alignnone size-full" src="'+b+'" /></a>\n'):d="[embed]"+b+"[/embed]\n",S||G.focus(),G.execCommand("mceInsertContent",!1,d),S=!0)}function r(){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>").attr("id","category-"+f.term_id).append(a('<label class="selectit">').text(f.name).append(a('<input type="checkbox" name="post_category[]" checked>').attr("value",f.term_id)));f.parent?(d&&d.length||(c=e.find("#category-"+f.parent),d=c.find("ul.children:first"),d.length||(d=a('<ul class="children">').appendTo(c))),d.append(g)):e.prepend(g)}),F()}else u(b.data.errorMessage)}))}function s(){L.u&&L.u.match(/^https?:/)&&a("#scanbar").hide()}function t(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 u(a){t(a,!0)}function v(){L.errors&&a.each(L.errors,function(a,b){u(b)}),L.v&&L._version&&L.v+""!=L._version+""&&a(".should-upgrade-bookmarklet").removeClass("is-hidden")}function w(){var b=Q||"",c=a("#title-container");P||(a("#post_title").val(b),c.text(b),a(".post-title-placeholder").addClass("is-hidden")),c.on("keyup",function(){H=!0}).on("paste",function(){H=!0,setTimeout(function(){c.text(c.text())},100)})}function x(){R&&(G||(G=b.tinymce.get("pressthis")),G&&(G.setContent(R),G.on("focus",function(){S=!0})))}function y(){var b=a("#featured-media-container"),d=a("#all-media-container"),e=0;return d.empty(),(O||N)&&d.append('<h2 class="screen-reader-text">'+c("allMediaHeading")+'</h2><ul class="wppt-all-media-list"/>'),O&&a.each(O,function(b,g){g=f(g);var h="",i="suggested-media-thumbnail suggested-media-embed";g.indexOf("youtube.com/")>-1?(h="https://i.ytimg.com/vi/"+g.replace(/.+v=([^&]+).*/,"$1")+"/hqdefault.jpg",i+=" is-video"):g.indexOf("youtu.be/")>-1?(h="https://i.ytimg.com/vi/"+g.replace(/\/([^\/])$/,"$1")+"/hqdefault.jpg",i+=" is-video"):g.indexOf("dailymotion.com")>-1?(h=g.replace("/video/","/thumbnail/video/"),i+=" is-video"):i+=g.indexOf("soundcloud.com")>-1?" is-audio":g.indexOf("twitter.com")>-1?" is-tweet":" is-video",a("<li></li>",{id:"embed-"+b+"-container","class":i,tabindex:"0"}).css({"background-image":h?"url("+h+")":null}).html('<span class="screen-reader-text">'+c("suggestedEmbedAlt").replace("%d",b+1)+"</span>").on("click keypress",function(a){("click"===a.type||13===a.which)&&q("embed",g)}).appendTo(".wppt-all-media-list",d),e++}),N&&a.each(N,function(b,g){g=f(g);var h=g.replace(/^(http[^\?]+)(\?.*)?$/,"$1");h=g.indexOf("files.wordpress.com/")>-1?h.replace(/\?.*$/,"")+"?w="+M:g.indexOf("gravatar.com/")>-1?h.replace(/\?.*$/,"")+"?s="+M:g,a("<li></li>",{id:"img-"+b+"-container","class":"suggested-media-thumbnail is-image",tabindex:"0"}).css({"background-image":"url("+h+")"}).html('<span class="screen-reader-text">'+c("suggestedImgAlt").replace("%d",b+1)+"</span>").on("click keypress",function(a){("click"===a.type||13===a.which)&&q("img",g,L.u)}).appendTo(".wppt-all-media-list",d),e++}),e?void b.removeClass("no-media").addClass("all-media-visible"):void b.removeClass("all-media-visible").addClass("no-media")}function z(){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(U).one(X,function(){a(this).addClass(V)}),e.removeClass(W).one(X,function(){a(this).find(".modal-close").focus()})}),e.on("click",function(){var d=a(this).parent(),e=d.index();b.removeClass(W),d.addClass(U),X?d.one(X,function(){a(this).addClass(V),c.eq(e-1).focus()}):setTimeout(function(){d.addClass(V),c.eq(e-1).focus()},350)})}function A(){J=!0,a(".options-open, .press-this-actions, #scanbar").addClass(V),a(".options-close, .options-panel-back").removeClass(V),a(".options-panel").removeClass(W).one("transitionend",function(){a(".post-option:first").focus()})}function B(){J=!1,a(".options-close, .options-panel-back").addClass(V),a(".options-open, .press-this-actions, #scanbar").removeClass(V),a(".options-panel").addClass(U).one("transitionend",function(){a(this).addClass(V),a(".post-options").removeClass(W),a(".setting-modal").addClass(W)})}function C(){var b=a("#title-container"),c=a(".post-title-placeholder");b.on("focus",function(){c.addClass("is-hidden")}),b.on("blur",function(){a(this).text()||c.removeClass("is-hidden")})}function D(){s(),w(),y(),a(document).on("tinymce-editor-init",x),v(),b.tagBox&&b.tagBox.init()}function E(){return a("#current-site a").click(function(a){a.preventDefault()}),a(".post-actions").on("click.press-this",function(c){var d=a(c.target);d.hasClass("draft-button")?p("draft"):d.hasClass("publish-button")?p("publish"):d.hasClass("preview-button")&&(o(),b.opener&&b.opener.focus(),a("#wp-preview").val("dopreview"),a("#pressthis-form").attr("target","_blank").submit().attr("target",""),a("#wp-preview").val(""))}),z(),C(),a(".options-open").on("click.press-this",A),a(".options-close").on("click.press-this",B),a(".options-panel, .options-panel-back").on("focusout.press-this",function(){setTimeout(function(){var b=document.activeElement,c=a(b);!J||!b||c.hasClass("options-panel-back")||"BODY"!==b.nodeName&&(c.closest(".options-panel").length||c.closest(".options-open").length)||B()},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()||"")}),a(b).on("beforeunload.press-this",function(){return H||G&&G.isDirty()?c("saveAlert"):void 0}),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",r),a(".categories-search").on("keyup.press-this",function(){var b=a(this).val().toLowerCase()||"";/[\x20-\xFF]+/.test(b)&&b.length<2||(a.each(T,function(a,b){b.node.removeClass("is-hidden searched-parent")}),b&&a.each(T,function(a,c){-1===c.text.indexOf(b)?c.node.addClass("is-hidden"):c.parents.addClass("searched-parent")}))}),!0}function F(){a(".categories-select").find("li").each(function(){var b=a(this);T.push({node:b,parents:b.parents("li"),text:b.children("label").text().toLowerCase()})})}var G,H=!1,I=document.createElement("textarea"),J=!1,K=b.wpPressThisConfig||{},L=b.wpPressThisData||{},M=128,N=l(L)||[],O=k(L)||[],P=!1,Q=i(L),R=j(L),S=!1,T=[],U="is-off-screen",V="is-hidden",W=U+" "+V,X=function(){var a=document.documentElement.style;return"undefined"!=typeof a.transition?"transitionend":"undefined"!=typeof a.WebkitTransition?"webkitTransitionEnd":!1}();return a(document).ready(function(){D(),E(),F()}),{renderNotice:t,renderError:u}};b.wp=b.wp||{},b.wp.pressThis=new c}(jQuery,window);