]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/tiny_mce/classes/AddOnManager.js
Release 6.2.2
[Github/sugarcrm.git] / include / javascript / tiny_mce / classes / AddOnManager.js
1 /**
2  * AddOnManager.js
3  *
4  * Copyright 2009, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://tinymce.moxiecode.com/license
8  * Contributing: http://tinymce.moxiecode.com/contributing
9  */
10
11 (function(tinymce) {
12         var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
13
14         /**
15          * This class handles the loading of themes/plugins or other add-ons and their language packs.
16          *
17          * @class tinymce.AddOnManager
18          */
19         tinymce.create('tinymce.AddOnManager', {
20                 AddOnManager : function() {
21                         var self = this;
22
23                         self.items = [];
24                         self.urls = {};
25                         self.lookup = {};
26                         self.onAdd = new Dispatcher(self);
27                 },
28
29                 /**
30                  * Fires when a item is added.
31                  *
32                  * @event onAdd
33                  */
34
35                 /**
36                  * Returns the specified add on by the short name.
37                  *
38                  * @method get
39                  * @param {String} n Add-on to look for.
40                  * @return {tinymce.Theme/tinymce.Plugin} Theme or plugin add-on instance or undefined.
41                  */
42                 get : function(n) {
43                         return this.lookup[n];
44                 },
45
46                 /**
47                  * Loads a language pack for the specified add-on.
48                  *
49                  * @method requireLangPack
50                  * @param {String} n Short name of the add-on.
51                  */
52                 requireLangPack : function(n) {
53                         var s = tinymce.settings;
54
55                         if (s && s.language && s.language_load !== false)
56                                 tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
57                 },
58
59                 /**
60                  * Adds a instance of the add-on by it's short name.
61                  *
62                  * @method add
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.
66                  * @example
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!');
72                  *         });
73                  *     }
74                  * });
75                  * 
76                  * // Register plugin using the add method
77                  * tinymce.PluginManager.add('test', tinymce.plugins.TestPlugin);
78                  * 
79                  * // Initialize TinyMCE
80                  * tinyMCE.init({
81                  *    ...
82                  *    plugins : '-test' // Init the plugin but don't try to load it
83                  * });
84                  */
85                 add : function(id, o) {
86                         this.items.push(o);
87                         this.lookup[id] = o;
88                         this.onAdd.dispatch(this, id, o);
89
90                         return o;
91                 },
92
93                 /**
94                  * Loads an add-on from a specific url.
95                  *
96                  * @method load
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.
101                  * @example
102                  * // Loads a plugin from an external URL
103                  * tinymce.PluginManager.load('myplugin', '/some/dir/someplugin/editor_plugin.js');
104                  * 
105                  * // Initialize TinyMCE
106                  * tinyMCE.init({
107                  *    ...
108                  *    plugins : '-myplugin' // Don't try to load it again
109                  * });
110                  */
111                 load : function(n, u, cb, s) {
112                         var t = this;
113
114                         if (t.urls[n])
115                                 return;
116
117                         if (u.indexOf('/') != 0 && u.indexOf('://') == -1)
118                                 u = tinymce.baseURL + '/' + u;
119
120                         t.urls[n] = u.substring(0, u.lastIndexOf('/'));
121
122                         if (!t.lookup[n])
123                                 tinymce.ScriptLoader.add(u, cb, s);
124                 }
125         });
126
127         // Create plugin and theme managers
128         tinymce.PluginManager = new tinymce.AddOnManager();
129         tinymce.ThemeManager = new tinymce.AddOnManager();
130 }(tinymce));
131
132 /**
133  * TinyMCE theme class.
134  *
135  * @class tinymce.Theme
136  */
137
138 /**
139  * Initializes the theme.
140  *
141  * @method init
142  * @param {tinymce.Editor} editor Editor instance that created the theme instance.
143  * @param {String} url Absolute URL where the theme is located. 
144  */
145
146 /**
147  * Meta info method, this method gets executed when TinyMCE wants to present information about the theme for example in the about/help dialog.
148  *
149  * @method getInfo
150  * @return {Object} Returns an object with meta information about the theme the current items are longname, author, authorurl, infourl and version.
151  */
152
153 /**
154  * This method is responsible for rendering/generating the overall user interface with toolbars, buttons, iframe containers etc.
155  *
156  * @method renderUI
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. 
159  */
160
161 /**
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.
163  *
164  * @class tinymce.Plugin
165  * @example
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!');
175  *             },
176  *             'class' : 'bold' // Use the bold icon from the theme
177  *         });
178  *     }
179  * });
180  * 
181  * // Register plugin with a short name
182  * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
183  * 
184  * // Initialize TinyMCE with the new plugin and button
185  * tinyMCE.init({
186  *    ...
187  *    plugins : '-example', // - means TinyMCE will not try to load it
188  *    theme_advanced_buttons1 : 'example' // Add the new example button to the toolbar
189  * });
190  */
191
192 /**
193  * Initialization function for the plugin. This will be called when the plugin is created. 
194  *
195  * @method init
196  * @param {tinymce.Editor} editor Editor instance that created the plugin instance. 
197  * @param {String} url Absolute URL where the plugin is located. 
198  * @example
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),
208  *                 inline : 1
209  *             }, {
210  *                 plugin_url : url, // Plugin absolute URL
211  *                 some_custom_arg : 'custom arg' // Custom argument
212  *             });
213  *         });
214  * 
215  *         // Register example button
216  *         ed.addButton('example', {
217  *             title : 'example.desc',
218  *             cmd : 'mceExample',
219  *             image : url + '/img/example.gif'
220  *         });
221  * 
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');
225  *         });
226  *     }
227  * });
228  * 
229  * // Register plugin
230  * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
231  */
232
233 /**
234  * Meta info method, this method gets executed when TinyMCE wants to present information about the plugin for example in the about/help dialog.
235  *
236  * @method getInfo
237  * @return {Object} Returns an object with meta information about the plugin the current items are longname, author, authorurl, infourl and version.
238  * @example 
239  * // Creates a new plugin class
240  * tinymce.create('tinymce.plugins.ExamplePlugin', {
241  *     // Meta info method
242  *     getInfo : function() {
243  *         return {
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',
248  *             version : "1.0"
249  *         };
250  *     }
251  * });
252  * 
253  * // Register plugin
254  * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
255  * 
256  * // Initialize TinyMCE with the new plugin
257  * tinyMCE.init({
258  *    ...
259  *    plugins : '-example' // - means TinyMCE will not try to load it
260  * });
261  */
262
263 /**
264  * Gets called when a new control instance is created.
265  *
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.
270  * @example 
271  * // Creates a new plugin class
272  * tinymce.create('tinymce.plugins.ExamplePlugin', {
273  *     createControl: function(n, cm) {
274  *         switch (n) {
275  *             case 'mylistbox':
276  *                 var mlb = cm.createListBox('mylistbox', {
277  *                      title : 'My list box',
278  *                      onselect : function(v) {
279  *                          tinyMCE.activeEditor.windowManager.alert('Value selected:' + v);
280  *                      }
281  *                 });
282  * 
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');
287  * 
288  *                 // Return the new listbox instance
289  *                 return mlb;
290  *         }
291  * 
292  *         return null;
293  *     }
294  * });
295  * 
296  * // Register plugin
297  * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
298  * 
299  * // Initialize TinyMCE with the new plugin and button
300  * tinyMCE.init({
301  *    ...
302  *    plugins : '-example', // - means TinyMCE will not try to load it
303  *    theme_advanced_buttons1 : 'mylistbox' // Add the new mylistbox control to the toolbar
304  * });
305  */