JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
c9bba7b512a89d2e177ecf47bacde30aff4ffcd5
[ckeditor.git] / _source / core / plugins.js
1 /*\r
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @fileOverview Defines the {@link CKEDITOR.plugins} object, which is used to\r
8  *              manage plugins registration and loading.\r
9  */\r
10 \r
11 /**\r
12  * Manages plugins registration and loading.\r
13  * @namespace\r
14  * @augments CKEDITOR.resourceManager\r
15  * @example\r
16  */\r
17 CKEDITOR.plugins = new CKEDITOR.resourceManager(\r
18         '_source/' +    // @Packager.RemoveLine\r
19         'plugins/', 'plugin' );\r
20 \r
21 // PACKAGER_RENAME( CKEDITOR.plugins )\r
22 \r
23 CKEDITOR.plugins.load = CKEDITOR.tools.override( CKEDITOR.plugins.load, function( originalLoad )\r
24         {\r
25                 return function( name, callback, scope )\r
26                 {\r
27                         var allPlugins = {};\r
28 \r
29                         var loadPlugins = function( names )\r
30                         {\r
31                                 originalLoad.call( this, names, function( plugins )\r
32                                         {\r
33                                                 CKEDITOR.tools.extend( allPlugins, plugins );\r
34 \r
35                                                 var requiredPlugins = [];\r
36                                                 for ( var pluginName in plugins )\r
37                                                 {\r
38                                                         var plugin = plugins[ pluginName ],\r
39                                                                 requires = plugin && plugin.requires;\r
40 \r
41                                                         if ( requires )\r
42                                                         {\r
43                                                                 for ( var i = 0 ; i < requires.length ; i++ )\r
44                                                                 {\r
45                                                                         if ( !allPlugins[ requires[ i ] ] )\r
46                                                                                 requiredPlugins.push( requires[ i ] );\r
47                                                                 }\r
48                                                         }\r
49                                                 }\r
50 \r
51                                                 if ( requiredPlugins.length )\r
52                                                         loadPlugins.call( this, requiredPlugins );\r
53                                                 else\r
54                                                 {\r
55                                                         // Call the "onLoad" function for all plugins.\r
56                                                         for ( pluginName in allPlugins )\r
57                                                         {\r
58                                                                 plugin = allPlugins[ pluginName ];\r
59                                                                 if ( plugin.onLoad && !plugin.onLoad._called )\r
60                                                                 {\r
61                                                                         plugin.onLoad();\r
62                                                                         plugin.onLoad._called = 1;\r
63                                                                 }\r
64                                                         }\r
65 \r
66                                                         // Call the callback.\r
67                                                         if ( callback )\r
68                                                                 callback.call( scope || window, allPlugins );\r
69                                                 }\r
70                                         }\r
71                                         , this);\r
72 \r
73                         };\r
74 \r
75                         loadPlugins.call( this, name );\r
76                 };\r
77         });\r
78 \r
79 CKEDITOR.plugins.setLang = function( pluginName, languageCode, languageEntries )\r
80 {\r
81         var plugin = this.get( pluginName ),\r
82                 pluginLang = plugin.lang || ( plugin.lang = {} );\r
83 \r
84         pluginLang[ languageCode ] = languageEntries;\r
85 };\r