Fckeditor编辑区域高度固定
fckeditor提供了编辑器高度的设置,但是只对整个编辑器,包括工具条。另外它也提供了一个插件autogrow,处理编辑器高度的自适应。
但目前这边有个需求,需要只固定可编辑区域高度。上面所述无法满足,尝试修改源码增加这个配置。
修改办法如下:
1.修改fckconfig.js,在文件最后增加:
FCKConfig.AutoHeight = true; //也可以默认为false
2.修改fcktoolbarset.js,增加如下红色代码:
function FCKToolbarSet_Create( overhideLocation ) { var oToolbarSet ; var initHeight; var sLocation = overhideLocation || FCKConfig.ToolbarLocation ; ……………………………………………………………………………………. var FCKToolbarSet = function( targetDocument ) { this._Document = targetDocument ; initHeight = parseInt(parent.document.getElementById(FCK.Name+ '___Frame').style.height, 10); // Get the element that will hold the elements structure. this._TargetElement = targetDocument.getElementById( 'xToolbar' ) ; // Setup the expand and collapse handlers. var eExpandHandle = targetDocument.getElementById( 'xExpandHandle' ) ; var eCollapseHandle = targetDocument.getElementById( 'xCollapseHandle' ) ; …………………………………………………… FCKToolbarSet.prototype._ChangeVisibility = function( collapse ) { this._Document.getElementById( 'xCollapsed' ).style.display = collapse ? '' : 'none' ; this._Document.getElementById( 'xExpanded' ).style.display = collapse ? 'none' : '' ; var toolbarHeight = this._Document.getElementById( 'xToolbar' ).scrollHeight; if(FCKConfig.AutoHeight) { if (collapse) { if ( !FCKConfig.ToolbarCanCollapse || FCKConfig.ToolbarStartExpanded ) { parent.document.getElementById(FCK.Name+'___Frame').style.height=initHeight - toolbarHeight+10 +'px'; }else { parent.document.getElementById(FCK.Name+'___Frame').style.height=initHeight + 'px'; } } else { if ( !FCKConfig.ToolbarCanCollapse || FCKConfig.ToolbarStartExpanded ) { parent.document.getElementById(FCK.Name+'___Frame').style.height=initHeight+"px"; }else { parent.document.getElementById(FCK.Name+'___Frame').style.height=initHeight + toolbarHeight -10+ 'px'; } } } if ( window.onresize ) { // I had to use "setTimeout" because Gecko was not responding in a right // way when calling window.onresize() directly. FCKTools.RunFunction( window.onresize ) ; } } …………………………………………………
3.压缩fcktoolbarset.js并将修改移到fckeditorcode_XXXX.js中
默认固定编辑区域高度,如要取消这功能,只需要在配置中加入:editor.Config["AutoHeight"] = false;
至此,功德圆满。技术有限,欢迎拍砖!