2

私は 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);

ボタンをクリックするとドキュメントに[VIDEO]を挿入するシンプルなプラグインです。

問題は、テキストを挿入した後に何らかの理由でこれが表示されることです

「inserthtml コマンドの実行中にエラーが発生しました」 プラグイン ボタンの下の小さな黄色いウィンドウ。

Javascript の経験がないために見逃しているのは小さなことだと確信しています。

前もって感謝します

4

1 に答える 1

3

エラーはここにあります

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);
于 2012-02-09T17:44:35.127 に答える