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
This commit is contained in:
Andrew Ozz 2012-09-24 03:08:31 +00:00
parent f4478ab647
commit 6da86aa93f

View File

@ -6,6 +6,7 @@
(function() { (function() {
tinymce.create('tinymce.plugins.wpFullscreenPlugin', { tinymce.create('tinymce.plugins.wpFullscreenPlugin', {
resize_timeout: false,
init : function(ed, url) { init : function(ed, url) {
var t = this, oldHeight = 0, s = {}, DOM = tinymce.DOM; var t = this, oldHeight = 0, s = {}, DOM = tinymce.DOM;
@ -119,23 +120,30 @@
/** /**
* This method gets executed each time the editor needs to resize. * This method gets executed each time the editor needs to resize.
*/ */
function resize() { function resize(editor, e) {
var d = ed.getDoc(), DOM = tinymce.DOM, resizeHeight, myHeight; 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 ( t.resize_timeout )
if ( tinymce.isWebKit ) return;
myHeight = d.body.offsetHeight;
else
myHeight = d.body.scrollHeight;
// Don't make it smaller than 300px // sometimes several events are fired few ms apart, trottle down resizing a little
resizeHeight = (myHeight > 300) ? myHeight : 300; t.resize_timeout = true;
setTimeout(function(){
t.resize_timeout = false;
}, 500);
// Resize content element height = body.scrollHeight > 300 ? body.scrollHeight : 300;
if ( oldHeight != resizeHeight ) {
DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px'); if ( height != ifr.scrollHeight ) {
oldHeight = resizeHeight; DOM.setStyle(ifr, 'height', height + 'px');
ed.getWin().scrollTo(0,0); 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"; 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) { ed.onLoadContent.add(function(ed, l) {
// Because the content area resizes when its content CSS loads, // Because the content area resizes when its content CSS loads,
// and we can't easily add a listener to its onload event, // and we can't easily add a listener to its onload event,