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

1 line
11 KiB
JavaScript

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