Domanda

how can I call a tinymce plugin function?

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

not working!

È stato utile?

Soluzione

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

Altri suggerimenti

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();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top