2012-02-09 2 views
2

저는 자바 전문가가 아니기 때문에이 작은 버튼 플러그인이 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); 

그것은 당신이 버튼을 클릭하면 문서에 [VIDEO]를 삽입하는 간단한 플러그인은 다음과 같습니다 여기

는 코드입니다.

문제는 몇 가지 이유로이가

오는 텍스트를 삽입 한 후 것입니다 "오류 발생 insertHTML를 명령 실행"플러그인 버튼 아래에 작은 노란색 창에서합니다.

Javascript에 대한 경험 부족으로 인해 내가 누락 된 내용 인 것으로 확신합니다.

답변

3

오류가 여기에 사전에

덕분에 당신은

editor.execCommand(data.command, html); 

을 가지고 있고 그것은해야한다 :

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

편집 : 성가신

의 verry, 함수의 끝에서 다음을 추가하십시오 :

(210)
return false; 

는 여기에 내가 다시이 아니라 오류 팝업은 여전히 ​​나에게 동일한 메시지를주고 있다고 덧붙였다 그

최종 코드

(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

에 대한 jsfiddle입니다. – MadScientist