Cleditor - 次要插件错误

时间:2012-02-09 17:09:52

标签: javascript jquery cleditor

我不是Javascript专家所以我有点困惑为什么这个小按钮插件在Cleditor中应该做的事情,但是jquery编辑器会弹出错误警告。

以下是代码:

(function($) {


  // Define the hello button
  $.cleditor.buttons.video = {
    name: "video",
    image: "video.gif",
    title: "Insert Video",
    command: "inserthtml",
    buttonClick: videoClick
  };


  // Add the button to the default controls before the bold button
  $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
    .replace("bold", "video bold");


  // Handle the hello button click event
  function videoClick(e, data) {

        // Get the editor
        var editor = data.editor;

        // Insert some html into the document
        var html = "[VIDEO]";
        editor.execCommand(data.command, html, null, data.button);


        // Hide the popup and set focus back to the editor
       // editor.focus();
  }


})(jQuery);

这是一个简单的插件,当您单击按钮时,会将[视频]插入到文档中。

问题在于,在插入文本后出于某种原因,这就出现了

“执行inserthtml命令时出错”在插件按钮下的黄色小窗口中。

我确信由于缺乏Javascript经验,我缺少一些小东西。

提前致谢

1 个答案:

答案 0 :(得分:3)

错误就在这里

editor.execCommand(data.command, html);

应该是:

editor.execCommand(data.command, html, null, data.button);

编辑:

非常烦人,在你的功能结束时只需添加:

return false;

这是jsfiddle

和最终代码

(function($) {


  // Define the hello button
  $.cleditor.buttons.video = {
    name: "video",
    image: "video.gif",
    title: "Insert Video",
    command: "inserthtml",
    buttonClick: videoClick
  };


  // Add the button to the default controls before the bold button
  $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
    .replace("bold", "video bold");


  // Handle the hello button click event
  function videoClick(e, data) {

        // Get the editor
        var editor = data.editor;

        // Insert some html into the document
        var html = "[VIDEO]";
        editor.execCommand(data.command, html, null, data.button);


        // Hide the popup and set focus back to the editor
       // editor.focus();
       return false;
  }


})(jQuery);