WordPress/wp-admin/js/press-this.min.js
Andrew Ozz f53199487d PressThis:
- Improve handling of the data, both from the bookmarklet and from server-side parsing.
- Standardize on processing the data in PHP and remove duplicate code from JS.
- Improve the bookmarklet code and remove pre-filtering of the data.
Part props stephdau, see #31373.
Built from https://develop.svn.wordpress.org/trunk@31609


git-svn-id: http://core.svn.wordpress.org/trunk@31590 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-03-04 19:29:25 +00:00

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),G.innerHTML=a,d(G.value)}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(){var a="";return I._links&&I._links.canonical&&I._links.canonical.length&&(a=I._links.canonical),!a.length&&I.u&&(a=I.u),!a.length&&I._meta&&(I._meta["twitter:url"]&&I._meta["twitter:url"].length?a=I._meta["twitter:url"]:I._meta["og:url"]&&I._meta["og:url"].length&&(a=I._meta["og:url"])),f(decodeURI(a))}function h(){var a="";return I._meta&&(I._meta["og:site_name"]&&I._meta["og:site_name"].length?a=I._meta["og:site_name"]:I._meta["application-name"]&&I._meta["application-name"].length&&(a=I._meta["application-name"])),e(a)}function i(){var a="";return I.t&&(a=I.t),!a&&I._meta&&(I._meta["twitter:title"]&&I._meta["twitter:title"].length?a=I._meta["twitter:title"]:I._meta["og:title"]&&I._meta["og:title"].length?a=I._meta["og:title"]:I._meta.title&&I._meta.title.length&&(a=I._meta.title)),a||(a=c("newPost"),M=!0),e(a)}function j(){var a="",b="",d=i(),f=g(),j=h();return I.s&&I.s.length?b=I.s:I._meta&&(I._meta["twitter:description"]&&I._meta["twitter:description"].length?b=I._meta["twitter:description"]:I._meta["og:description"]&&I._meta["og:description"].length?b=I._meta["og:description"]:I._meta.description&&I._meta.description.length&&(b=I._meta.description)),b&&H.html.quote&&(a=H.html.quote.replace(/%1\$s/g,e(b))),f&&H.html.link&&(d&&c("newPost")!==d||j)&&(a+=H.html.link.replace(/%1\$s/g,encodeURI(f)).replace(/%2\$s/g,d||j)),a||""}function k(){var b=I._embed||[],c=[],d=[];return b.length&&a.each(b,function(b,e){if(e&&e.length){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),b&&b.length){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){F=!1,m();var d=a("#pressthis-form");"publish"===c&&a("#post_status").val("publish"),E&&E.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&&H.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="";E&&(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",P||E.focus(),E.execCommand("mceInsertContent",!1,d),P=!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)}),D()}else t(b.data.errorMessage)}))}function r(){I.u&&I.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(){I.errors&&I.errors.length&&a.each(I.errors,function(a,b){t(b)}),I.v&&I._version&&I.v+""!=I._version+""&&a(".should-upgrade-bookmarklet").removeClass("is-hidden")}function v(){var b=N||"",c=a("#title-container");M||(a("#title-field").val(b),c.text(b),a(".post-title-placeholder").addClass("is-hidden")),c.on("keyup",function(){F=!0}).on("paste",function(){F=!0,setTimeout(function(){c.text(c.text())},100)})}function w(){O&&O.length&&(E||(E=b.tinymce.get("pressthis")),E&&(E.setContent(O),E.on("focus",function(){P=!0})))}function x(){var b=a("#featured-media-container"),d=a("#all-media-container"),e=0;return d.empty(),(L&&L.length||K&&K.length)&&d.append('<h2 class="screen-reader-text">'+c("allMediaHeading")+'</h2><ul class="wppt-all-media-list"/>'),L&&L.length&&a.each(L,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.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)&&p("embed",g)}).appendTo(".wppt-all-media-list",d),e++}),K&&K.length&&a.each(K,function(b,g){g=f(g);var h=g.replace(/^(http[^\?]+)(\?.*)?$/,"$1");h=g.indexOf("files.wordpress.com/")>-1?h.replace(/\?.*$/,"")+"?w="+J:g.indexOf("gravatar.com/")>-1?h.replace(/\?.*$/,"")+"?s="+J: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,I.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="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(R,function(){a(this).addClass(c)}),h.removeClass(b+" "+c).one(R,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(R,function(){a(this).addClass(c),e.eq(h-1).focus()}),R||setTimeout(function(){g.addClass(c),e.eq(h-1).focus()},350)})}function z(){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 A(){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 B(){r(),v(),x(),a(document).on("tinymce-editor-init",w),u()}function C(){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(),z(),A(),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 F||E&&E.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",q),a(".categories-search").on("keyup.press-this",function(){var b=a(this).val().toLowerCase()||"";/[\x20-\xFF]+/.test(b)&&b.length<2||(a.each(Q,function(a,b){b.node.removeClass("is-hidden searched-parent")}),b&&a.each(Q,function(a,c){-1===c.text.indexOf(b)?c.node.addClass("is-hidden"):c.parents.addClass("searched-parent")}))}),!0}function D(){a(".categories-select").find("li").each(function(){var b=a(this);Q.push({node:b,parents:b.parents("li"),text:b.children("label").text().toLowerCase()})})}var E,F=!1,G=document.createElement("textarea"),H=b.wpPressThisConfig||{},I=b.wpPressThisData||{},J=128,K=l(I)||[],L=k(I)||[],M=!1,N=i(I),O=j(I),P=!1,Q=[],R=function(){var a=document.documentElement.style;return"undefined"!=typeof a.transition?"transitionend":"undefined"!=typeof a.WebkitTransition?"webkitTransitionEnd":!1}();return a(document).ready(function(){B(),C(),D()}),{renderNotice:s,renderError:t}};b.wp=b.wp||{},b.wp.pressThis=new c}(jQuery,window);