2012-02-09 2 views
2

Я не специалист по Javascript, поэтому я немного смущен, почему этот плагин с маленькими кнопками делает то, что он должен использовать в Cleditor, но предупреждение об ошибке появляется в редакторе jquery.Cleditor - незначительная ошибка плагина

Вот код:

(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.

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

ответ

3

Ошибка находится здесь у вас есть

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); 
+0

я добавил, что еще в России, но всплывающая ошибка все еще дают мне такое же сообщение. – MadScientist