4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
12 * This class handles the loading of themes/plugins or other add-ons and their language packs.
14 * @class tinymce.AddOnManager
16 define("tinymce/AddOnManager", [
17 "tinymce/dom/ScriptLoader",
19 ], function(ScriptLoader, Tools) {
20 var each = Tools.each;
22 function AddOnManager() {
30 AddOnManager.prototype = {
32 * Returns the specified add on by the short name.
35 * @param {String} name Add-on to look for.
36 * @return {tinymce.Theme/tinymce.Plugin} Theme or plugin add-on instance or undefined.
39 if (this.lookup[name]) {
40 return this.lookup[name].instance;
46 dependencies: function(name) {
49 if (this.lookup[name]) {
50 result = this.lookup[name].dependencies;
57 * Loads a language pack for the specified add-on.
59 * @method requireLangPack
60 * @param {String} name Short name of the add-on.
62 requireLangPack: function(name) {
63 var settings = AddOnManager.settings;
65 if (settings && settings.language && settings.language_load !== false) {
66 ScriptLoader.ScriptLoader.add(this.urls[name] + '/langs/' + settings.language + '.js');
71 * Adds a instance of the add-on by it's short name.
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.
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!');
87 * // Register plugin using the add method
88 * tinymce.PluginManager.add('test', tinymce.plugins.TestPlugin);
90 * // Initialize TinyMCE
93 * plugins: '-test' // Init the plugin but don't try to load it
96 add: function(id, addOn, dependencies) {
97 this.items.push(addOn);
98 this.lookup[id] = {instance: addOn, dependencies: dependencies};
103 createUrl: function(baseUrl, dep) {
104 if (typeof dep === "object") {
107 return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
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.
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.
120 addComponents: function(pluginName, scripts) {
121 var pluginUrl = this.urls[pluginName];
123 each(scripts, function(script) {
124 ScriptLoader.ScriptLoader.add(pluginUrl + "/" + script);
129 * Loads an add-on from a specific url.
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.
137 * // Loads a plugin from an external URL
138 * tinymce.PluginManager.load('myplugin', '/some/dir/someplugin/plugin.js');
140 * // Initialize TinyMCE
143 * plugins: '-myplugin' // Don't try to load it again
146 load: function(n, u, cb, s) {
147 var t = this, url = u;
149 function loadDependencies() {
150 var dependencies = t.dependencies(n);
152 each(dependencies, function(dep) {
153 var newUrl = t.createUrl(u, dep);
155 t.load(newUrl.resource, newUrl, undefined, undefined);
162 cb.call(ScriptLoader);
171 if (typeof u === "object") {
172 url = u.prefix + u.resource + u.suffix;
175 if (url.indexOf('/') !== 0 && url.indexOf('://') == -1) {
176 url = AddOnManager.baseURL + '/' + url;
179 t.urls[n] = url.substring(0, url.lastIndexOf('/'));
184 ScriptLoader.ScriptLoader.add(url, loadDependencies, s);
189 AddOnManager.PluginManager = new AddOnManager();
190 AddOnManager.ThemeManager = new AddOnManager();
196 * TinyMCE theme class.
198 * @class tinymce.Theme
202 * This method is responsible for rendering/generating the overall user interface with toolbars, buttons, iframe containers etc.
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.
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.
212 * @class tinymce.Plugin
214 * tinymce.PluginManager.add('example', function(editor, url) {
215 * // Add a button that opens a window
216 * editor.addButton('example', {
219 * onclick: function() {
221 * editor.windowManager.open({
222 * title: 'Example plugin',
224 * {type: 'textbox', name: 'title', label: 'Title'}
226 * onsubmit: function(e) {
227 * // Insert content when the window form is submitted
228 * editor.insertContent('Title: ' + e.data.title);
234 * // Adds a menu item to the tools menu
235 * editor.addMenuItem('example', {
236 * text: 'Example plugin',
238 * onclick: function() {
239 * // Open window with a specific url
240 * editor.windowManager.open({
241 * title: 'TinyMCE site',
242 * url: 'http://www.tinymce.com',