diff options
Diffstat (limited to 'sources/core/plugins.js')
-rw-r--r-- | sources/core/plugins.js | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/sources/core/plugins.js b/sources/core/plugins.js new file mode 100644 index 0000000..8e6c952 --- /dev/null +++ b/sources/core/plugins.js | |||
@@ -0,0 +1,119 @@ | |||
1 | /** | ||
2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. | ||
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | ||
4 | */ | ||
5 | |||
6 | /** | ||
7 | * @fileOverview Defines the {@link CKEDITOR.plugins} object, which is used to | ||
8 | * manage plugins registration and loading. | ||
9 | */ | ||
10 | |||
11 | /** | ||
12 | * Manages plugins registration and loading. | ||
13 | * | ||
14 | * @class | ||
15 | * @extends CKEDITOR.resourceManager | ||
16 | * @singleton | ||
17 | */ | ||
18 | CKEDITOR.plugins = new CKEDITOR.resourceManager( 'plugins/', 'plugin' ); | ||
19 | |||
20 | // PACKAGER_RENAME( CKEDITOR.plugins ) | ||
21 | |||
22 | CKEDITOR.plugins.load = CKEDITOR.tools.override( CKEDITOR.plugins.load, function( originalLoad ) { | ||
23 | var initialized = {}; | ||
24 | |||
25 | return function( name, callback, scope ) { | ||
26 | var allPlugins = {}; | ||
27 | |||
28 | var loadPlugins = function( names ) { | ||
29 | originalLoad.call( this, names, function( plugins ) { | ||
30 | CKEDITOR.tools.extend( allPlugins, plugins ); | ||
31 | |||
32 | var requiredPlugins = []; | ||
33 | for ( var pluginName in plugins ) { | ||
34 | var plugin = plugins[ pluginName ], | ||
35 | requires = plugin && plugin.requires; | ||
36 | |||
37 | if ( !initialized[ pluginName ] ) { | ||
38 | // Register all icons eventually defined by this plugin. | ||
39 | if ( plugin.icons ) { | ||
40 | var icons = plugin.icons.split( ',' ); | ||
41 | for ( var ic = icons.length; ic--; ) { | ||
42 | CKEDITOR.skin.addIcon( icons[ ic ], | ||
43 | plugin.path + | ||
44 | 'icons/' + | ||
45 | ( CKEDITOR.env.hidpi && plugin.hidpi ? 'hidpi/' : '' ) + | ||
46 | icons[ ic ] + | ||
47 | '.png' ); | ||
48 | } | ||
49 | } | ||
50 | initialized[ pluginName ] = 1; | ||
51 | } | ||
52 | |||
53 | if ( requires ) { | ||
54 | // Trasnform it into an array, if it's not one. | ||
55 | if ( requires.split ) | ||
56 | requires = requires.split( ',' ); | ||
57 | |||
58 | for ( var i = 0; i < requires.length; i++ ) { | ||
59 | if ( !allPlugins[ requires[ i ] ] ) | ||
60 | requiredPlugins.push( requires[ i ] ); | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | if ( requiredPlugins.length ) | ||
66 | loadPlugins.call( this, requiredPlugins ); | ||
67 | else { | ||
68 | // Call the "onLoad" function for all plugins. | ||
69 | for ( pluginName in allPlugins ) { | ||
70 | plugin = allPlugins[ pluginName ]; | ||
71 | if ( plugin.onLoad && !plugin.onLoad._called ) { | ||
72 | // Make it possible to return false from plugin::onLoad to disable it. | ||
73 | if ( plugin.onLoad() === false ) | ||
74 | delete allPlugins[ pluginName ]; | ||
75 | |||
76 | plugin.onLoad._called = 1; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | // Call the callback. | ||
81 | if ( callback ) | ||
82 | callback.call( scope || window, allPlugins ); | ||
83 | } | ||
84 | }, this ); | ||
85 | |||
86 | }; | ||
87 | |||
88 | loadPlugins.call( this, name ); | ||
89 | }; | ||
90 | } ); | ||
91 | |||
92 | /** | ||
93 | * Loads a specific language file, or auto detect it. A callback is | ||
94 | * then called when the file gets loaded. | ||
95 | * | ||
96 | * CKEDITOR.plugins.setLang( 'myPlugin', 'en', { | ||
97 | * title: 'My plugin', | ||
98 | * selectOption: 'Please select an option' | ||
99 | * } ); | ||
100 | * | ||
101 | * @param {String} pluginName The name of the plugin to which the provided translation | ||
102 | * should be attached. | ||
103 | * @param {String} languageCode The code of the language translation provided. | ||
104 | * @param {Object} languageEntries An object that contains pairs of label and | ||
105 | * the respective translation. | ||
106 | */ | ||
107 | CKEDITOR.plugins.setLang = function( pluginName, languageCode, languageEntries ) { | ||
108 | var plugin = this.get( pluginName ), | ||
109 | pluginLangEntries = plugin.langEntries || ( plugin.langEntries = {} ), | ||
110 | pluginLang = plugin.lang || ( plugin.lang = [] ); | ||
111 | |||
112 | if ( pluginLang.split ) | ||
113 | pluginLang = pluginLang.split( ',' ); | ||
114 | |||
115 | if ( CKEDITOR.tools.indexOf( pluginLang, languageCode ) == -1 ) | ||
116 | pluginLang.push( languageCode ); | ||
117 | |||
118 | pluginLangEntries[ languageCode ] = languageEntries; | ||
119 | }; | ||