2016-12-13 20 views
1

自分自身のプラグインとダイアログをhtml要素で作成しようとしています。 html要素をクリックすると、エディタにテキストが追加されます。私はonOk機能をバイパスする方法を見つけることができません。"onOk"を使用せずにダイアログhtml要素からckeditor関数にアクセス

onOk機能の中にeditor.insertHtml(' some code ')を使用すると、テキストが追加されますが、私が外部で使用したい場合はUncaught TypeError: Cannot read property 'editor' of undefined(…)エラーが発生します。

エディタにアクセスする正しい方法は何ですか?

CKEDITOR.dialog.add('smiley2', function(editor) { 
    return { 
     title: 'Abbreviation Properties', 
     minWidth: 400, 
     minHeight: 200, 
     contents: [ 
      { 
       id: 'tab-basic', 
       label: 'Basic Settings', 
       elements: [ 
        { 
         type: 'html', 
         id: '2', 
         label: 'Explanation', 
         html: "<div onclick=\"editor.insertHtml(' some code ')\">add code</a></div></div>" 
        } 
       ] 
      } 
     ], 
     onShow : function() 
      {   
      document.getElementById(this.getButton('ok').domId).style.display='none'; // disapper ok btn 
      }, 
     onOk: function() { 

      editor.insertHtml(' abbr '); 
     } 
    }; 
}); 

答えて

-1

あなたがサンプルでdiv要素をクリックすると、editorはあなたのスコープではありません。エディタオブジェクトを取得し、このようなメソッドinsertHtmlを使用する必要があります。

CKEDITOR.instances.editor1.insertHtml('your text`) 

この例では、あなたのtextarea idがeditor1ある前提としています。

+0

ページには多くの編集者がいます。だから私はエディタのIDは何か分からない... – user186585

0
CKEDITOR.dialog.add('smiley2', function(editor) { 

    var onChoice = function(evt) { 
      var target; 
      target = new CKEDITOR.dom.element(evt); 
      editor.insertHtml("SMILEY YES!"); 
      CKEDITOR.dialog.getCurrent().hide(); 
    }; 
    var onClick = CKEDITOR.tools.addFunction(onChoice); 

    return { 
     title: 'Abbreviation Properties', 
     minWidth: 400, 
     minHeight: 200, 
     buttons: [CKEDITOR.dialog.cancelButton], 
     contents: [ 
      { 
       id: 'tab-basic', 
       label: 'Basic Settings', 
       elements: [ 
        { 
         type: 'html', 
         id: '2', 
         label: 'Explana22tion', 
         html: "<div onclick=\"CKEDITOR.tools.callFunction(" + onClick +", this); return false;\" >111111</a></div></div>" 
        } 
       ] 
      } 
     ] 

    }; 
}); 
関連する問題