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

1 line
13 KiB
JavaScript

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