javascriptjquerycleditor

Cleditor - minor plugin error


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


Solution

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