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.

заранее спасибо


person MadScientist    schedule 09.02.2012    source источник


Ответы (1)


Ошибка здесь у вас есть

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);
person firegnom    schedule 09.02.2012
comment
Я добавил это обратно, но всплывающее окно с ошибкой все еще дает мне то же сообщение. - person MadScientist; 09.02.2012