From 6da86aa93f699d9bf51e825bb5b8dce3e2a22cd5 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 24 Sep 2012 03:08:31 +0000 Subject: [PATCH] DFW: add scroll locking to prevent scrolling to top in WebKit on paste, add auto-resize throttling to 0.5 sec, only compare scrollHeight values (works well in all supported browsers), fixes #21979 git-svn-id: http://core.svn.wordpress.org/trunk@21963 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../plugins/wpfullscreen/editor_plugin_src.js | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js b/wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js index 6cf84fdf59..c1a30759b5 100644 --- a/wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js +++ b/wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js @@ -6,6 +6,7 @@ (function() { tinymce.create('tinymce.plugins.wpFullscreenPlugin', { + resize_timeout: false, init : function(ed, url) { var t = this, oldHeight = 0, s = {}, DOM = tinymce.DOM; @@ -119,23 +120,30 @@ /** * This method gets executed each time the editor needs to resize. */ - function resize() { - var d = ed.getDoc(), DOM = tinymce.DOM, resizeHeight, myHeight; + function resize(editor, e) { + var DOM = tinymce.DOM, body = ed.getBody(), ifr = DOM.get(ed.id + '_ifr'), height, y = ed.dom.win.scrollY; - // Get height differently depending on the browser used - if ( tinymce.isWebKit ) - myHeight = d.body.offsetHeight; - else - myHeight = d.body.scrollHeight; + if ( t.resize_timeout ) + return; - // Don't make it smaller than 300px - resizeHeight = (myHeight > 300) ? myHeight : 300; + // sometimes several events are fired few ms apart, trottle down resizing a little + t.resize_timeout = true; + setTimeout(function(){ + t.resize_timeout = false; + }, 500); - // Resize content element - if ( oldHeight != resizeHeight ) { - DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px'); - oldHeight = resizeHeight; - ed.getWin().scrollTo(0,0); + height = body.scrollHeight > 300 ? body.scrollHeight : 300; + + if ( height != ifr.scrollHeight ) { + DOM.setStyle(ifr, 'height', height + 'px'); + ed.getWin().scrollTo(0, 0); // iframe window object, make sure there's no scrolling + } + + // WebKit scrolls to top on paste... + if ( e && e.type == 'paste' && tinymce.isWebKit ) { + setTimeout(function(){ + ed.dom.win.scrollTo(0, y); + }, 40); } }; @@ -150,7 +158,7 @@ ed.getBody().style.overflowY = "hidden"; }); - if (ed.getParam('autoresize_on_init', true)) { + if ( ed.getParam('autoresize_on_init', true) ) { ed.onLoadContent.add(function(ed, l) { // Because the content area resizes when its content CSS loads, // and we can't easily add a listener to its onload event,