Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how call a TinyMCE plugin function?

how can I call a tinymce plugin function?

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

not working!

like image 597
m3hdi Avatar asked Aug 10 '12 08:08

m3hdi


People also ask

How do you add a custom plugin to TinyMCE?

Custom plugins can be added to a TinyMCE instance by either: Using external_plugins : Use the external_plugins option to specify the URL-based location of the entry point file for the plugin.

How do you init TinyMCE?

Initialize TinyMCE 5 on any element (or elements) on the web page by passing an object containing a selector value to tinymce. init() . The selector value can be any valid CSS selector. For example: To replace <textarea id="mytextarea"> with a TinyMCE 5 editor instance, pass the selector '#mytextarea' to tinymce.


2 Answers

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();
like image 122
Thariama Avatar answered Oct 19 '22 08:10

Thariama


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();
like image 33
Fred Avatar answered Oct 19 '22 07:10

Fred