WordPress/wp-admin/js/press-this.min.js
Andrew Ozz a27967aa05 PressThis:
- Close the sidebar on moving the focus outside of it (by clicking or by "tabbing").
- Fix a (weird) structural CSS problem where clicks go through the sidebar when it is open.
- Clean up the JS a bit.
Fixes #31457.
Built from https://develop.svn.wordpress.org/trunk@31651


git-svn-id: http://core.svn.wordpress.org/trunk@31632 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-03-06 22:57:26 +00:00

1 line
9.3 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),H.innerHTML=a,d(H.value)}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(){var a="";return K._links&&K._links.canonical&&(a=K._links.canonical),!a&&K.u&&(a=K.u),!a&&K._meta&&(K._meta["twitter:url"]?a=K._meta["twitter:url"]:K._meta["og:url"]&&(a=K._meta["og:url"])),f(decodeURI(a))}function h(){var a="";return K._meta&&(K._meta["og:site_name"]?a=K._meta["og:site_name"]:K._meta["application-name"]&&(a=K._meta["application-name"])),e(a)}function i(){var a="";return K.t&&(a=K.t),!a&&K._meta&&(K._meta["twitter:title"]?a=K._meta["twitter:title"]:K._meta["og:title"]?a=K._meta["og:title"]:K._meta.title&&(a=K._meta.title)),a||(a=c("newPost"),O=!0),e(a)}function j(){var a="",b="",d=i(),f=g(),j=h();return K.s?b=K.s:K._meta&&(K._meta["twitter:description"]?b=K._meta["twitter:description"]:K._meta["og:description"]?b=K._meta["og:description"]:K._meta.description&&(b=K._meta.description)),b&&J.html.quote&&(a=J.html.quote.replace(/%1\$s/g,e(b))),f&&J.html.link&&(d&&c("newPost")!==d||j)&&(a+=J.html.link.replace(/%1\$s/g,encodeURI(f)).replace(/%2\$s/g,d||j)),a||""}function k(){var b=K._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(c){G=!1,m();var d=a("#pressthis-form");"publish"===c&&a("#post_status").val("publish"),F&&F.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.redirInParent){try{b.opener.location.href=a.data.redirect}catch(c){}b.self.close()}else b.location.href=a.data.redirect}else t(a.data.errorMessage),n()}})}function p(a,b,c){var d="";F&&(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",R||F.focus(),F.execCommand("mceInsertContent",!1,d),R=!0)}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>").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)}),E()}else t(b.data.errorMessage)}))}function r(){K.u&&K.u.match(/^https?:/)&&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(){K.errors&&a.each(K.errors,function(a,b){t(b)}),K.v&&K._version&&K.v+""!=K._version+""&&a(".should-upgrade-bookmarklet").removeClass("is-hidden")}function v(){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(){G=!0}).on("paste",function(){G=!0,setTimeout(function(){c.text(c.text())},100)})}function w(){Q&&(F||(F=b.tinymce.get("pressthis")),F&&(F.setContent(Q),F.on("focus",function(){R=!0})))}function x(){var b=a("#featured-media-container"),d=a("#all-media-container"),e=0;return d.empty(),(N||M)&&d.append('<h2 class="screen-reader-text">'+c("allMediaHeading")+'</h2><ul class="wppt-all-media-list"/>'),N&&a.each(N,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)&&p("embed",g)}).appendTo(".wppt-all-media-list",d),e++}),M&&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)&&p("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 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(T).one(W,function(){a(this).addClass(U)}),e.removeClass(V).one(W,function(){a(this).find(".modal-close").focus()})}),e.on("click",function(){var d=a(this).parent(),e=d.index();b.removeClass(V),d.addClass(T),W?d.one(W,function(){a(this).addClass(U),c.eq(e-1).focus()}):setTimeout(function(){d.addClass(U),c.eq(e-1).focus()},350)})}function z(){I=!0,a(".options-open, .press-this-actions, #scanbar").addClass(U),a(".options-close, .options-panel-back").removeClass(U),a(".options-panel").removeClass(V).one("transitionend",function(){a(".post-option:first").focus()})}function A(){I=!1,a(".options-close, .options-panel-back").addClass(U),a(".options-open, .press-this-actions, #scanbar").removeClass(U),a(".options-panel").addClass(T).one("transitionend",function(){a(this).addClass(U),a(".post-options").removeClass(V),a(".setting-modal").addClass(V)})}function B(){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 C(){r(),v(),x(),a(document).on("tinymce-editor-init",w),u()}function D(){return a("#current-site a").click(function(a){a.preventDefault()}),a("#draft-field").on("click",function(){o("draft")}),a("#publish-field").on("click",function(){o("publish")}),y(),B(),a(".options-open").on("click.press-this",z),a(".options-close").on("click.press-this",A),a(".options-panel, .options-panel-back").on("focusout.press-this",function(){setTimeout(function(){var b=document.activeElement,c=a(b);!I||!b||c.hasClass("options-panel-back")||"BODY"!==b.nodeName&&(c.closest(".options-panel").length||c.closest(".options-open").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()||"")}),a(b).on("beforeunload.press-this",function(){return G||F&&F.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",q),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 E(){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 F,G=!1,H=document.createElement("textarea"),I=!1,J=b.wpPressThisConfig||{},K=b.wpPressThisData||{},L=128,M=l(K)||[],N=k(K)||[],O=!1,P=i(K),Q=j(K),R=!1,S=[],T="is-off-screen",U="is-hidden",V=T+" "+U,W=function(){var a=document.documentElement.style;return"undefined"!=typeof a.transition?"transitionend":"undefined"!=typeof a.WebkitTransition?"webkitTransitionEnd":!1}();return a(document).ready(function(){C(),D(),E()}),{renderNotice:s,renderError:t}};b.wp=b.wp||{},b.wp.pressThis=new c}(jQuery,window);