2008-10-08 12:16:30 +02:00
|
|
|
|
/*
|
|
|
|
|
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
2009-07-07 10:58:12 +02:00
|
|
|
|
* Copyright (C) 2003-2009 Frederico Caldeira Knabben
|
2008-10-08 12:16:30 +02:00
|
|
|
|
*
|
|
|
|
|
* == BEGIN LICENSE ==
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the terms of any of the following licenses at your
|
|
|
|
|
* choice:
|
|
|
|
|
*
|
|
|
|
|
* - GNU General Public License Version 2 or later (the "GPL")
|
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
|
|
|
|
* http://www.gnu.org/licenses/lgpl.html
|
|
|
|
|
*
|
|
|
|
|
* - Mozilla Public License Version 1.1 or later (the "MPL")
|
|
|
|
|
* http://www.mozilla.org/MPL/MPL-1.1.html
|
|
|
|
|
*
|
|
|
|
|
* == END LICENSE ==
|
|
|
|
|
*
|
|
|
|
|
* Plugin: automatically resizes the editor until a configurable maximun
|
|
|
|
|
* height (FCKConfig.AutoGrowMax), based on its contents.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
var FCKAutoGrow = {
|
|
|
|
|
MIN_HEIGHT : window.frameElement.offsetHeight,
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
Check : function()
|
|
|
|
|
{
|
|
|
|
|
var delta = FCKAutoGrow.GetHeightDelta() ;
|
|
|
|
|
if ( delta != 0 )
|
|
|
|
|
{
|
|
|
|
|
var newHeight = window.frameElement.offsetHeight + delta ;
|
|
|
|
|
|
|
|
|
|
newHeight = FCKAutoGrow.GetEffectiveHeight( newHeight ) ;
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
if ( newHeight != window.frameElement.height )
|
|
|
|
|
{
|
|
|
|
|
window.frameElement.style.height = newHeight + "px" ;
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
// Gecko browsers use an onresize handler to update the innermost
|
|
|
|
|
// IFRAME's height. If the document is modified before the onresize
|
|
|
|
|
// is triggered, the plugin will miscalculate the new height. Thus,
|
|
|
|
|
// forcibly trigger onresize. #1336
|
|
|
|
|
if ( typeof window.onresize == 'function' )
|
|
|
|
|
{
|
|
|
|
|
window.onresize() ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
CheckEditorStatus : function( sender, status )
|
2008-10-08 12:16:30 +02:00
|
|
|
|
{
|
2009-07-07 10:58:12 +02:00
|
|
|
|
if ( status == FCK_STATUS_COMPLETE )
|
|
|
|
|
FCKAutoGrow.Check() ;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
GetEffectiveHeight : function( height )
|
2008-10-08 12:16:30 +02:00
|
|
|
|
{
|
2009-07-07 10:58:12 +02:00
|
|
|
|
if ( height < FCKAutoGrow.MIN_HEIGHT )
|
|
|
|
|
height = FCKAutoGrow.MIN_HEIGHT;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var max = FCKConfig.AutoGrowMax;
|
|
|
|
|
if ( max && max > 0 && height > max )
|
|
|
|
|
height = max;
|
|
|
|
|
}
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
return height;
|
|
|
|
|
},
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
GetHeightDelta : function()
|
2008-10-08 12:16:30 +02:00
|
|
|
|
{
|
2009-07-07 10:58:12 +02:00
|
|
|
|
var oInnerDoc = FCK.EditorDocument ;
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
var iFrameHeight ;
|
|
|
|
|
var iInnerHeight ;
|
|
|
|
|
|
|
|
|
|
if ( FCKBrowserInfo.IsIE )
|
2008-10-08 12:16:30 +02:00
|
|
|
|
{
|
2009-07-07 10:58:12 +02:00
|
|
|
|
iFrameHeight = FCK.EditorWindow.frameElement.offsetHeight ;
|
|
|
|
|
iInnerHeight = oInnerDoc.body.scrollHeight ;
|
2008-10-08 12:16:30 +02:00
|
|
|
|
}
|
2009-07-07 10:58:12 +02:00
|
|
|
|
else
|
2008-10-08 12:16:30 +02:00
|
|
|
|
{
|
2009-07-07 10:58:12 +02:00
|
|
|
|
iFrameHeight = FCK.EditorWindow.innerHeight ;
|
|
|
|
|
iInnerHeight = oInnerDoc.body.offsetHeight +
|
|
|
|
|
( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-top' ), 10 ) || 0 ) +
|
|
|
|
|
( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-bottom' ), 10 ) || 0 ) ;
|
2008-10-08 12:16:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
return iInnerHeight - iFrameHeight ;
|
|
|
|
|
},
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
SetListeners : function()
|
|
|
|
|
{
|
|
|
|
|
if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
|
|
|
|
return ;
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow.Check ) ;
|
|
|
|
|
FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow.Check ) ;
|
|
|
|
|
}
|
|
|
|
|
};
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
2009-07-07 10:58:12 +02:00
|
|
|
|
FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ;
|
2008-10-08 12:16:30 +02:00
|
|
|
|
|
|
|
|
|
if ( FCKBrowserInfo.IsIE )
|
2009-07-07 10:58:12 +02:00
|
|
|
|
FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow.SetListeners ) ;
|
|
|
|
|
|
|
|
|
|
FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow.CheckEditorStatus ) ;
|