From e50ffd401ef5aee61974cc400b6608a8b5a360e4 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 1 Aug 2014 21:43:18 +0000 Subject: [PATCH] Editor scrolling: run one more adjust() 200ms after scroll or resize in case the browser is slow to re-calculate the element heights and pin/unpin the toolbars. See #28328, fixes #29059. Built from https://develop.svn.wordpress.org/trunk@29352 git-svn-id: http://core.svn.wordpress.org/trunk@29128 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/editor-expand.js | 9 ++++++++- wp-admin/js/editor-expand.min.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-admin/js/editor-expand.js b/wp-admin/js/editor-expand.js index 9129366e99..62c050675f 100644 --- a/wp-admin/js/editor-expand.js +++ b/wp-admin/js/editor-expand.js @@ -21,7 +21,8 @@ jQuery( document ).ready( function($) { mceBind = function(){}, mceUnbind = function(){}, fixedTop = false, - fixedBottom = false; + fixedBottom = false, + scrollTimer; $textEditorClone.insertAfter( $textEditor ); @@ -345,6 +346,11 @@ jQuery( document ).ready( function($) { } } + function afterScroll() { + clearTimeout( scrollTimer ); + scrollTimer = setTimeout( adjust, 200 ); + } + function on() { // Scroll to the top when triggering this from JS. // Ensures toolbars are pinned properly. @@ -357,6 +363,7 @@ jQuery( document ).ready( function($) { // Adjust when the window is scrolled or resized. $window.on( 'scroll.editor-expand resize.editor-expand', function( event ) { adjust( event.type ); + afterScroll(); } ); // Adjust when collapsing the menu, changing the columns, changing the body class. diff --git a/wp-admin/js/editor-expand.min.js b/wp-admin/js/editor-expand.min.js index fea5ce5136..7c34754acf 100644 --- a/wp-admin/js/editor-expand.min.js +++ b/wp-admin/js/editor-expand.min.js @@ -1 +1 @@ -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()+" "),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('
'),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-fc&&(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}}); \ No newline at end of file +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=v[0].selectionStart,k=v[0].selectionEnd,l=w[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()+t.outerHeight()+u.outerHeight(),f=m-x.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=v.height();w.width(v.width()),w.text(v.val()+" "),a=w.height(),300>a&&(a=300),a!==b&&(v.height(a),d())}}function d(a){if(!y||!y.settings.visible){var b,c,d,e,f,g,h,i,n,p=x.outerHeight(),r=o.scrollTop(),z=o.height(),A=o.width(),D=A>600?q.height():0,E="scroll"!==a,F=m&&!m.isHidden(),G=200;F?(b=j,c=k):(b=u,c=v),d=t.outerHeight(),e=b.parent().offset().top,f=b.outerHeight(),g=c.offset().top,h=c.outerHeight(),i=c.outerWidth(),n=F?l.outerHeight():0,(!B||E)&&r>=e-d-D&&e-d-D+h-G>=r?(B=!0,b.css({position:"fixed",top:D+d,width:c.parent().width()-(b.outerWidth()-b.width()),borderTop:"1px solid #e5e5e5"}),t.css({position:"fixed",top:D,width:i+2})):(B||E)&&(e-d-D>=r?(B=!1,b.css({position:"absolute",top:0,borderTop:"none",width:c.parent().width()-(b.outerWidth()-b.width())}),t.css({position:"absolute",top:0,width:s.width()})):r>=e-d-D+h-G&&(B=!1,b.css({position:"absolute",top:h-G}),t.css({position:"absolute",top:h-G+1,width:s.width()}))),(!C||E)&&g+h+p+n+1>=r+z?(C=!0,x.css({position:"fixed",bottom:0,width:i+2,borderTop:"1px solid #dedede"})):(C||E)&&r+z>g+h+p+n-1&&(C=!1,x.css({position:"relative",bottom:"auto",width:"100%",borderTop:"none"})),E&&(s.css({paddingTop:t.outerHeight()}),F?k.css({paddingTop:j.outerHeight()}):(v.css({marginTop:u.outerHeight()}),w.width(v.width())))}}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>130&&window.scrollTo(window.pageXOffset,0),r.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),v.on("focus.editor-expand input.editor-expand propertychange.editor-expand",c),v.on("keyup.editor-expand",b),z(),y&&y.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>130&&window.scrollTo(window.pageXOffset,0),r.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),v.off("focus.editor-expand input.editor-expand propertychange.editor-expand",c),v.off("keyup.editor-expand",b),A(),y&&y.pubsub.unsubscribe("hidden",e),a.each([j,u,t,x,s,k,v],function(a,b){b&&b.attr("style","")}),m&&(m.settings.wp_autoresize_on=!1,m.execCommand("wpAutoResizeOff"),m.isHidden()||(v.hide(),f&&m.theme.resizeTo(null,f))),f&&v.height(f)}var j,k,l,m,n,o=a(window),p=a(document),q=a("#wpadminbar"),r=a("#postdivrich"),s=a("#wp-content-wrap"),t=a("#wp-content-editor-tools"),u=a("#ed_toolbar"),v=a("#content"),w=a('
'),x=a("#post-status-info"),y=window.wp.editor&&window.wp.editor.fullscreen,z=function(){},A=function(){},B=!1,C=!1;w.insertAfter(v),w.css({"font-family":v.css("font-family"),"font-size":v.css("font-size"),"line-height":v.css("line-height"),padding:v.css("padding"),"padding-top":37,"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()+t.outerHeight()+j.outerHeight(),g=l-x.outerHeight(),g-fc&&(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=300,j=s.find(".mce-toolbar-grp"),k=s.find(".mce-edit-area"),l=s.find(".mce-statusbar").filter(":visible"),z=function(){b.on("keyup",g),b.on("show",h),b.on("hide",i),b.on("setcontent wp-autoresize wp-toolbar-toggle",d)},A=function(){b.off("keyup",g),b.off("show",h),b.off("hide",i),b.off("setcontent wp-autoresize wp-toolbar-toggle",d)},r.hasClass("wp-editor-expand")&&(z(),f(d)))}),r.hasClass("wp-editor-expand")&&(h(),s.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}}); \ No newline at end of file