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

1 line
6.0 KiB
JavaScript

window.wp=window.wp||{},jQuery(document).ready(function(a){function b(a){var b,c,d,e,f,g=jQuery.ui.keyCode,h=a.keyCode,i=document.createRange(),j=w[0].selectionStart,k=w[0].selectionEnd,l=x[0].firstChild,m=o.height(),n=10;if(!j||!k||j===k){try{i.setStart(l,j),i.setEnd(l,k+1)}catch(p){}b=i.getBoundingClientRect(),b.height&&(c=b.top-n,d=c+b.height+n,e=q.outerHeight()+u.outerHeight()+v.outerHeight(),f=m-y.outerHeight(),e>c&&(h===g.UP||h===g.LEFT||h===g.BACKSPACE)?window.scrollTo(window.pageXOffset,c+window.pageYOffset-e):d>f&&window.scrollTo(window.pageXOffset,d+window.pageYOffset-f))}}function c(){if(!m||m.isHidden()){var a,b=w.height();x.width(w.width()),x.text(w.val()+"&nbsp;"),a=x.height(),M>a&&(a=M),a!==b&&(w.height(a),d())}}function d(a){if(!C||!C.settings.visible){var b,c,d,e,f,g,h,i,n,s,D,E=y.outerHeight(),K=o.scrollTop(),N=o.height(),O=o.width(),P=O>600?q.height():0,Q="scroll"!==a,R=m&&!m.isHidden(),S=M+P,T=B.offset().top,U=1,V=t.width(),W=z.height();R?(b=j,c=k):(b=v,c=w),f=u.outerHeight(),g=b.parent().offset().top,h=b.outerHeight(),i=c.offset().top,n=c.outerHeight(),s=c.outerWidth(),D=R?l.outerHeight():0,(!F||Q)&&K>=g-f-P&&g-f-P+n-S>=K?(F=!0,b.css({position:"fixed",top:P+f,width:V-2*U-(R?0:b.outerWidth()-b.width()),borderTop:"1px solid #e5e5e5"}),u.css({position:"fixed",top:P,width:V})):(F||Q)&&(g-f-P>=K?(F=!1,b.css({position:"absolute",top:0,borderTop:"none",width:V-2*U-(R?0:b.outerWidth()-b.width())}),u.css({position:"absolute",top:0,width:V})):K>=g-f-P+n-S&&(F=!1,b.css({position:"absolute",top:n-S,width:V-2*U-(R?0:b.outerWidth()-b.width())}),u.css({position:"absolute",top:n-S+U,width:V}))),(!G||Q)&&i+n+E+D+U>=K+N?(G=!0,y.css({position:"fixed",bottom:0,width:s+2*U,borderTop:"1px solid #dedede"})):(G||Q)&&K+N>i+n+E+D-U&&(G=!1,y.css({position:"relative",bottom:"auto",width:"100%",borderTop:"none"})),A.width()<300&&O>600&&p.height()>z.height()+T+120&&.7*n>N?(W>N||H||I?T>=K+L?(z.attr("style",""),H=I=!1):K>J?H?(H=!1,d=z.offset().top-P,e=r.offset().top,d+W+20>e&&(d=e-W-20),z.css({position:"absolute",top:d,bottom:""})):!I&&W+z.offset().top+20<K+N&&(I=!0,z.css({position:"fixed",top:"auto",bottom:"20px"})):J>K&&(I?(I=!1,d=z.offset().top-20,e=r.offset().top,d+W+20>e&&(d=e-W-20),z.css({position:"absolute",top:d,bottom:""})):!H&&z.offset().top>=K+L&&(H=!0,z.css({position:"fixed",top:L,bottom:""}))):(K>=T-L?z.css({position:"fixed",top:L}):z.attr("style",""),H=I=!1),J=K):(z.attr("style",""),H=I=!1),Q&&(t.css({paddingTop:u.outerHeight()}),R?k.css({paddingTop:j.outerHeight()}):w.css({marginTop:v.outerHeight()}),x.width(V-20-2*U))}}function e(){c(),d()}function f(a){for(var b=1;6>b;b++)setTimeout(a,500*b)}function g(){clearTimeout(n),n=setTimeout(d,200)}function h(){window.pageYOffset&&window.pageYOffset>K&&window.scrollTo(window.pageXOffset,0),s.addClass("wp-editor-expand"),o.on("scroll.editor-expand resize.editor-expand",function(a){d(a.type),g()}),p.on("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",d),w.on("focus.editor-expand input.editor-expand propertychange.editor-expand",c),w.on("keyup.editor-expand",b),D(),C&&C.pubsub.subscribe("hidden",e),m&&(m.settings.wp_autoresize_on=!0,m.execCommand("wpAutoResizeOn"),m.isHidden()||m.execCommand("wpAutoResize")),(!m||m.isHidden())&&c(),d()}function i(){var f=window.getUserSetting("ed_size");window.pageYOffset&&window.pageYOffset>K&&window.scrollTo(window.pageXOffset,0),s.removeClass("wp-editor-expand"),o.off("scroll.editor-expand resize.editor-expand"),p.off("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",d),w.off("focus.editor-expand input.editor-expand propertychange.editor-expand",c),w.off("keyup.editor-expand",b),E(),C&&C.pubsub.unsubscribe("hidden",e),a.each([j,v,u,y,t,k,w,z],function(a,b){b&&b.attr("style","")}),F=G=H=I=!1,m&&(m.settings.wp_autoresize_on=!1,m.execCommand("wpAutoResizeOff"),m.isHidden()||(w.hide(),f&&m.theme.resizeTo(null,f))),f&&w.height(f)}var j,k,l,m,n,o=a(window),p=a(document),q=a("#wpadminbar"),r=a("#wpfooter"),s=a("#postdivrich"),t=a("#wp-content-wrap"),u=a("#wp-content-editor-tools"),v=a("#ed_toolbar"),w=a("#content"),x=a('<div id="content-textarea-clone"></div>'),y=a("#post-status-info"),z=a("#side-sortables"),A=a("#postbox-container-1"),B=a("#post-body"),C=window.wp.editor&&window.wp.editor.fullscreen,D=function(){},E=function(){},F=!1,G=!1,H=!1,I=!1,J=0,K=130,L=56,M=300;x.insertAfter(w),x.css({"font-family":w.css("font-family"),"font-size":w.css("font-size"),"line-height":w.css("line-height"),"white-space":"pre-wrap","word-wrap":"break-word"}),p.on("tinymce-editor-init.editor-expand",function(a,b){function e(){var a,c,d=b.selection.getNode();return c=b.plugins.wpview&&(a=b.plugins.wpview.getView(d))?a.getBoundingClientRect():d.getBoundingClientRect(),c.height?c:!1}function g(a){var c,d,f,g,h=tinymce.util.VK,i=a.keyCode,k=e(),l=o.height(),m=10;k&&(c=k.top+b.getContentAreaContainer().firstChild.getBoundingClientRect().top,d=c+k.height,c-=m,d+=m,f=q.outerHeight()+u.outerHeight()+j.outerHeight(),g=l-y.outerHeight(),g-f<k.height||(f>c&&(i===h.UP||i===h.LEFT||i===h.BACKSPACE)?window.scrollTo(window.pageXOffset,c+window.pageYOffset-f):d>g&&window.scrollTo(window.pageXOffset,d+window.pageYOffset-g)))}function h(){setTimeout(function(){b.execCommand("wpAutoResize"),d()},300)}function i(){c(),d()}"content"===b.id&&(m=b,b.settings.autoresize_min_height=M,j=t.find(".mce-toolbar-grp"),k=t.find(".mce-edit-area"),l=t.find(".mce-statusbar").filter(":visible"),D=function(){b.on("keyup",g),b.on("show",h),b.on("hide",i),b.on("setcontent wp-autoresize wp-toolbar-toggle",d)},E=function(){b.off("keyup",g),b.off("show",h),b.off("hide",i),b.off("setcontent wp-autoresize wp-toolbar-toggle",d)},s.hasClass("wp-editor-expand")&&(D(),f(d)))}),s.hasClass("wp-editor-expand")&&(h(),t.hasClass("html-active")&&f(function(){d(),c()})),a("#adv-settings .editor-expand").show(),a("#editor-expand-toggle").on("change.editor-expand",function(){a(this).prop("checked")?(h(),window.setUserSetting("editor_expand","on")):(i(),window.setUserSetting("editor_expand","off"))}),window.editorExpand={on:h,off:i}});