WordPress/wp-admin/js/press-this.min.js
Andrew Ozz 8164f8fe0e PressThis:
- Remove unneeded passing of post formats strings to JS.
- Set the currently selected post format name with jQuery.
See #31373.
Built from https://develop.svn.wordpress.org/trunk@31589


git-svn-id: http://core.svn.wordpress.org/trunk@31570 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-28 20:08:27 +00:00

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][^>]*>/gi,"")}function e(a){return a=d(a),a.replace(/\\/,"").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(a){if(!a||a.length)return"";var b="";return a._links&&a._links.canonical&&a._links.canonical.length&&(b=a._links.canonical),!b.length&&a.u&&(b=a.u),!b.length&&a._meta&&(a._meta["twitter:url"]&&a._meta["twitter:url"].length?b=a._meta["twitter:url"]:a._meta["og:url"]&&a._meta["og:url"].length&&(b=a._meta["og:url"])),decodeURI(b)}function h(a){if(!a||a.length)return"";var b="";return a._meta&&(a._meta["og:site_name"]&&a._meta["og:site_name"].length?b=a._meta["og:site_name"]:a._meta["application-name"]&&a._meta["application-name"].length&&(b=a._meta["application-name"])),b.replace(/\\/g,"")}function i(a){if(!a||a.length)return c("newPost");var b="";return a.t&&(b=a.t),!b.length&&a._meta&&(a._meta["twitter:title"]&&a._meta["twitter:title"].length?b=a._meta["twitter:title"]:a._meta["og:title"]&&a._meta["og:title"].length?b=a._meta["og:title"]:a._meta.title&&a._meta.title.length&&(b=a._meta.title)),b.length||(b=c("newPost"),O=!0),b.replace(/\\/g,"")}function j(a){if(!a||a.length)return"";var b="",d=i(a),f=g(a),j=h(a);return a.s&&a.s.length?b=a.s:a._meta&&(a._meta["twitter:description"]&&a._meta["twitter:description"].length?b=a._meta["twitter:description"]:a._meta["og:description"]&&a._meta["og:description"].length?b=a._meta["og:description"]:a._meta.description&&a._meta.description.length&&(b=a._meta.description)),b=b.length?'<blockquote class="press-this-suggested-content">'+e(b)+"</blockquote>":"",(d.length&&c("newPost")!==d||j.length)&&f.length&&(b+='<p class="press-this-suggested-source">',b+=c("source"),b+=" <cite>",b+=c("sourceLink").replace("%1$s",encodeURI(f)).replace("%2$s",e(d||j)),b+="</cite></p>"),b||(b=""),b.replace(/\\/g,"")}function k(a){return a?a.match(/\/\/(m\.|www\.)?youtube\.com\/watch\?/)||a.match(/\/youtu\.be\/.+$/)?!0:a.match(/\/\/vimeo\.com\/(.+\/)?[\d]+$/)?!0:a.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?!0:a.match(/\/\/soundcloud\.com\/.+$/)?!0:a.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?!0:a.match(/\/\/vine\.co\/v\/[^\/]+/)?!0:!1:!1}function l(a){return a.match(/\/ad[sx]{1}?\//)?!0:a.match(/(\/share-?this[^\.]+?\.[a-z0-9]{3,4})(\?.*)?$/)?!0:a.match(/\/(spinner|loading|spacer|blank|rss)\.(gif|jpg|png)/)?!0:a.match(/\/([^\.\/]+[-_]{1})?(spinner|loading|spacer|blank)s?([-_]{1}[^\.\/]+)?\.[a-z0-9]{3,4}/)?!0:a.match(/([^\.\/]+[-_]{1})?thumb[^.]*\.(gif|jpg|png)$/)?!0:a.match(/\/wp-includes\//)?!0:a.match(/[^\d]{1}\d{1,2}x\d+\.(gif|jpg|png)$/)?!0:a.indexOf("/g.gif")>-1?!0:a.indexOf("/pixel.mathtag.com")>-1?!0:!1}function m(){var b=K._embed||[],c=[],d=[];return b.length&&a.each(b,function(b,e){if(e&&e.length&&k(e)){var f=e.replace(/^https?:/,"");a.inArray(f,d)>-1||(c.push(e),d.push(f))}}),c}function n(a){var b="";return a&&a._meta?(a._meta["twitter:image0:src"]&&a._meta["twitter:image0:src"].length?b=a._meta["twitter:image0:src"]:a._meta["twitter:image0"]&&a._meta["twitter:image0"].length?b=a._meta["twitter:image0"]:a._meta["twitter:image:src"]&&a._meta["twitter:image:src"].length?b=a._meta["twitter:image:src"]:a._meta["twitter:image"]&&a._meta["twitter:image"].length?b=a._meta["twitter:image"]:a._meta["og:image"]&&a._meta["og:image"].length?b=a._meta["og:image"]:a._meta["og:image:secure_url"]&&a._meta["og:image:secure_url"].length&&(b=a._meta["og:image:secure_url"]),b=f(b),l(b)?"":b):""}function o(b){var c=b._img||[],d=n(b)||"",e=[],g=[];return d.length&&(e.push(d),g.push(d.replace(/^https?:/,""))),c.length&&a.each(c,function(a,b){if(b=b.replace(/http:\/\/[\d]+\.gravatar\.com\//,"https://secure.gravatar.com/"),b=f(b),b&&b.length){var c=b.replace(/^https?:/,"");Array.prototype.indexOf&&g.indexOf(c)>-1||l(b)||b.indexOf("avatar")>-1&&e.length>=15||(e.push(b),g.push(c))}}),e}function p(){a("#spinner").addClass("show"),a(".post-actions button").each(function(){a(this).attr("disabled","disabled")})}function q(){a("#spinner").removeClass("show"),a(".post-actions button").each(function(){a(this).removeAttr("disabled")})}function r(c){I=!1,p();var d=a("#pressthis-form");"publish"===c&&a("#post_status").val("publish"),H&&H.save(),a("#title-field").val(e(a("#title-container").text())),b.tagBox&&a("div.tagsdiv").each(function(){b.tagBox.flushTags(this,!1,1)});var f=d.serialize();a.ajax({type:"post",url:b.ajaxurl,data:f,success:function(a){if(a.success){if(a.data.redirect)if(b.opener&&J.redir_in_parent){try{b.opener.location.href=a.data.redirect}catch(c){}b.self.close()}else b.location.href=a.data.redirect}else w(a.data.errorMessage),q()}})}function s(a,b,c){var d="";H&&(b=f(b),c=f(c),"img"===a?(c&&c.length||(c=b),d='<a href="'+c+'"><img class="alignnone size-full" src="'+b+'" /></a>\n'):d="[embed]"+b+"[/embed]\n",R?H.execCommand("mceInsertContent",!1,d):H.setContent(d+H.getContent()),R=!0)}function t(){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)}),G()}else w(b.data.errorMessage)}))}function u(){K.u&&K.u.match(/^https?:/)&&a("#scanbar").hide()}function v(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 w(a){v(a,!0)}function x(){K.errors&&K.errors.length&&a.each(K.errors,function(a,b){w(b)}),K.v&&K._version&&K.v+""!=K._version+""&&a(".should-upgrade-bookmarklet").removeClass("is-hidden")}function y(){var b=P||"",c=a("#title-container");O||(a("#title-field").val(b),c.text(b),a(".post-title-placeholder").addClass("is-hidden")),c.on("keyup",function(){I=!0}).on("paste",function(){I=!0,setTimeout(function(){c.text(c.text())},100)})}function z(){Q&&Q.length&&(H||(H=b.tinymce.get("pressthis")),H&&(H.setContent(Q),H.on("focus",function(){R=!0})))}function A(){var b=a("#featured-media-container"),d=a("#all-media-container"),e=0;return d.empty(),(N&&N.length||M&&M.length)&&d.append('<h2 class="screen-reader-text">'+c("allMediaHeading")+'</h2><ul class="wppt-all-media-list"/>'),N&&N.length&&a.each(N,function(b,g){if(g=f(g),k(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.length?"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)&&s("embed",g)}).appendTo(".wppt-all-media-list",d),e++}}),M&&M.length&&a.each(M,function(b,g){g=f(g);var h=g.replace(/^(http[^\?]+)(\?.*)?$/,"$1");h=g.indexOf("files.wordpress.com/")>-1?h.replace(/\?.*$/,"")+"?w="+L:g.indexOf("gravatar.com/")>-1?h.replace(/\?.*$/,"")+"?s="+L: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)&&s("img",g,K.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 B(){var b="is-off-screen",c="is-hidden",d=a(".post-options"),e=a(".post-option"),f=a(".setting-modal"),g=a(".modal-close");e.on("click",function(e){var g=a(this).index(),h=f.eq(g);e.preventDefault(),d.addClass(b).one(T,function(){a(this).addClass(c)}),h.removeClass(b+" "+c).one(T,function(){a(this).find(".modal-close").focus()})}),g.on("click",function(f){var g=a(this).parent(),h=g.index();f.preventDefault(),d.removeClass(b+" "+c),g.addClass(b).one(T,function(){a(this).addClass(c),e.eq(h-1).focus()}),T||setTimeout(function(){g.addClass(c),e.eq(h-1).focus()},350)})}function C(){var b=a(".options-open"),c=a(".options-close"),d=a(".post-option"),e=a(".options-panel"),f=a(".press-this-actions"),g=a("#scanbar"),h="is-off-screen",i="is-hidden",j=h+" "+i;b.on("click",function(){b.addClass(i),c.removeClass(i),f.addClass(i),g.addClass(i),e.removeClass(j).one("transitionend",function(){d.eq(0).focus()})}),c.on("click",function(){c.addClass(i),b.removeClass(i),f.removeClass(i),g.removeClass(i),e.addClass(h).one("transitionend",function(){a(this).addClass(i),a(".post-options").removeClass(j),a(".setting-modal").addClass(j)})})}function D(){var b=a("#title-container"),c=a(".post-title-placeholder");b.on("focus",function(){c.addClass("is-hidden")}),b.on("blur",function(){var b=a(this).text().length;b||c.removeClass("is-hidden")})}function E(){u(),y(),A(),a(document).on("tinymce-editor-init",z),x()}function F(){return a("#current-site a").click(function(a){a.preventDefault()}),a("#draft-field").on("click",function(){r("draft")}),a("#publish-field").on("click",function(){r("publish")}),B(),C(),D(),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("#tax-input-post_tag").on("change",function(){var b=a(this).val();a("#post-option-tags").text(b.length?b.replace(/,([^\s])/g,", $1"):"")}),a(b).on("beforeunload.press-this",function(){return I||H&&H.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",!b.attr("aria-expanded")),a(".setting-modal .add-category, .categories-search-wrapper").toggleClass("is-hidden")}),a("button.add-cat-submit").on("click.press-this",t),a(".categories-search").on("keyup.press-this",function(){var b=a(this).val().toLowerCase()||"";/[\x20-\xFF]+/.test(b)&&b.length<2||(a.each(S,function(a,b){b.node.removeClass("is-hidden searched-parent")}),b&&a.each(S,function(a,c){-1===c.text.indexOf(b)?c.node.addClass("is-hidden"):c.parents.addClass("searched-parent")}))}),!0}function G(){a(".categories-select").find("li").each(function(){var b=a(this);S.push({node:b,parents:b.parents("li"),text:b.children("label").text().toLowerCase()})})}var H,I=!1,J=b.wpPressThisConfig||{},K=b.wpPressThisData||{},L=128,M=o(K)||[],N=m(K)||[],O=!1,P=i(K),Q=j(K),R=!1,S=[],T=function(){var a=document.documentElement.style;return"undefined"!=typeof a.transition?"transitionend":"undefined"!=typeof a.WebkitTransition?"webkitTransitionEnd":!1}();return a(document).ready(function(){E(),F(),G()}),{renderNotice:v,renderError:w}};b.wp=b.wp||{},b.wp.pressThis=new c}(jQuery,window);