zoukankan      html  css  js  c++  java
  • 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的问题。

      欢迎拍砖!!!

     

  • 相关阅读:
    在SpringBoot或者Spring项目中实现最原始的分页功能
    element ui 弹出组件的遮罩层在弹出层的上面的解决方法
    vue中ref的使用(this.$refs获取为undefined)
    echarts的图表根据父容器大小的改变而改变(弹窗easy-ui的window窗口)
    vue项目使用history模式打包应该注意的地方
    echarts数据变了不重新渲染,以及重新渲染了前后数据会重叠渲染的问题
    element-ui的layout将24等分换为48等分
    vue中解决拖动和点击事件的冲突
    制作首页的显示列表。
    发布功能完成。
  • 原文地址:https://www.cnblogs.com/zhangchaozheng/p/2607840.html
Copyright © 2011-2022 走看看