Cleditor - minor plugin error

女生的网名这么多〃 提交于 2019-12-06 11:37:53

问题


I am not a Javascript specialist so I am a little confused as to why this little button plugin does what it is supposed to in Cleditor but a error warning is popped up by the jquery editor.

Here is the code:

(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);

It is a simple plugin that inserts [VIDEO] into the document when you click the button.

The problem is that for some reason after it inserts the text this comes up

"Error Executing the inserthtml command" In a little yellow window under the plugin button.

I am sure it is something small that I am missing due to lack of experience with Javascript.

Thanks in advance


回答1:


Error is here you have

editor.execCommand(data.command, html);

and it should be:

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

EDIT:

verry annoying, at the end of your function just add:

return false;

here is jsfiddle for that

and final code

(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);


来源:https://stackoverflow.com/questions/9215426/cleditor-minor-plugin-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!