4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
15 * This class handles the loading of themes/plugins or other add-ons and their language packs.
17 * @class tinymce.AddOnManager
19 tinymce.create('tinymce.AddOnManager', {
20 AddOnManager : function() {
26 self.onAdd = new Dispatcher(self);
30 * Fires when a item is added.
36 * Returns the specified add on by the short name.
39 * @param {String} n Add-on to look for.
40 * @return {tinymce.Theme/tinymce.Plugin} Theme or plugin add-on instance or undefined.
43 return this.lookup[n];
47 * Loads a language pack for the specified add-on.
49 * @method requireLangPack
50 * @param {String} n Short name of the add-on.
52 requireLangPack : function(n) {
53 var s = tinymce.settings;
55 if (s && s.language && s.language_load !== false)
56 tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
60 * Adds a instance of the add-on by it's short name.
63 * @param {String} id Short name/id for the add-on.
64 * @param {tinymce.Theme/tinymce.Plugin} o Theme or plugin to add.
65 * @return {tinymce.Theme/tinymce.Plugin} The same theme or plugin instance that got passed in.
67 * // Create a simple plugin
68 * tinymce.create('tinymce.plugins.TestPlugin', {
69 * TestPlugin : function(ed, url) {
70 * ed.onClick.add(function(ed, e) {
71 * ed.windowManager.alert('Hello World!');
76 * // Register plugin using the add method
77 * tinymce.PluginManager.add('test', tinymce.plugins.TestPlugin);
79 * // Initialize TinyMCE
82 * plugins : '-test' // Init the plugin but don't try to load it
85 add : function(id, o) {
88 this.onAdd.dispatch(this, id, o);
94 * Loads an add-on from a specific url.
97 * @param {String} n Short name of the add-on that gets loaded.
98 * @param {String} u URL to the add-on that will get loaded.
99 * @param {function} cb Optional callback to execute ones the add-on is loaded.
100 * @param {Object} s Optional scope to execute the callback in.
102 * // Loads a plugin from an external URL
103 * tinymce.PluginManager.load('myplugin', '/some/dir/someplugin/editor_plugin.js');
105 * // Initialize TinyMCE
108 * plugins : '-myplugin' // Don't try to load it again
111 load : function(n, u, cb, s) {
117 if (u.indexOf('/') != 0 && u.indexOf('://') == -1)
118 u = tinymce.baseURL + '/' + u;
120 t.urls[n] = u.substring(0, u.lastIndexOf('/'));
123 tinymce.ScriptLoader.add(u, cb, s);
127 // Create plugin and theme managers
128 tinymce.PluginManager = new tinymce.AddOnManager();
129 tinymce.ThemeManager = new tinymce.AddOnManager();
133 * TinyMCE theme class.
135 * @class tinymce.Theme
139 * Initializes the theme.
142 * @param {tinymce.Editor} editor Editor instance that created the theme instance.
143 * @param {String} url Absolute URL where the theme is located.
147 * Meta info method, this method gets executed when TinyMCE wants to present information about the theme for example in the about/help dialog.
150 * @return {Object} Returns an object with meta information about the theme the current items are longname, author, authorurl, infourl and version.
154 * This method is responsible for rendering/generating the overall user interface with toolbars, buttons, iframe containers etc.
157 * @param {Object} obj Object parameter containing the targetNode DOM node that will be replaced visually with an editor instance.
158 * @return {Object} an object with items like iframeContainer, editorContainer, sizeContainer, deltaWidth, deltaHeight.
162 * Plugin base class, this is a pseudo class that describes how a plugin is to be created for TinyMCE. The methods below are all optional.
164 * @class tinymce.Plugin
166 * // Create a new plugin class
167 * tinymce.create('tinymce.plugins.ExamplePlugin', {
168 * init : function(ed, url) {
169 * // Register an example button
170 * ed.addButton('example', {
171 * title : 'example.desc',
172 * onclick : function() {
173 * // Display an alert when the user clicks the button
174 * ed.windowManager.alert('Hello world!');
176 * 'class' : 'bold' // Use the bold icon from the theme
181 * // Register plugin with a short name
182 * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
184 * // Initialize TinyMCE with the new plugin and button
187 * plugins : '-example', // - means TinyMCE will not try to load it
188 * theme_advanced_buttons1 : 'example' // Add the new example button to the toolbar
193 * Initialization function for the plugin. This will be called when the plugin is created.
196 * @param {tinymce.Editor} editor Editor instance that created the plugin instance.
197 * @param {String} url Absolute URL where the plugin is located.
199 * // Creates a new plugin class
200 * tinymce.create('tinymce.plugins.ExamplePlugin', {
201 * init : function(ed, url) {
202 * // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
203 * ed.addCommand('mceExample', function() {
204 * ed.windowManager.open({
205 * file : url + '/dialog.htm',
206 * width : 320 + ed.getLang('example.delta_width', 0),
207 * height : 120 + ed.getLang('example.delta_height', 0),
210 * plugin_url : url, // Plugin absolute URL
211 * some_custom_arg : 'custom arg' // Custom argument
215 * // Register example button
216 * ed.addButton('example', {
217 * title : 'example.desc',
218 * cmd : 'mceExample',
219 * image : url + '/img/example.gif'
222 * // Add a node change handler, selects the button in the UI when a image is selected
223 * ed.onNodeChange.add(function(ed, cm, n) {
224 * cm.setActive('example', n.nodeName == 'IMG');
230 * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
234 * Meta info method, this method gets executed when TinyMCE wants to present information about the plugin for example in the about/help dialog.
237 * @return {Object} Returns an object with meta information about the plugin the current items are longname, author, authorurl, infourl and version.
239 * // Creates a new plugin class
240 * tinymce.create('tinymce.plugins.ExamplePlugin', {
241 * // Meta info method
242 * getInfo : function() {
244 * longname : 'Example plugin',
245 * author : 'Some author',
246 * authorurl : 'http://tinymce.moxiecode.com',
247 * infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example',
254 * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
256 * // Initialize TinyMCE with the new plugin
259 * plugins : '-example' // - means TinyMCE will not try to load it
264 * Gets called when a new control instance is created.
266 * @method createControl
267 * @param {String} name Control name to create for example "mylistbox"
268 * @param {tinymce.ControlManager} controlman Control manager/factory to use to create the control.
269 * @return {tinymce.ui.Control} Returns a new control instance or null.
271 * // Creates a new plugin class
272 * tinymce.create('tinymce.plugins.ExamplePlugin', {
273 * createControl: function(n, cm) {
276 * var mlb = cm.createListBox('mylistbox', {
277 * title : 'My list box',
278 * onselect : function(v) {
279 * tinyMCE.activeEditor.windowManager.alert('Value selected:' + v);
283 * // Add some values to the list box
284 * mlb.add('Some item 1', 'val1');
285 * mlb.add('some item 2', 'val2');
286 * mlb.add('some item 3', 'val3');
288 * // Return the new listbox instance
297 * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
299 * // Initialize TinyMCE with the new plugin and button
302 * plugins : '-example', // - means TinyMCE will not try to load it
303 * theme_advanced_buttons1 : 'mylistbox' // Add the new mylistbox control to the toolbar