fckeditor只读状态下回车仍可输入的BUG
我对Fckeditor设置为不可编辑状态,但仍可以通过ENTER或SHIFT+ENTER产生p或者br标签。如下是fckeditor设置为只读状态的代码。
<script type="text/javascript"> window.onload = function() { var sBasePath = document.location.href.substring(0,document.location.href.lastIndexOf('_samples')) ; var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ; oFCKeditor.Config["AutoHeight"] = false; oFCKeditor.Config['ToolBarLess'] = 'Basic'; oFCKeditor.Config["ToolbarStartExpanded"] = true; oFCKeditor.ToolbarSet = 'ComposeEmailReadOnly'; //oFCKeditor.ToolbarSet = 'Advance'; oFCKeditor.BasePath = sBasePath ; oFCKeditor.ReplaceTextarea() ; } function FCKeditor_OnComplete( editor ) { editor.EditorDocument.body.contentEditable = false; editor.EditMode=FCK_EDITMODE_SOURCE; editor.ToolbarSet.RefreshModeState(); editor.EditMode=FCK_EDITMODE_WYSIWYG; editor.ToolbarSet.RefreshModeState(); } </script>
查看FCK的配置,并没有发现有方法可以解决这一问题。于是只好硬着头皮修改下源码。
大概修改如下,修改fckenterkey.js文件。请看红色部分。
var FCKEnterKey = function( targetWindow, enterMode, shiftEnterMode, tabSpaces ) { this.Window = targetWindow ; this.EnterMode = enterMode || 'p' ; this.ShiftEnterMode = shiftEnterMode || 'br' ; ......... FCKEnterKey.prototype.DoEnter = function( mode, hasShift ) { // Save an undo snapshot before doing anything FCKUndo.SaveUndoStep() ; this._HasShift = ( hasShift === true ) ; var parentElement = FCKSelection.GetParentElement() ; var parentPath = new FCKElementPath( parentElement ) ; var sMode = mode || this.EnterMode ;
if (sMode == '') return;
if ( sMode == 'br' || parentPath.Block && parentPath.Block.tagName.toLowerCase() == 'pre' ) return this._ExecuteEnterBr() ; else return this._ExecuteEnterBlock( sMode ) ; } ...................
修改后,使用js压缩工具进行压缩并更改到fckeditorcode_XXX.js文件中即可。
然后使用时在只读状态的编辑吕配置中加入如下:
editor.Config["EnterMode"] = '';
editor.Config["ShiftEnterMode"] = '';
个人水平有限,这并不是个很好的办法,但可以解决到这个bug的问题。
欢迎拍砖!!!