WordPress/wp-admin/js/editor-expand.min.js

1 line
14 KiB
JavaScript

!function(L,V){"use strict";var j=V(L),I=V(document),M=V("#wpadminbar"),N=V("#wpfooter");V(function(){var g,e,u=V("#postdivrich"),h=V("#wp-content-wrap"),m=V("#wp-content-editor-tools"),w=V(),H=V(),b=V("#ed_toolbar"),v=V("#content"),x=V('<div id="content-textarea-clone" class="wp-exclude-emoji"></div>'),y=V("#post-status-info"),C=V(),T=V(),B=V("#side-sortables"),O=V("#postbox-container-1"),S=V("#post-body"),z=L.wp.editor&&L.wp.editor.fullscreen,r=function(){},l=function(){},E=!1,k=!1,A=!1,R=!1,K=0,W=56,Y=20,U=300,o=h.hasClass("tmce-active")?"tinymce":"html",P=!!parseInt(L.getUserSetting("hidetb"),10),D={windowHeight:0,windowWidth:0,adminBarHeight:0,toolsHeight:0,menuBarHeight:0,visualTopHeight:0,textTopHeight:0,bottomHeight:0,statusBarHeight:0,sideSortablesHeight:0};function t(t){var e,o,i,n=jQuery.ui.keyCode,s=t.keyCode,f=document.createRange(),a=v[0].selectionStart,d=v[0].selectionEnd,c=x[0].firstChild;if(!a||!d||a===d){try{f.setStart(c,a),f.setEnd(c,d+1)}catch(t){}(i=f.getBoundingClientRect()).height&&(o=(e=i.top-10)+i.height+10,t=D.adminBarHeight+D.toolsHeight+D.textTopHeight,i=D.windowHeight-D.bottomHeight,e<t&&(s===n.UP||s===n.LEFT||s===n.BACKSPACE)?L.scrollTo(L.pageXOffset,e+L.pageYOffset-t):i<o&&L.scrollTo(L.pageXOffset,o+L.pageYOffset-i))}}function X(){var t,e;g&&!g.isHidden()||!g&&"tinymce"===o||(t=v.height(),x.width(v.width()-22),x.text(v.val()+"&nbsp;"),(e=(e=x.height())<U?U:e)!==t&&(v.height(e),p()))}function p(t){var e,o,i,n,s,f,a,d,c,u,r,l,p;z&&z.settings.visible||(e=j.scrollTop(),o="scroll"!==(r=t&&t.type),i=g&&!g.isHidden(),n=U,s=S.offset().top,f=h.width(),!o&&D.windowHeight||(p=j.width(),(D={windowHeight:j.height(),windowWidth:p,adminBarHeight:600<p?M.outerHeight():0,toolsHeight:m.outerHeight()||0,menuBarHeight:C.outerHeight()||0,visualTopHeight:w.outerHeight()||0,textTopHeight:b.outerHeight()||0,bottomHeight:y.outerHeight()||0,statusBarHeight:T.outerHeight()||0,sideSortablesHeight:B.height()||0}).menuBarHeight<3&&(D.menuBarHeight=0)),i||"resize"!==r||X(),u=i?(a=w,l=H,D.visualTopHeight):(a=b,l=v,D.textTopHeight),(i||a.length)&&(p=a.parent().offset().top,r=l.offset().top,l=l.outerHeight(),(i?U+u:U+20)+5<l?((!E||o)&&e>=p-D.toolsHeight-D.adminBarHeight&&e<=p-D.toolsHeight-D.adminBarHeight+l-n?(E=!0,m.css({position:"fixed",top:D.adminBarHeight,width:f}),i&&C.length&&C.css({position:"fixed",top:D.adminBarHeight+D.toolsHeight,width:f-2-(i?0:a.outerWidth()-a.width())}),a.css({position:"fixed",top:D.adminBarHeight+D.toolsHeight+D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())})):(E||o)&&(e<=p-D.toolsHeight-D.adminBarHeight?(E=!1,m.css({position:"absolute",top:0,width:f}),i&&C.length&&C.css({position:"absolute",top:0,width:f-2}),a.css({position:"absolute",top:D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())})):e>=p-D.toolsHeight-D.adminBarHeight+l-n&&(E=!1,m.css({position:"absolute",top:l-n,width:f}),i&&C.length&&C.css({position:"absolute",top:l-n,width:f-2}),a.css({position:"absolute",top:l-n+D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())}))),(!k||o&&P)&&e+D.windowHeight<=r+l+D.bottomHeight+D.statusBarHeight+1?t&&0<t.deltaHeight&&t.deltaHeight<100?L.scrollBy(0,t.deltaHeight):P&&(k=!0,T.css({position:"fixed",bottom:D.bottomHeight,visibility:"",width:f-2}),y.css({position:"fixed",bottom:0,width:f})):(!P&&k||(k||o)&&e+D.windowHeight>r+l+D.bottomHeight+D.statusBarHeight-1)&&(k=!1,T.attr("style",P?"":"visibility: hidden;"),y.attr("style",""))):o&&(m.css({position:"absolute",top:0,width:f}),i&&C.length&&C.css({position:"absolute",top:0,width:f-2}),a.css({position:"absolute",top:D.menuBarHeight,width:f-2-(i?0:a.outerWidth()-a.width())}),T.attr("style",P?"":"visibility: hidden;"),y.attr("style","")),O.width()<300&&600<D.windowWidth&&I.height()>B.height()+s+120&&D.windowHeight<l?(D.sideSortablesHeight+W+Y>D.windowHeight||A||R?e+W<=s?(B.attr("style",""),A=R=!1):K<e?A?(A=!1,d=B.offset().top-D.adminBarHeight,(c=N.offset().top)<d+D.sideSortablesHeight+Y&&(d=c-D.sideSortablesHeight-12),B.css({position:"absolute",top:d,bottom:""})):!R&&D.sideSortablesHeight+B.offset().top+Y<e+D.windowHeight&&(R=!0,B.css({position:"fixed",top:"auto",bottom:Y})):e<K&&(R?(R=!1,d=B.offset().top-Y,(c=N.offset().top)<d+D.sideSortablesHeight+Y&&(d=c-D.sideSortablesHeight-12),B.css({position:"absolute",top:d,bottom:""})):!A&&B.offset().top>=e+W&&(A=!0,B.css({position:"fixed",top:W,bottom:""}))):(s-W<=e?B.css({position:"fixed",top:W}):B.attr("style",""),A=R=!1),K=e):(B.attr("style",""),A=R=!1),o&&(h.css({paddingTop:D.toolsHeight}),i?H.css({paddingTop:D.visualTopHeight+D.menuBarHeight}):(v.css({marginTop:D.textTopHeight}),x.width(f-20-2)))))}function i(){X(),p()}function F(t){for(var e=1;e<6;e++)setTimeout(t,500*e)}function n(){L.pageYOffset&&130<L.pageYOffset&&L.scrollTo(L.pageXOffset,0),u.addClass("wp-editor-expand"),j.on("scroll.editor-expand resize.editor-expand",function(t){p(t.type),clearTimeout(e),e=setTimeout(p,100)}),I.on("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",p).on("postbox-toggled.editor-expand",function(){!A&&!R&&L.pageYOffset>W&&(R=!0,L.scrollBy(0,-1),p(),L.scrollBy(0,1)),p()}).on("wp-window-resized.editor-expand",function(){g&&!g.isHidden()?g.execCommand("wpAutoResize"):X()}),v.on("focus.editor-expand input.editor-expand propertychange.editor-expand",X),v.on("keyup.editor-expand",t),r(),z&&z.pubsub.subscribe("hidden",i),g&&(g.settings.wp_autoresize_on=!0,g.execCommand("wpAutoResizeOn"),g.isHidden()||g.execCommand("wpAutoResize")),g&&!g.isHidden()||X(),p(),I.trigger("editor-expand-on")}function s(){var t=parseInt(L.getUserSetting("ed_size",300),10);t<50?t=50:5e3<t&&(t=5e3),L.pageYOffset&&130<L.pageYOffset&&L.scrollTo(L.pageXOffset,0),u.removeClass("wp-editor-expand"),j.off(".editor-expand"),I.off(".editor-expand"),v.off(".editor-expand"),l(),z&&z.pubsub.unsubscribe("hidden",i),V.each([w,b,m,C,y,T,h,H,v,B],function(t,e){e&&e.attr("style","")}),E=k=A=R=!1,g&&(g.settings.wp_autoresize_on=!1,g.execCommand("wpAutoResizeOff"),g.isHidden()||(v.hide(),t&&g.theme.resizeTo(null,t))),t&&v.height(t),I.trigger("editor-expand-off")}x.insertAfter(v),x.css({"font-family":v.css("font-family"),"font-size":v.css("font-size"),"line-height":v.css("line-height"),"white-space":"pre-wrap","word-wrap":"break-word"}),I.on("tinymce-editor-init.editor-expand",function(t,f){var a=L.tinymce.util.VK,e=_.debounce(function(){V(".mce-floatpanel:hover").length||L.tinymce.ui.FloatPanel.hideAll(),V(".mce-tooltip").hide()},1e3,!0);function o(t){t=t.keyCode;t<=47&&t!==a.SPACEBAR&&t!==a.ENTER&&t!==a.DELETE&&t!==a.BACKSPACE&&t!==a.UP&&t!==a.LEFT&&t!==a.DOWN&&t!==a.UP||91<=t&&t<=93||112<=t&&t<=123||144===t||145===t||i(t)}function i(t){var e,o,i,n,s=function(){var t,e,o,i=f.selection.getNode();if(f.wp&&f.wp.getView&&(e=f.wp.getView(i)))o=e.getBoundingClientRect();else{t=f.selection.getRng();try{o=t.getClientRects()[0]}catch(t){}o=o||i.getBoundingClientRect()}return!!o.height&&o}();s&&(o=(e=s.top+f.iframeElement.getBoundingClientRect().top)+s.height,e-=50,o+=50,i=D.adminBarHeight+D.toolsHeight+D.menuBarHeight+D.visualTopHeight,(n=D.windowHeight-(P?D.bottomHeight+D.statusBarHeight:0))-i<s.height||(e<i&&(t===a.UP||t===a.LEFT||t===a.BACKSPACE)?L.scrollTo(L.pageXOffset,e+L.pageYOffset-i):n<o&&L.scrollTo(L.pageXOffset,o+L.pageYOffset-n)))}function n(t){t.state||p()}function s(){j.on("scroll.mce-float-panels",e),setTimeout(function(){f.execCommand("wpAutoResize"),p()},300)}function d(){j.off("scroll.mce-float-panels"),setTimeout(function(){var t=h.offset().top;L.pageYOffset>t&&L.scrollTo(L.pageXOffset,t-D.adminBarHeight),X(),p()},100),p()}function c(){P=!P}"content"===f.id&&((g=f).settings.autoresize_min_height=U,w=h.find(".mce-toolbar-grp"),H=h.find(".mce-edit-area"),T=h.find(".mce-statusbar"),C=h.find(".mce-menubar"),r=function(){f.on("keyup",o),f.on("show",s),f.on("hide",d),f.on("wp-toolbar-toggle",c),f.on("setcontent wp-autoresize wp-toolbar-toggle",p),f.on("undo redo",i),f.on("FullscreenStateChanged",n),j.off("scroll.mce-float-panels").on("scroll.mce-float-panels",e)},l=function(){f.off("keyup",o),f.off("show",s),f.off("hide",d),f.off("wp-toolbar-toggle",c),f.off("setcontent wp-autoresize wp-toolbar-toggle",p),f.off("undo redo",i),f.off("FullscreenStateChanged",n),j.off("scroll.mce-float-panels")},u.hasClass("wp-editor-expand")&&(r(),F(p)))}),u.hasClass("wp-editor-expand")&&(n(),h.hasClass("html-active")&&F(function(){p(),X()})),V("#adv-settings .editor-expand").show(),V("#editor-expand-toggle").on("change.editor-expand",function(){V(this).prop("checked")?(n(),L.setUserSetting("editor_expand","on")):(s(),L.setUserSetting("editor_expand","off"))}),L.editorExpand={on:n,off:s}}),V(function(){var i,n,t,s,f,a,d,c,u,r,l,p=V(document.body),o=V("#wpcontent"),g=V("#post-body-content"),e=V("#title"),h=V("#content"),m=V(document.createElement("DIV")),w=V("#edit-slug-box"),H=w.find("a").add(w.find("button")).add(w.find("input")),b=V("#adminmenuwrap"),v=(V(),V(),"on"===L.getUserSetting("editor_expand","on")),x=!!v&&"on"===L.getUserSetting("post_dfw"),y=0,C=0,T=20;function B(){(s=g.offset()).right=s.left+g.outerWidth(),s.bottom=s.top+g.outerHeight()}function O(){v||(v=!0,I.trigger("dfw-activate"),h.on("keydown.focus-shortcut",Y))}function S(){v&&(E(),v=!1,I.trigger("dfw-deactivate"),h.off("keydown.focus-shortcut"))}function z(){!x&&v&&(x=!0,h.on("keydown.focus",A),e.add(h).on("blur.focus",R),A(),L.setUserSetting("post_dfw","on"),I.trigger("dfw-on"))}function E(){x&&(x=!1,e.add(h).off(".focus"),_(),g.off(".focus"),L.setUserSetting("post_dfw","off"),I.trigger("dfw-off"))}function k(){(x?E:z)()}function A(t){var e,o=t&&t.keyCode;L.navigator.platform&&(e=-1<L.navigator.platform.indexOf("Mac")),27===o||87===o&&t.altKey&&(!e&&t.shiftKey||e&&t.ctrlKey)?_(t):t&&(t.metaKey||t.ctrlKey&&!t.altKey||t.altKey&&t.shiftKey||o&&(o<=47&&8!==o&&13!==o&&32!==o&&46!==o||91<=o&&o<=93||112<=o&&o<=135||144<=o&&o<=150||224<=o))||(i||(i=!0,clearTimeout(r),r=setTimeout(function(){m.show()},600),g.css("z-index",9998),m.on("mouseenter.focus",function(){B(),j.on("scroll.focus",function(){var t=L.pageYOffset;c&&d&&c!==t&&(d<s.top-T||d>s.bottom+T)&&_(),c=t})}).on("mouseleave.focus",function(){f=a=null,y=C=0,j.off("scroll.focus")}).on("mousemove.focus",function(t){var e=t.clientX,o=t.clientY,i=L.pageYOffset,t=L.pageXOffset;if(f&&a&&(e!==f||o!==a))if(o<=a&&o<s.top-i||a<=o&&o>s.bottom-i||e<=f&&e<s.left-t||f<=e&&e>s.right-t){if(y+=Math.abs(f-e),C+=Math.abs(a-o),(o<=s.top-T-i||o>=s.bottom+T-i||e<=s.left-T-t||e>=s.right+T-t)&&(10<y||10<C))return _(),f=a=null,void(y=C=0)}else y=C=0;f=e,a=o}).on("touchstart.focus",function(t){t.preventDefault(),_()}),g.off("mouseenter.focus"),u&&(clearTimeout(u),u=null),p.addClass("focus-on").removeClass("focus-off")),!n&&i&&(n=!0,M.on("mouseenter.focus",function(){M.addClass("focus-off")}).on("mouseleave.focus",function(){M.removeClass("focus-off")})),K())}function _(t){i&&(i=!1,clearTimeout(r),r=setTimeout(function(){m.hide()},200),g.css("z-index",""),m.off("mouseenter.focus mouseleave.focus mousemove.focus touchstart.focus"),void 0===t&&g.on("mouseenter.focus",function(){(V.contains(g.get(0),document.activeElement)||l)&&A()}),u=setTimeout(function(){u=null,g.off("mouseenter.focus")},1e3),p.addClass("focus-off").removeClass("focus-on")),n&&(n=!1,M.off(".focus")),W()}function R(){setTimeout(function(){var t=document.activeElement.compareDocumentPosition(g.get(0));function e(t){return V.contains(t.get(0),document.activeElement)}2!==t&&4!==t||!(e(b)||e(o)||e(N))||_()},0)}function K(){t||!i||w.find(":focus").length||(t=!0,w.stop().fadeTo("fast",.3).on("mouseenter.focus",W).off("mouseleave.focus"),H.on("focus.focus",W).off("blur.focus"))}function W(){t&&(t=!1,w.stop().fadeTo("fast",1).on("mouseleave.focus",K).off("mouseenter.focus"),H.on("blur.focus",K).off("focus.focus"))}function Y(t){t.altKey&&t.shiftKey&&87===t.keyCode&&k()}p.append(m),m.css({display:"none",position:"fixed",top:M.height(),right:0,bottom:0,left:0,"z-index":9997}),g.css({position:"relative"}),j.on("mousemove.focus",function(t){d=t.pageY}),V("#postdivrich").hasClass("wp-editor-expand")&&h.on("keydown.focus-shortcut",Y),I.on("tinymce-editor-setup.focus",function(t,e){e.addButton("dfw",{active:x,classes:"wp-dfw btn widget",disabled:!v,onclick:k,onPostRender:function(){var t=this;I.on("dfw-activate.focus",function(){t.disabled(!1)}).on("dfw-deactivate.focus",function(){t.disabled(!0)}).on("dfw-on.focus",function(){t.active(!0)}).on("dfw-off.focus",function(){t.active(!1)})},tooltip:"Distraction-free writing mode",shortcut:"Alt+Shift+W"}),e.addCommand("wpToggleDFW",k),e.addShortcut("access+w","","wpToggleDFW")}),I.on("tinymce-editor-init.focus",function(t,e){var o,i;function n(){l=!0}function s(){l=!1}"content"===e.id&&(V(e.getWin()),V(e.getContentAreaContainer()).find("iframe"),o=function(){e.on("keydown",A),e.on("blur",R),e.on("focus",n),e.on("blur",s),e.on("wp-autoresize",B)},i=function(){e.off("keydown",A),e.off("blur",R),e.off("focus",n),e.off("blur",s),e.off("wp-autoresize",B)},x&&o(),I.on("dfw-on.focus",o).on("dfw-off.focus",i),e.on("click",function(t){t.target===e.getDoc().documentElement&&e.focus()}))}),I.on("quicktags-init",function(t,e){var o;e.settings.buttons&&-1!==(","+e.settings.buttons+",").indexOf(",dfw,")&&(o=V("#"+e.name+"_dfw"),V(document).on("dfw-activate",function(){o.prop("disabled",!1)}).on("dfw-deactivate",function(){o.prop("disabled",!0)}).on("dfw-on",function(){o.addClass("active")}).on("dfw-off",function(){o.removeClass("active")}))}),I.on("editor-expand-on.focus",O).on("editor-expand-off.focus",S),x&&(h.on("keydown.focus",A),e.add(h).on("blur.focus",R)),L.wp=L.wp||{},L.wp.editor=L.wp.editor||{},L.wp.editor.dfw={activate:O,deactivate:S,isActive:function(){return v},on:z,off:E,toggle:k,isOn:function(){return x}}})}(window,window.jQuery);