how call a TinyMCE plugin function?

一个人想着一个人 提交于 2019-12-12 08:05:58

问题


how can I call a tinymce plugin function?

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

not working!


回答1:


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

is the correct way to call such a function. Be aware that tinymce.activeEditor needs to be set already in order to use it. tinymce.activeEditor gets set when the user clicks into the editor for example. Otherwise use

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

There might be another reason for your function call not to work: The function you want to call needs to be defined like the functions getInfo, _save and _nodeChange in the save plugin (see the developer build of tinymce to inspect this plugin in the plugins directory).

The save plugin shortened here:

(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);
})();

You may call the getInfo function of this plugin using the following javascript call:

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



回答2:


Put the function you want to expose to the outside world in self.

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

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

Then:

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


来源:https://stackoverflow.com/questions/11897631/how-call-a-tinymce-plugin-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!