PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/includes/js/tiny_mce/jscripts/tiny_mce/classes/AddOnManager.js

https://github.com/KenBoyer/CompactCMS
JavaScript | 305 lines | 38 code | 23 blank | 244 comment | 8 complexity | 656a19b1fa7d4e7ad5f35fc7073e3d7e MD5 | raw file
  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. (function(tinymce) {
  11. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  12. /**
  13. * This class handles the loading of themes/plugins or other add-ons and their language packs.
  14. *
  15. * @class tinymce.AddOnManager
  16. */
  17. tinymce.create('tinymce.AddOnManager', {
  18. AddOnManager : function() {
  19. var self = this;
  20. self.items = [];
  21. self.urls = {};
  22. self.lookup = {};
  23. self.onAdd = new Dispatcher(self);
  24. },
  25. /**
  26. * Fires when a item is added.
  27. *
  28. * @event onAdd
  29. */
  30. /**
  31. * Returns the specified add on by the short name.
  32. *
  33. * @method get
  34. * @param {String} n Add-on to look for.
  35. * @return {tinymce.Theme/tinymce.Plugin} Theme or plugin add-on instance or undefined.
  36. */
  37. get : function(n) {
  38. return this.lookup[n];
  39. },
  40. /**
  41. * Loads a language pack for the specified add-on.
  42. *
  43. * @method requireLangPack
  44. * @param {String} n Short name of the add-on.
  45. */
  46. requireLangPack : function(n) {
  47. var s = tinymce.settings;
  48. if (s && s.language && s.language_load !== false)
  49. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  50. },
  51. /**
  52. * Adds a instance of the add-on by it's short name.
  53. *
  54. * @method add
  55. * @param {String} id Short name/id for the add-on.
  56. * @param {tinymce.Theme/tinymce.Plugin} o Theme or plugin to add.
  57. * @return {tinymce.Theme/tinymce.Plugin} The same theme or plugin instance that got passed in.
  58. * @example
  59. * // Create a simple plugin
  60. * tinymce.create('tinymce.plugins.TestPlugin', {
  61. * TestPlugin : function(ed, url) {
  62. * ed.onClick.add(function(ed, e) {
  63. * ed.windowManager.alert('Hello World!');
  64. * });
  65. * }
  66. * });
  67. *
  68. * // Register plugin using the add method
  69. * tinymce.PluginManager.add('test', tinymce.plugins.TestPlugin);
  70. *
  71. * // Initialize TinyMCE
  72. * tinyMCE.init({
  73. * ...
  74. * plugins : '-test' // Init the plugin but don't try to load it
  75. * });
  76. */
  77. add : function(id, o) {
  78. this.items.push(o);
  79. this.lookup[id] = o;
  80. this.onAdd.dispatch(this, id, o);
  81. return o;
  82. },
  83. /**
  84. * Loads an add-on from a specific url.
  85. *
  86. * @method load
  87. * @param {String} n Short name of the add-on that gets loaded.
  88. * @param {String} u URL to the add-on that will get loaded.
  89. * @param {function} cb Optional callback to execute ones the add-on is loaded.
  90. * @param {Object} s Optional scope to execute the callback in.
  91. * @example
  92. * // Loads a plugin from an external URL
  93. * tinymce.PluginManager.load('myplugin', '/some/dir/someplugin/editor_plugin.js');
  94. *
  95. * // Initialize TinyMCE
  96. * tinyMCE.init({
  97. * ...
  98. * plugins : '-myplugin' // Don't try to load it again
  99. * });
  100. */
  101. load : function(n, u, cb, s) {
  102. var t = this;
  103. if (t.urls[n])
  104. return;
  105. if (u.indexOf('/') != 0 && u.indexOf('://') == -1)
  106. u = tinymce.baseURL + '/' + u;
  107. t.urls[n] = u.substring(0, u.lastIndexOf('/'));
  108. if (!t.lookup[n])
  109. tinymce.ScriptLoader.add(u, cb, s);
  110. }
  111. });
  112. // Create plugin and theme managers
  113. tinymce.PluginManager = new tinymce.AddOnManager();
  114. tinymce.ThemeManager = new tinymce.AddOnManager();
  115. }(tinymce));
  116. /**
  117. * TinyMCE theme class.
  118. *
  119. * @class tinymce.Theme
  120. */
  121. /**
  122. * Initializes the theme.
  123. *
  124. * @method init
  125. * @param {tinymce.Editor} editor Editor instance that created the theme instance.
  126. * @param {String} url Absolute URL where the theme is located.
  127. */
  128. /**
  129. * Meta info method, this method gets executed when TinyMCE wants to present information about the theme for example in the about/help dialog.
  130. *
  131. * @method getInfo
  132. * @return {Object} Returns an object with meta information about the theme the current items are longname, author, authorurl, infourl and version.
  133. */
  134. /**
  135. * This method is responsible for rendering/generating the overall user interface with toolbars, buttons, iframe containers etc.
  136. *
  137. * @method renderUI
  138. * @param {Object} obj Object parameter containing the targetNode DOM node that will be replaced visually with an editor instance.
  139. * @return {Object} an object with items like iframeContainer, editorContainer, sizeContainer, deltaWidth, deltaHeight.
  140. */
  141. /**
  142. * 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.
  143. *
  144. * @class tinymce.Plugin
  145. * @example
  146. * // Create a new plugin class
  147. * tinymce.create('tinymce.plugins.ExamplePlugin', {
  148. * init : function(ed, url) {
  149. * // Register an example button
  150. * ed.addButton('example', {
  151. * title : 'example.desc',
  152. * onclick : function() {
  153. * // Display an alert when the user clicks the button
  154. * ed.windowManager.alert('Hello world!');
  155. * },
  156. * 'class' : 'bold' // Use the bold icon from the theme
  157. * });
  158. * }
  159. * });
  160. *
  161. * // Register plugin with a short name
  162. * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
  163. *
  164. * // Initialize TinyMCE with the new plugin and button
  165. * tinyMCE.init({
  166. * ...
  167. * plugins : '-example', // - means TinyMCE will not try to load it
  168. * theme_advanced_buttons1 : 'example' // Add the new example button to the toolbar
  169. * });
  170. */
  171. /**
  172. * Initialization function for the plugin. This will be called when the plugin is created.
  173. *
  174. * @method init
  175. * @param {tinymce.Editor} editor Editor instance that created the plugin instance.
  176. * @param {String} url Absolute URL where the plugin is located.
  177. * @example
  178. * // Creates a new plugin class
  179. * tinymce.create('tinymce.plugins.ExamplePlugin', {
  180. * init : function(ed, url) {
  181. * // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
  182. * ed.addCommand('mceExample', function() {
  183. * ed.windowManager.open({
  184. * file : url + '/dialog.htm',
  185. * width : 320 + ed.getLang('example.delta_width', 0),
  186. * height : 120 + ed.getLang('example.delta_height', 0),
  187. * inline : 1
  188. * }, {
  189. * plugin_url : url, // Plugin absolute URL
  190. * some_custom_arg : 'custom arg' // Custom argument
  191. * });
  192. * });
  193. *
  194. * // Register example button
  195. * ed.addButton('example', {
  196. * title : 'example.desc',
  197. * cmd : 'mceExample',
  198. * image : url + '/img/example.gif'
  199. * });
  200. *
  201. * // Add a node change handler, selects the button in the UI when a image is selected
  202. * ed.onNodeChange.add(function(ed, cm, n) {
  203. * cm.setActive('example', n.nodeName == 'IMG');
  204. * });
  205. * }
  206. * });
  207. *
  208. * // Register plugin
  209. * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
  210. */
  211. /**
  212. * Meta info method, this method gets executed when TinyMCE wants to present information about the plugin for example in the about/help dialog.
  213. *
  214. * @method getInfo
  215. * @return {Object} Returns an object with meta information about the plugin the current items are longname, author, authorurl, infourl and version.
  216. * @example
  217. * // Creates a new plugin class
  218. * tinymce.create('tinymce.plugins.ExamplePlugin', {
  219. * // Meta info method
  220. * getInfo : function() {
  221. * return {
  222. * longname : 'Example plugin',
  223. * author : 'Some author',
  224. * authorurl : 'http://tinymce.moxiecode.com',
  225. * infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example',
  226. * version : "1.0"
  227. * };
  228. * }
  229. * });
  230. *
  231. * // Register plugin
  232. * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
  233. *
  234. * // Initialize TinyMCE with the new plugin
  235. * tinyMCE.init({
  236. * ...
  237. * plugins : '-example' // - means TinyMCE will not try to load it
  238. * });
  239. */
  240. /**
  241. * Gets called when a new control instance is created.
  242. *
  243. * @method createControl
  244. * @param {String} name Control name to create for example "mylistbox"
  245. * @param {tinymce.ControlManager} controlman Control manager/factory to use to create the control.
  246. * @return {tinymce.ui.Control} Returns a new control instance or null.
  247. * @example
  248. * // Creates a new plugin class
  249. * tinymce.create('tinymce.plugins.ExamplePlugin', {
  250. * createControl: function(n, cm) {
  251. * switch (n) {
  252. * case 'mylistbox':
  253. * var mlb = cm.createListBox('mylistbox', {
  254. * title : 'My list box',
  255. * onselect : function(v) {
  256. * tinyMCE.activeEditor.windowManager.alert('Value selected:' + v);
  257. * }
  258. * });
  259. *
  260. * // Add some values to the list box
  261. * mlb.add('Some item 1', 'val1');
  262. * mlb.add('some item 2', 'val2');
  263. * mlb.add('some item 3', 'val3');
  264. *
  265. * // Return the new listbox instance
  266. * return mlb;
  267. * }
  268. *
  269. * return null;
  270. * }
  271. * });
  272. *
  273. * // Register plugin
  274. * tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
  275. *
  276. * // Initialize TinyMCE with the new plugin and button
  277. * tinyMCE.init({
  278. * ...
  279. * plugins : '-example', // - means TinyMCE will not try to load it
  280. * theme_advanced_buttons1 : 'mylistbox' // Add the new mylistbox control to the toolbar
  281. * });
  282. */