2012-08-10 97 views

回答

2

tinymce.activeEditor.plugins.customplugin.customfunction(customvar);

是調用此功能的正確方法。 請注意,tinymce.activeEditor需要設置才能使用它。例如,當用戶點擊編輯器時, tinymce.activeEditor被設置。 否則使用

tinymce.get('your_editor_id_here').plugins.customplugin.customfunction(customvar); 

有可能是另一個原因您的函數調用不工作: 要調用需要的功能一樣的功能getInfo,在保存插件_save_nodeChange(請參閱開發人員定義構建tinymce來檢查插件目錄中的插件)。

在這裏保存插件縮短:

(function() { 
    tinymce.create('tinymce.plugins.Save', { 
     init : function(ed, url) { 
      ... 
     }, 

     getInfo : function() { 
        ... 
     }, 

     // Private methods 

     _nodeChange : function(ed, cm, n) { 
        ... 
     }, 

     // Private methods 
        ... 
     _save : function() { 

     } 
    }); 

    // Register plugin 
    tinymce.PluginManager.add('save', tinymce.plugins.Save); 
})(); 

您可以使用下面的JavaScript調用調用該插件的getInfo功能:

tinymce.get('your_editor_id_here').plugins.save.getInfo(); 
+0

參考:https://github.com/tinymce/tinymce/blob/master/js/tinymce/plugins/save/plugin.js – Fred 2015-04-29 09:01:52

+0

此鏈接現在不是最新版本,因爲插件的更新版本現在在plugin.add()方法的參數中使用了一個匿名函數 – 2016-04-19 15:09:33

1

將要暴露給外界的功能在self

tinymce.PluginManager.add('myplugin', function(editor) { 
    var self = this; 
    var self.myFunction = myFunction(); // Put function into self! 

    function myFunction() { 
     console.log('Hello world!'); 
    } 
} 

然後:

tinymce.get('your_editor_id_here').plugins.myplugin.myFunction();