]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/classes/AddOnManager.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / classes / AddOnManager.js
1 /**
2  * AddOnManager.js
3  *
4  * Copyright, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://www.tinymce.com/license
8  * Contributing: http://www.tinymce.com/contributing
9  */
10
11 /**
12  * This class handles the loading of themes/plugins or other add-ons and their language packs.
13  *
14  * @class tinymce.AddOnManager
15  */
16 define("tinymce/AddOnManager", [
17     "tinymce/dom/ScriptLoader",
18     "tinymce/util/Tools"
19 ], function(ScriptLoader, Tools) {
20     var each = Tools.each;
21
22     function AddOnManager() {
23         var self = this;
24
25         self.items = [];
26         self.urls = {};
27         self.lookup = {};
28     }
29
30     AddOnManager.prototype = {
31         /**
32          * Returns the specified add on by the short name.
33          *
34          * @method get
35          * @param {String} name Add-on to look for.
36          * @return {tinymce.Theme/tinymce.Plugin} Theme or plugin add-on instance or undefined.
37          */
38         get: function(name) {
39             if (this.lookup[name]) {
40                 return this.lookup[name].instance;
41             } else {
42                 return undefined;
43             }
44         },
45
46         dependencies: function(name) {
47             var result;
48
49             if (this.lookup[name]) {
50                 result = this.lookup[name].dependencies;
51             }
52
53             return result || [];
54         },
55
56         /**
57          * Loads a language pack for the specified add-on.
58          *
59          * @method requireLangPack
60          * @param {String} name Short name of the add-on.
61          */
62         requireLangPack: function(name) {
63             var settings = AddOnManager.settings;
64
65             if (settings && settings.language && settings.language_load !== false) {
66                 ScriptLoader.ScriptLoader.add(this.urls[name] + '/langs/' + settings.language + '.js');
67             }
68         },
69
70         /**
71          * Adds a instance of the add-on by it's short name.
72          *
73          * @method add
74          * @param {String} id Short name/id for the add-on.
75          * @param {tinymce.Theme/tinymce.Plugin} addOn Theme or plugin to add.
76          * @return {tinymce.Theme/tinymce.Plugin} The same theme or plugin instance that got passed in.
77          * @example
78          * // Create a simple plugin
79          * tinymce.create('tinymce.plugins.TestPlugin', {
80          *     TestPlugin: function(ed, url) {
81          *         ed.on('click', function(e) {
82          *             ed.windowManager.alert('Hello World!');
83          *         });
84          *     }
85          * });
86          *
87          * // Register plugin using the add method
88          * tinymce.PluginManager.add('test', tinymce.plugins.TestPlugin);
89          *
90          * // Initialize TinyMCE
91          * tinymce.init({
92          *    ...
93          *    plugins: '-test' // Init the plugin but don't try to load it
94          * });
95          */
96         add: function(id, addOn, dependencies) {
97             this.items.push(addOn);
98             this.lookup[id] = {instance: addOn, dependencies: dependencies};
99
100             return addOn;
101         },
102
103         createUrl: function(baseUrl, dep) {
104             if (typeof dep === "object") {
105                 return dep;
106             } else {
107                 return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
108             }
109         },
110
111         /**
112          * Add a set of components that will make up the add-on. Using the url of the add-on name as the base url.
113          * This should be used in development mode.  A new compressor/javascript munger process will ensure that the
114          * components are put together into the plugin.js file and compressed correctly.
115          *
116          * @method addComponents
117          * @param {String} pluginName name of the plugin to load scripts from (will be used to get the base url for the plugins).
118          * @param {Array} scripts Array containing the names of the scripts to load.
119          */
120         addComponents: function(pluginName, scripts) {
121             var pluginUrl = this.urls[pluginName];
122
123             each(scripts, function(script) {
124                 ScriptLoader.ScriptLoader.add(pluginUrl + "/" + script);
125             });
126         },
127
128         /**
129          * Loads an add-on from a specific url.
130          *
131          * @method load
132          * @param {String} n Short name of the add-on that gets loaded.
133          * @param {String} u URL to the add-on that will get loaded.
134          * @param {function} cb Optional callback to execute ones the add-on is loaded.
135          * @param {Object} s Optional scope to execute the callback in.
136          * @example
137          * // Loads a plugin from an external URL
138          * tinymce.PluginManager.load('myplugin', '/some/dir/someplugin/plugin.js');
139          *
140          * // Initialize TinyMCE
141          * tinymce.init({
142          *    ...
143          *    plugins: '-myplugin' // Don't try to load it again
144          * });
145          */
146         load: function(n, u, cb, s) {
147             var t = this, url = u;
148
149             function loadDependencies() {
150                 var dependencies = t.dependencies(n);
151
152                 each(dependencies, function(dep) {
153                     var newUrl = t.createUrl(u, dep);
154
155                     t.load(newUrl.resource, newUrl, undefined, undefined);
156                 });
157
158                 if (cb) {
159                     if (s) {
160                         cb.call(s);
161                     } else {
162                         cb.call(ScriptLoader);
163                     }
164                 }
165             }
166
167             if (t.urls[n]) {
168                 return;
169             }
170
171             if (typeof u === "object") {
172                 url = u.prefix + u.resource + u.suffix;
173             }
174
175             if (url.indexOf('/') !== 0 && url.indexOf('://') == -1) {
176                 url = AddOnManager.baseURL + '/' + url;
177             }
178
179             t.urls[n] = url.substring(0, url.lastIndexOf('/'));
180
181             if (t.lookup[n]) {
182                 loadDependencies();
183             } else {
184                 ScriptLoader.ScriptLoader.add(url, loadDependencies, s);
185             }
186         }
187     };
188
189     AddOnManager.PluginManager = new AddOnManager();
190     AddOnManager.ThemeManager = new AddOnManager();
191
192     return AddOnManager;
193 });
194
195 /**
196  * TinyMCE theme class.
197  *
198  * @class tinymce.Theme
199  */
200
201 /**
202  * This method is responsible for rendering/generating the overall user interface with toolbars, buttons, iframe containers etc.
203  *
204  * @method renderUI
205  * @param {Object} obj Object parameter containing the targetNode DOM node that will be replaced visually with an editor instance.
206  * @return {Object} an object with items like iframeContainer, editorContainer, sizeContainer, deltaWidth, deltaHeight.
207  */
208
209 /**
210  * 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.
211  *
212  * @class tinymce.Plugin
213  * @example
214  * tinymce.PluginManager.add('example', function(editor, url) {
215  *     // Add a button that opens a window
216  *     editor.addButton('example', {
217  *         text: 'My button',
218  *         icon: false,
219  *         onclick: function() {
220  *             // Open window
221  *             editor.windowManager.open({
222  *                 title: 'Example plugin',
223  *                 body: [
224  *                     {type: 'textbox', name: 'title', label: 'Title'}
225  *                 ],
226  *                 onsubmit: function(e) {
227  *                     // Insert content when the window form is submitted
228  *                     editor.insertContent('Title: ' + e.data.title);
229  *                 }
230  *             });
231  *         }
232  *     });
233  *
234  *     // Adds a menu item to the tools menu
235  *     editor.addMenuItem('example', {
236  *         text: 'Example plugin',
237  *         context: 'tools',
238  *         onclick: function() {
239  *             // Open window with a specific url
240  *             editor.windowManager.open({
241  *                 title: 'TinyMCE site',
242  *                 url: 'http://www.tinymce.com',
243  *                 width: 800,
244  *                 height: 600,
245  *                 buttons: [{
246  *                     text: 'Close',
247  *                     onclick: 'close'
248  *                 }]
249  *             });
250  *         }
251  *     });
252  * });
253  */