2013-03-10 79 views
0

构建论坛并使用Ckeditor发送消息 - 在表单内使用textarea可以正常工作。现在我希望用户能够编辑他们的帖子,因此我让ckeditor以内联方式工作,以便用户点击他们的帖子,他们的消息被ckeditor取代。这工作到目前为止,看起来不错。但保存按钮被禁用。我用表单包围了整个事物,但当然ckeditor现在是div而不是文本区域,所以我猜表单不起作用。那么如何将数据传递给我的PHP呢?ckeditor内联保存

另一个问题是,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'] 

     ] 
    }); 

} 

回答

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'}); 
    } 
}