Skip to content

Commit

Permalink
Merge branch 't/10196b'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Mar 20, 2013
2 parents 2c54f8d + ea14055 commit 18a9148
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions plugins/autogrow/plugin.js
Expand Up @@ -33,40 +33,46 @@
return doc.$.compatMode == 'BackCompat' ? body : htmlElement;
}

var resizeEditor = function( editor ) {
if ( !editor.window )
return;
// @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;

var maximize = editor.getCommand( 'maximize' );
// Disable autogrow when the editor is maximized .(#6339)
if( maximize && maximize.state == CKEDITOR.TRISTATE_ON )
return;

var scrollable = getScrollable( editor ),
currentHeight = editor.window.getViewPaneSize().height,
newHeight = contentHeight( scrollable );
currentHeight = editor.window.getViewPaneSize().height,
newHeight = contentHeight( scrollable );

// Additional space specified by user.
newHeight += ( editor.config.autoGrow_bottomSpace || 0 );
// Additional space specified by user.
newHeight += ( editor.config.autoGrow_bottomSpace || 0 );

var min = editor.config.autoGrow_minHeight != undefined ? editor.config.autoGrow_minHeight : 200,
max = editor.config.autoGrow_maxHeight || Infinity;
var min = editor.config.autoGrow_minHeight != undefined ? editor.config.autoGrow_minHeight : 200,
max = editor.config.autoGrow_maxHeight || Infinity;

newHeight = Math.max( newHeight, min );
newHeight = Math.min( newHeight, max );
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' );
// #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', {
init: function( editor ) {
Expand All @@ -77,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() )
Expand All @@ -86,7 +93,9 @@
else
{
editor.addCommand( 'autogrow', {
exec:resizeEditor,
exec: function( editor ) {
lastHeight = resizeEditor( editor, lastHeight );
},
modes:{ wysiwyg:1 },
readOnly: 1,
canUndo: false,
Expand All @@ -99,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 );
}
});
Expand All @@ -116,7 +125,7 @@
scrollable.removeStyle( 'overflow' );
}
else
resizeEditor( editor );
lastHeight = resizeEditor( editor, lastHeight );
}
});

Expand Down

0 comments on commit 18a9148

Please sign in to comment.