From 84b3c0f478a90c513f93b4d6451e3a0de9f24737 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Tue, 19 Mar 2013 15:01:52 +0100 Subject: [PATCH 1/2] Fixed horrible code-style of autogrow resizeEditor(). --- plugins/autogrow/plugin.js | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/plugins/autogrow/plugin.js b/plugins/autogrow/plugin.js index 3ff8d277ee7..9dd2f15a7af 100644 --- a/plugins/autogrow/plugin.js +++ b/plugins/autogrow/plugin.js @@ -34,8 +34,8 @@ } var resizeEditor = function( editor ) { - if ( !editor.window ) - return; + if ( !editor.window ) + return; var maximize = editor.getCommand( 'maximize' ); // Disable autogrow when the editor is maximized .(#6339) @@ -43,30 +43,28 @@ return; var scrollable = getScrollable( editor ), - currentHeight = editor.window.getViewPaneSize().height, - newHeight = contentHeight( scrollable ); - - // Additional space specified by user. - newHeight += ( editor.config.autoGrow_bottomSpace || 0 ); + currentHeight = editor.window.getViewPaneSize().height, + newHeight = contentHeight( scrollable ); - var min = editor.config.autoGrow_minHeight != undefined ? editor.config.autoGrow_minHeight : 200, - max = editor.config.autoGrow_maxHeight || Infinity; + // Additional space specified by user. + newHeight += ( editor.config.autoGrow_bottomSpace || 0 ); - newHeight = Math.max( newHeight, min ); - newHeight = Math.min( newHeight, max ); + var min = editor.config.autoGrow_minHeight != undefined ? editor.config.autoGrow_minHeight : 200, + max = editor.config.autoGrow_maxHeight || Infinity; - if ( newHeight != currentHeight ) { - newHeight = editor.fire( 'autoGrow', { currentHeight: currentHeight, newHeight: newHeight } ).newHeight; - editor.resize( editor.container.getStyle( 'width' ), newHeight, true ); - } - - if ( scrollable.$.scrollHeight > scrollable.$.clientHeight && newHeight < max ) - scrollable.setStyle( 'overflow-y', 'hidden' ); - else - scrollable.removeStyle( 'overflow-y' ); + newHeight = Math.max( newHeight, min ); + newHeight = Math.min( newHeight, max ); + if ( newHeight != currentHeight ) { + newHeight = editor.fire( 'autoGrow', { currentHeight: currentHeight, newHeight: newHeight } ).newHeight; + editor.resize( editor.container.getStyle( 'width' ), newHeight, true ); + } - }; + if ( scrollable.$.scrollHeight > scrollable.$.clientHeight && newHeight < max ) + scrollable.setStyle( 'overflow-y', 'hidden' ); + else + scrollable.removeStyle( 'overflow-y' ); + }; CKEDITOR.plugins.add( 'autogrow', { init: function( editor ) { From ea1405504b5047256a6bf3979d630fa6eba8cdb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Reinmar=20Koszuli=C5=84ski?= Date: Wed, 20 Mar 2013 10:34:19 +0100 Subject: [PATCH 2/2] Do not resize editor when height hasn't been changed. --- plugins/autogrow/plugin.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/plugins/autogrow/plugin.js b/plugins/autogrow/plugin.js index 9dd2f15a7af..708da72a37f 100644 --- a/plugins/autogrow/plugin.js +++ b/plugins/autogrow/plugin.js @@ -33,7 +33,10 @@ return doc.$.compatMode == 'BackCompat' ? body : htmlElement; } - var resizeEditor = function( editor ) { + // @param editor + // @param {Number} lastHeight The last height set by autogrow. + // @returns {Number} New height if has been changed, or the passed `lastHeight`. + var resizeEditor = function( editor, lastHeight ) { if ( !editor.window ) return; @@ -55,15 +58,20 @@ newHeight = Math.max( newHeight, min ); newHeight = Math.min( newHeight, max ); - if ( newHeight != currentHeight ) { + // #10196 Do not resize editor if new height is equal + // to the one set by previous resizeEditor() call. + if ( newHeight != currentHeight && lastHeight != newHeight ) { newHeight = editor.fire( 'autoGrow', { currentHeight: currentHeight, newHeight: newHeight } ).newHeight; editor.resize( editor.container.getStyle( 'width' ), newHeight, true ); + lastHeight = newHeight; } if ( scrollable.$.scrollHeight > scrollable.$.clientHeight && newHeight < max ) scrollable.setStyle( 'overflow-y', 'hidden' ); else scrollable.removeStyle( 'overflow-y' ); + + return lastHeight; }; CKEDITOR.plugins.add( 'autogrow', { @@ -75,7 +83,8 @@ editor.on( 'instanceReady', function() { - var editable = editor.editable(); + var editable = editor.editable(), + lastHeight; // Simply set auto height with div wysiwyg. if ( editable.isInline() ) @@ -84,7 +93,9 @@ else { editor.addCommand( 'autogrow', { - exec:resizeEditor, + exec: function( editor ) { + lastHeight = resizeEditor( editor, lastHeight ); + }, modes:{ wysiwyg:1 }, readOnly: 1, canUndo: false, @@ -97,10 +108,10 @@ // Some time is required for insertHtml, and it gives other events better performance as well. if ( evt.editor.mode == 'wysiwyg' ) { setTimeout( function() { - resizeEditor( evt.editor ); + lastHeight = resizeEditor( evt.editor, lastHeight ); // Second pass to make correction upon // the first resize, e.g. scrollbar. - resizeEditor( evt.editor ); + lastHeight = resizeEditor( evt.editor, lastHeight ); }, 100 ); } }); @@ -114,7 +125,7 @@ scrollable.removeStyle( 'overflow' ); } else - resizeEditor( editor ); + lastHeight = resizeEditor( editor, lastHeight ); } });