WordPress/wp-admin/js/editor-expand.min.js
Andrew Ozz b9886e92e3 Editor scrolling:
- Add a Screen Option to turn it on/off, and on()/off() methods from JS. Store the user preference.
- Fix delayed calls to resize() in the TinyMCE autoresize plugin.
See #28328.
Built from https://develop.svn.wordpress.org/trunk@29336


git-svn-id: http://core.svn.wordpress.org/trunk@29116 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-08-01 02:43:17 +00:00

1 line
5.2 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=t[0].selectionStart,k=t[0].selectionEnd,l=u[0].firstChild,n=m.height(),p=10;if(!j||!k||j===k){try{i.setStart(l,j),i.setEnd(l,k+1)}catch(q){}b=i.getBoundingClientRect(),b.height&&(c=b.top-p,d=c+b.height+p,e=o.outerHeight()+r.outerHeight()+s.outerHeight(),f=n-v.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(!l||l.isHidden()){var a,b=t.height();u.width(t.width()),u.text(t.val()+"&nbsp;"),a=u.height(),300>a&&(a=300),a!==b&&(t.height(a),d())}}function d(a){if(!w||!w.settings.visible){var b,c,d,e,f,g,h,n,p,x=v.outerHeight(),y=m.scrollTop(),B=m.height(),C=m.width(),D=C>600?o.height():0,E="scroll"!==a,F=l&&!l.isHidden(),G=200;F?(b=i,c=j):(b=s,c=t),d=r.outerHeight(),e=b.parent().offset().top,f=b.outerHeight(),g=c.offset().top,h=c.outerHeight(),n=c.outerWidth(),p=F?k.outerHeight():0,(!z||E)&&y>=e-d-D&&e-d-D+h-G>=y?(z=!0,b.css({position:"fixed",top:D+d,width:c.parent().width()-(b.outerWidth()-b.width()),borderTop:"1px solid #e5e5e5"}),r.css({position:"fixed",top:D,width:n+2})):(z||E)&&(e-d-D>=y?(z=!1,b.css({position:"absolute",top:0,borderTop:"none",width:c.parent().width()-(b.outerWidth()-b.width())}),r.css({position:"absolute",top:0,width:q.width()})):y>=e-d-D+h-G&&(z=!1,b.css({position:"absolute",top:h-G}),r.css({position:"absolute",top:h-G+1,width:q.width()}))),(!A||E)&&g+h+x+p+1>=y+B?(A=!0,v.css({position:"fixed",bottom:0,width:n+2,borderTop:"1px solid #dedede"})):(A||E)&&y+B>g+h+x+p-1&&(A=!1,v.css({position:"relative",bottom:"auto",width:"100%",borderTop:"none"})),E&&(q.css({paddingTop:r.outerHeight()}),F?j.css({paddingTop:i.outerHeight()}):(t.css({marginTop:s.outerHeight()}),u.width(t.width())))}}function e(){c(),d()}function f(a){for(var b=1;6>b;b++)setTimeout(a,500*b)}function g(){window.pageYOffset&&window.pageYOffset>130&&window.scrollTo(window.pageXOffset,0),p.addClass("wp-editor-expand"),m.on("scroll.editor-expand resize.editor-expand",function(a){d(a.type)}),n.on("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",d),t.on("focus.editor-expand input.editor-expand propertychange.editor-expand",c),t.on("keyup.editor-expand",b),x(),w&&w.pubsub.subscribe("hidden",e),l&&(l.settings.wp_autoresize_on=!0,l.execCommand("wpAutoResizeOn"),l.isHidden()||l.execCommand("wpAutoResize")),(!l||l.isHidden())&&c(),d()}function h(){var f=window.getUserSetting("ed_size");window.pageYOffset&&window.pageYOffset>130&&window.scrollTo(window.pageXOffset,0),p.removeClass("wp-editor-expand"),m.off("scroll.editor-expand resize.editor-expand"),n.off("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",d),t.off("focus.editor-expand input.editor-expand propertychange.editor-expand",c),t.off("keyup.editor-expand",b),y(),w&&w.pubsub.unsubscribe("hidden",e),a.each([i,s,r,v,q,j,t],function(a,b){b&&b.attr("style","")}),l&&(l.settings.wp_autoresize_on=!1,l.execCommand("wpAutoResizeOff"),l.isHidden()||(t.hide(),f&&l.theme.resizeTo(null,f))),f&&t.height(f)}var i,j,k,l,m=a(window),n=a(document),o=a("#wpadminbar"),p=a("#postdivrich"),q=a("#wp-content-wrap"),r=a("#wp-content-editor-tools"),s=a("#ed_toolbar"),t=a("#content"),u=a('<div id="content-textarea-clone"></div>'),v=a("#post-status-info"),w=window.wp.editor&&window.wp.editor.fullscreen,x=function(){},y=function(){},z=!1,A=!1;u.insertAfter(t),u.css({"font-family":t.css("font-family"),"font-size":t.css("font-size"),"line-height":t.css("line-height"),padding:t.css("padding"),"padding-top":37,"white-space":"pre-wrap","word-wrap":"break-word"}),n.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,j=a.keyCode,k=e(),l=m.height(),n=10;k&&(c=k.top+b.getContentAreaContainer().firstChild.getBoundingClientRect().top,d=c+k.height,c-=n,d+=n,f=o.outerHeight()+r.outerHeight()+i.outerHeight(),g=l-v.outerHeight(),g-f<k.height||(f>c&&(j===h.UP||j===h.LEFT||j===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 n(){c(),d()}"content"===b.id&&(l=b,b.settings.autoresize_min_height=300,i=q.find(".mce-toolbar-grp"),j=q.find(".mce-edit-area"),k=q.find(".mce-statusbar").filter(":visible"),x=function(){b.on("keyup",g),b.on("show",h),b.on("hide",n),b.on("setcontent wp-autoresize wp-toolbar-toggle",d)},y=function(){b.off("keyup",g),b.off("show",h),b.off("hide",n),b.off("setcontent wp-autoresize wp-toolbar-toggle",d)},p.hasClass("wp-editor-expand")&&(x(),f(d)))}),p.hasClass("wp-editor-expand")&&(g(),q.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")?(g(),window.setUserSetting("editor_expand","on")):(h(),window.setUserSetting("editor_expand","off"))}),window.editorExpand={on:g,off:h}});