WordPress/wp-admin/js/editor-expand.min.js
Aaron Jorbin a870c7e8f3 Build/Test: Update dependencies for 5.0
Updates package dependencies to more modern versions, also adds .nvmrc and package-lock.json as followups to [43683] and [43571].

See #44600.
Fixes #45064.


Built from https://develop.svn.wordpress.org/branches/5.0@43684


git-svn-id: http://core.svn.wordpress.org/branches/5.0@43513 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-10-09 02:52:45 +00:00

1 line
13 KiB
JavaScript

!function(L,M,t){"use strict";var V=M(L),N=M(document),j=M("#wpadminbar"),q=M("#wpfooter");M(function(){var w,e,u=M("#postdivrich"),H=M("#wp-content-wrap"),b=M("#wp-content-editor-tools"),v=M(),x=M(),y=M("#ed_toolbar"),T=M("#content"),i=T[0],o=0,B=M("#post-status-info"),C=M(),S=M(),O=M("#side-sortables"),z=M("#postbox-container-1"),E=M("#post-body"),k=L.wp.editor&&L.wp.editor.fullscreen,r=function(){},l=function(){},A=!1,W=!1,K=!1,R=!1,Y=0,U=56,D=20,P=300,n=H.hasClass("tmce-active")?"tinymce":"html",X=!!parseInt(L.getUserSetting("hidetb"),10),F={windowHeight:0,windowWidth:0,adminBarHeight:0,toolsHeight:0,menuBarHeight:0,visualTopHeight:0,textTopHeight:0,bottomHeight:0,statusBarHeight:0,sideSortablesHeight:0},s=L._.throttle(function(){var t=L.scrollX||document.documentElement.scrollLeft,e=L.scrollY||document.documentElement.scrollTop,o=parseInt(i.style.height,10);i.style.height=P+"px",i.scrollHeight>P&&(i.style.height=i.scrollHeight+"px"),void 0!==t&&L.scrollTo(t,e),i.scrollHeight<o&&p()},300);function I(){var t=i.value.length;w&&!w.isHidden()||(w||"tinymce"!==n)&&(t<o?s():parseInt(i.style.height,10)<i.scrollHeight&&(i.style.height=Math.ceil(i.scrollHeight)+"px",p()),o=t)}function p(t){if(!k||!k.settings.visible){var e,o,i,n,s,f,a,d,c,u=V.scrollTop(),r=t&&t.type,l="scroll"!==r,p=w&&!w.isHidden(),g=P,h=E.offset().top,m=H.width();!l&&F.windowHeight||(c=V.width(),(F={windowHeight:V.height(),windowWidth:c,adminBarHeight:600<c?j.outerHeight():0,toolsHeight:b.outerHeight()||0,menuBarHeight:C.outerHeight()||0,visualTopHeight:v.outerHeight()||0,textTopHeight:y.outerHeight()||0,bottomHeight:B.outerHeight()||0,statusBarHeight:S.outerHeight()||0,sideSortablesHeight:O.height()||0}).menuBarHeight<3&&(F.menuBarHeight=0)),p||"resize"!==r||I(),f=p?(e=v,o=x,F.visualTopHeight):(e=y,o=T,F.textTopHeight),(p||e.length)&&(s=e.parent().offset().top,a=o.offset().top,d=o.outerHeight(),(p?P+f:P+20)+5<d?((!A||l)&&u>=s-F.toolsHeight-F.adminBarHeight&&u<=s-F.toolsHeight-F.adminBarHeight+d-g?(A=!0,b.css({position:"fixed",top:F.adminBarHeight,width:m}),p&&C.length&&C.css({position:"fixed",top:F.adminBarHeight+F.toolsHeight,width:m-2-(p?0:e.outerWidth()-e.width())}),e.css({position:"fixed",top:F.adminBarHeight+F.toolsHeight+F.menuBarHeight,width:m-2-(p?0:e.outerWidth()-e.width())})):(A||l)&&(u<=s-F.toolsHeight-F.adminBarHeight?(A=!1,b.css({position:"absolute",top:0,width:m}),p&&C.length&&C.css({position:"absolute",top:0,width:m-2}),e.css({position:"absolute",top:F.menuBarHeight,width:m-2-(p?0:e.outerWidth()-e.width())})):u>=s-F.toolsHeight-F.adminBarHeight+d-g&&(A=!1,b.css({position:"absolute",top:d-g,width:m}),p&&C.length&&C.css({position:"absolute",top:d-g,width:m-2}),e.css({position:"absolute",top:d-g+F.menuBarHeight,width:m-2-(p?0:e.outerWidth()-e.width())}))),(!W||l&&X)&&u+F.windowHeight<=a+d+F.bottomHeight+F.statusBarHeight+1?t&&0<t.deltaHeight&&t.deltaHeight<100?L.scrollBy(0,t.deltaHeight):p&&X&&(W=!0,S.css({position:"fixed",bottom:F.bottomHeight,visibility:"",width:m-2}),B.css({position:"fixed",bottom:0,width:m})):(!X&&W||(W||l)&&u+F.windowHeight>a+d+F.bottomHeight+F.statusBarHeight-1)&&(W=!1,S.attr("style",X?"":"visibility: hidden;"),B.attr("style",""))):l&&(b.css({position:"absolute",top:0,width:m}),p&&C.length&&C.css({position:"absolute",top:0,width:m-2}),e.css({position:"absolute",top:F.menuBarHeight,width:m-2-(p?0:e.outerWidth()-e.width())}),S.attr("style",X?"":"visibility: hidden;"),B.attr("style","")),z.width()<300&&600<F.windowWidth&&N.height()>O.height()+h+120&&F.windowHeight<d?(F.sideSortablesHeight+U+D>F.windowHeight||K||R?u+U<=h?(O.attr("style",""),K=R=!1):Y<u?K?(K=!1,i=O.offset().top-F.adminBarHeight,(n=q.offset().top)<i+F.sideSortablesHeight+D&&(i=n-F.sideSortablesHeight-12),O.css({position:"absolute",top:i,bottom:""})):!R&&F.sideSortablesHeight+O.offset().top+D<u+F.windowHeight&&(R=!0,O.css({position:"fixed",top:"auto",bottom:D})):u<Y&&(R?(R=!1,i=O.offset().top-D,(n=q.offset().top)<i+F.sideSortablesHeight+D&&(i=n-F.sideSortablesHeight-12),O.css({position:"absolute",top:i,bottom:""})):!K&&O.offset().top>=u+U&&(K=!0,O.css({position:"fixed",top:U,bottom:""}))):(h-U<=u?O.css({position:"fixed",top:U}):O.attr("style",""),K=R=!1),Y=u):(O.attr("style",""),K=R=!1),l&&(H.css({paddingTop:F.toolsHeight}),p?x.css({paddingTop:F.visualTopHeight+F.menuBarHeight}):T.css({marginTop:F.textTopHeight})))}}function f(){I(),p()}function g(t){for(var e=1;e<6;e++)setTimeout(t,500*e)}function t(){L.pageYOffset&&130<L.pageYOffset&&L.scrollTo(L.pageXOffset,0),u.addClass("wp-editor-expand"),V.on("scroll.editor-expand resize.editor-expand",function(t){p(t.type),clearTimeout(e),e=setTimeout(p,100)}),N.on("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",p).on("postbox-toggled.editor-expand postbox-moved.editor-expand",function(){!K&&!R&&L.pageYOffset>U&&(R=!0,L.scrollBy(0,-1),p(),L.scrollBy(0,1)),p()}).on("wp-window-resized.editor-expand",function(){w&&!w.isHidden()?w.execCommand("wpAutoResize"):I()}),T.on("focus.editor-expand input.editor-expand propertychange.editor-expand",I),r(),k&&k.pubsub.subscribe("hidden",f),w&&(w.settings.wp_autoresize_on=!0,w.execCommand("wpAutoResizeOn"),w.isHidden()||w.execCommand("wpAutoResize")),w&&!w.isHidden()||I(),p(),N.trigger("editor-expand-on")}function a(){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"),V.off(".editor-expand"),N.off(".editor-expand"),T.off(".editor-expand"),l(),k&&k.pubsub.unsubscribe("hidden",f),M.each([v,y,b,C,B,S,H,x,T,O],function(t,e){e&&e.attr("style","")}),A=W=K=R=!1,w&&(w.settings.wp_autoresize_on=!1,w.execCommand("wpAutoResizeOff"),w.isHidden()||(T.hide(),t&&w.theme.resizeTo(null,t))),t&&T.height(t),N.trigger("editor-expand-off")}N.on("tinymce-editor-init.editor-expand",function(t,f){var a=L.tinymce.util.VK,e=_.debounce(function(){!M(".mce-floatpanel:hover").length&&L.tinymce.ui.FloatPanel.hideAll(),M(".mce-tooltip").hide()},1e3,!0);function o(t){var e=t.keyCode;e<=47&&e!==a.SPACEBAR&&e!==a.ENTER&&e!==a.DELETE&&e!==a.BACKSPACE&&e!==a.UP&&e!==a.LEFT&&e!==a.DOWN&&e!==a.UP||91<=e&&e<=93||112<=e&&e<=123||144===e||145===e||i(e)}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=F.adminBarHeight+F.toolsHeight+F.menuBarHeight+F.visualTopHeight,(n=F.windowHeight-(X?F.bottomHeight+F.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(){V.on("scroll.mce-float-panels",e),setTimeout(function(){f.execCommand("wpAutoResize"),p()},300)}function d(){V.off("scroll.mce-float-panels"),setTimeout(function(){var t=H.offset().top;L.pageYOffset>t&&L.scrollTo(L.pageXOffset,t-F.adminBarHeight),I(),p()},100),p()}function c(){X=!X}"content"===f.id&&((w=f).settings.autoresize_min_height=P,v=H.find(".mce-toolbar-grp"),x=H.find(".mce-edit-area"),S=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),V.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),V.off("scroll.mce-float-panels")},u.hasClass("wp-editor-expand")&&(r(),g(p)))}),u.hasClass("wp-editor-expand")&&(t(),H.hasClass("html-active")&&g(function(){p(),I()})),M("#adv-settings .editor-expand").show(),M("#editor-expand-toggle").on("change.editor-expand",function(){M(this).prop("checked")?(t(),L.setUserSetting("editor_expand","on")):(a(),L.setUserSetting("editor_expand","off"))}),L.editorExpand={on:t,off:a}}),M(function(){var i,n,t,s,f,a,d,c,u,r,l,p=M(document.body),o=M("#wpcontent"),g=M("#post-body-content"),e=M("#title"),h=M("#content"),m=M(document.createElement("DIV")),w=M("#edit-slug-box"),H=w.find("a").add(w.find("button")).add(w.find("input")),b=M("#adminmenuwrap"),v=(M(),M(),"on"===L.getUserSetting("editor_expand","on")),x=!!v&&"on"===L.getUserSetting("post_dfw"),y=0,T=0,B=20;function C(){(s=g.offset()).right=s.left+g.outerWidth(),s.bottom=s.top+g.outerHeight()}function S(){v||(v=!0,N.trigger("dfw-activate"),h.on("keydown.focus-shortcut",Y))}function O(){v&&(E(),v=!1,N.trigger("dfw-deactivate"),h.off("keydown.focus-shortcut"))}function z(){!x&&v&&(x=!0,h.on("keydown.focus",k),e.add(h).on("blur.focus",W),k(),L.setUserSetting("post_dfw","on"),N.trigger("dfw-on"))}function E(){x&&(x=!1,e.add(h).off(".focus"),A(),g.off(".focus"),L.setUserSetting("post_dfw","off"),N.trigger("dfw-off"))}function _(){x?E():z()}function k(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)?A(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(){C(),V.on("scroll.focus",function(){var t=L.pageYOffset;c&&d&&c!==t&&(d<s.top-B||d>s.bottom+B)&&A(),c=t})}).on("mouseleave.focus",function(){f=a=null,y=T=0,V.off("scroll.focus")}).on("mousemove.focus",function(t){var e=t.clientX,o=t.clientY,i=L.pageYOffset,n=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-n||f<=e&&e>s.right-n){if(y+=Math.abs(f-e),T+=Math.abs(a-o),(o<=s.top-B-i||o>=s.bottom+B-i||e<=s.left-B-n||e>=s.right+B-n)&&(10<y||10<T))return A(),f=a=null,void(y=T=0)}else y=T=0;f=e,a=o}).on("touchstart.focus",function(t){t.preventDefault(),A()}),g.off("mouseenter.focus"),u&&(clearTimeout(u),u=null),p.addClass("focus-on").removeClass("focus-off")),!n&&i&&(n=!0,j.on("mouseenter.focus",function(){j.addClass("focus-off")}).on("mouseleave.focus",function(){j.removeClass("focus-off")})),K())}function A(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(){(M.contains(g.get(0),document.activeElement)||l)&&k()}),u=setTimeout(function(){u=null,g.off("mouseenter.focus")},1e3),p.addClass("focus-off").removeClass("focus-on")),n&&(n=!1,j.off(".focus")),R()}function W(){setTimeout(function(){var t=document.activeElement.compareDocumentPosition(g.get(0));function e(t){return M.contains(t.get(0),document.activeElement)}2!==t&&4!==t||!(e(b)||e(o)||e(q))||A()},0)}function K(){t||!i||w.find(":focus").length||(t=!0,w.stop().fadeTo("fast",.3).on("mouseenter.focus",R).off("mouseleave.focus"),H.on("focus.focus",R).off("blur.focus"))}function R(){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&&_()}p.append(m),m.css({display:"none",position:"fixed",top:j.height(),right:0,bottom:0,left:0,"z-index":9997}),g.css({position:"relative"}),V.on("mousemove.focus",function(t){d=t.pageY}),M("#postdivrich").hasClass("wp-editor-expand")&&h.on("keydown.focus-shortcut",Y),N.on("tinymce-editor-setup.focus",function(t,e){e.addButton("dfw",{active:x,classes:"wp-dfw btn widget",disabled:!v,onclick:_,onPostRender:function(){var t=this;N.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",_),e.addShortcut("access+w","","wpToggleDFW")}),N.on("tinymce-editor-init.focus",function(t,e){var o,i;function n(){l=!0}function s(){l=!1}"content"===e.id&&(M(e.getWin()),M(e.getContentAreaContainer()).find("iframe"),o=function(){e.on("keydown",k),e.on("blur",W),e.on("focus",n),e.on("blur",s),e.on("wp-autoresize",C)},i=function(){e.off("keydown",k),e.off("blur",W),e.off("focus",n),e.off("blur",s),e.off("wp-autoresize",C)},x&&o(),N.on("dfw-on.focus",o).on("dfw-off.focus",i),e.on("click",function(t){t.target===e.getDoc().documentElement&&e.focus()}))}),N.on("quicktags-init",function(t,e){var o;e.settings.buttons&&-1!==(","+e.settings.buttons+",").indexOf(",dfw,")&&(o=M("#"+e.name+"_dfw"),M(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")}))}),N.on("editor-expand-on.focus",S).on("editor-expand-off.focus",O),x&&(h.on("keydown.focus",k),e.add(h).on("blur.focus",W)),L.wp=L.wp||{},L.wp.editor=L.wp.editor||{},L.wp.editor.dfw={activate:S,deactivate:O,isActive:function(){return v},on:z,off:E,toggle:_,isOn:function(){return x}}})}(window,window.jQuery);