Cleditor - небольшая ошибка плагина - PullRequest
2 голосов
/ 09 февраля 2012

Я не специалист по 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);

Это простой плагин, который вставляет [ВИДЕО] в документ при нажатии кнопки.

Проблема в том, что по какой-то причине после вставки текста появляется

«Ошибка выполнения команды insertthtml» В маленьком желтом окне под кнопкой плагина.

Я уверен, что это что-то маленькое, что мне не хватает из-за отсутствия опыта работы с Javascript.

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

1 Ответ

3 голосов
/ 09 февраля 2012

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

editor.execCommand(data.command, html);

и должно быть:

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

EDIT:

очень раздражает, в конце вашей функции просто добавьте:

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