Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically load & unload a TinyMCE Plugin

Tags:

tinymce

Does anyone know if there is a way I can dynamically load and unload a TinyMCE plugin after TinyMCE has already been loaded? Specifically, I'm thinking about asking the user whether or not they wish to load the fullpage plugin using perhaps a radio button or something above TinyMCE:

<input type="radio" name="fullpage" value="enabled"  /> Enable Fullpage Plugin<br />
<input type="radio" name="fullpage" value="disabled" /> Disable Fullpage Plugin<br />
<textarea name="tinymce" id="tinymce">...</textarea>

I suppose I could destroy the original instance and load a new config (one for enabled / one for disabled), but it seems as though there should be a more elegant way of loading and unloading plugins.

like image 936
Matt Simpson Avatar asked Dec 06 '09 19:12

Matt Simpson


2 Answers

I've used TinyMCE in the past a bit, and don't recall any way of doing this.

Checking the API docs at http://tinymce.moxiecode.com/js/tinymce/docs/api/index.html#class_tinymce.Editor.html, it seems like there is only a property for the plugins, no method() to add more.

It would seem that destroying the original instance and loading a new config is your only option. (Unless you want to modify TinyMCE code)

like image 170
Jonathan Fingland Avatar answered Oct 01 '22 06:10

Jonathan Fingland


You can use the AddOnManager load() function to dynamically load a plugin (AddOnManager API Reference). You may need to create an instance of the plugin class, in this case tinymce.plugins.FullPagePlugin once it's loaded.

However, since most plugins are designed to be loaded during the initialization of the editor, it's unlikely that the plugin will work consistently. The full page plugin in particular expects to be able to filter the content on the way into the editor so it's likely to have problems.

REgards,

Adrian Sutton.
http://tinymce.ephox.com

like image 34
ajsutton Avatar answered Oct 01 '22 07:10

ajsutton