【问题标题】:ckeditor inline saveckeditor 内联保存
【发布时间】:2013-03-10 11:39:01
【问题描述】:

建立一个论坛并使用 Ckeditor 发布消息 - 在表单中使用 textarea 可以正常工作。现在我希望用户能够编辑他们的帖子,所以我有 ckeditor 内联工作,所以用户点击他们的帖子,他们的消息被 ckeditor 替换。到目前为止效果很好,看起来不错。但是保存按钮被禁用。我用一个表格包围了整个东西,但当然 ckeditor 现在是一个 div 而不是一个文本区域,所以我猜这个表格不起作用。那么如何将数据传递给我的 PHP 呢?

另一个问题是 Ckeditor 似乎无法在手机上运行。你能想出一个简单的手机回退方法吗?

这是我用来渲染内联编辑器的代码;

// Uncomment the following code to test the "Timeout Loading Method".
// CKEDITOR.loadFullCoreTimeout = 5;

window.onload = function() {
    // Listen to the double click event.
    if (window.addEventListener)
        document.body.addEventListener('click', onClick, false);
    else if (window.attachEvent)
        document.body.attachEvent('onclick', onClick);

};

function onClick(ev) {
    // Get the element which fired the event. This is not necessarily the
    // element to which the event has been attached.
    var element = ev.target || ev.srcElement;

    // Find out the div that holds this element.
    var name;

    do {
        element = element.parentNode;
    }
    while (element && (name = element.nodeName.toLowerCase()) &&
            (name != 'div' || element.className.indexOf('edit_post') == -1) && name != 'body');

    if (name == 'div' && element.className.indexOf('edit_post') != -1)
        replaceDiv(element);
}

var editor;

function replaceDiv(div) {
    if (editor)
        editor.destroy();

    editor = CKEDITOR.replace(div, {
        uiColor: '#FFFFFF',
        toolbar: [
            ['Save', 'Cut', 'Copy', 'Paste', 'PasteFromWord', '-', 'Undo', 'Redo', '-', 'Scayt'],
            '/',
            ['Bold', 'Italic', 'Underline', 'Blockquote', '-', 'Link', 'Unlink', '-', 'Image', 'Smiley', 'oembed']

        ]
    });

}

【问题讨论】:

    标签: save ckeditor inline


    【解决方案1】:

    您可以尝试覆盖默认的保存命令并使用您需要对那里的保存执行的任何操作。

    类似

    // Override the normal CKEditor save plugin
    CKEDITOR.plugins.registered['save'] =
    {
        init : function( editor )
        {
            editor.addCommand( 'save', 
                {
                    modes : { wysiwyg:1, source:1 },
                    exec : function( editor ) {
                        if(Editor.CheckDirty()) {
                            // Do wahtever you need to do during the save button here
                        } else {
                            alert("NothingToSave);
                        }
                    }
                }
            );
            editor.ui.addButton( 'Save', {label : '@GeneralTerms.Save', command : 'save'} );
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 2013-05-07
      相关资源
      最近更新 更多