-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
plugins.js
132 lines (112 loc) · 3.87 KB
/
plugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @fileOverview Defines the {@link CKEDITOR.plugins} object, which is used to
* manage plugins registration and loading.
*/
/**
* Manages plugins registration and loading.
*
* @class
* @extends CKEDITOR.resourceManager
* @singleton
*/
CKEDITOR.plugins = new CKEDITOR.resourceManager( 'plugins/', 'plugin' );
// PACKAGER_RENAME( CKEDITOR.plugins )
CKEDITOR.plugins.load = CKEDITOR.tools.override( CKEDITOR.plugins.load, function( originalLoad ) {
var initialized = {};
return function( name, callback, scope ) {
var allPlugins = {};
var loadPlugins = function( names ) {
originalLoad.call( this, names, function( plugins ) {
CKEDITOR.tools.extend( allPlugins, plugins );
var requiredPlugins = [];
for ( var pluginName in plugins ) {
var plugin = plugins[ pluginName ],
requires = plugin && plugin.requires;
if ( !initialized[ pluginName ] ) {
// Register all icons eventually defined by this plugin.
if ( plugin.icons ) {
var icons = plugin.icons.split( ',' );
for ( var ic = icons.length; ic--; ) {
CKEDITOR.skin.addIcon( icons[ ic ],
plugin.path +
'icons/' +
( CKEDITOR.env.hidpi && plugin.hidpi ? 'hidpi/' : '' ) +
icons[ ic ] +
'.png' );
}
}
initialized[ pluginName ] = 1;
}
if ( requires ) {
// Trasnform it into an array, if it's not one.
if ( requires.split )
requires = requires.split( ',' );
for ( var i = 0; i < requires.length; i++ ) {
if ( !allPlugins[ requires[ i ] ] )
requiredPlugins.push( requires[ i ] );
}
}
}
if ( requiredPlugins.length )
loadPlugins.call( this, requiredPlugins );
else {
// Call the "onLoad" function for all plugins.
for ( pluginName in allPlugins ) {
plugin = allPlugins[ pluginName ];
if ( plugin.onLoad && !plugin.onLoad._called ) {
// Make it possible to return false from plugin::onLoad to disable it.
if ( plugin.onLoad() === false )
delete allPlugins[ pluginName ];
plugin.onLoad._called = 1;
}
}
// Call the callback.
if ( callback )
callback.call( scope || window, allPlugins );
}
}, this );
};
loadPlugins.call( this, name );
};
} );
/**
* Loads a specific language file, or auto detect it. A callback is
* then called when the file gets loaded.
*
* CKEDITOR.plugins.setLang( 'myPlugin', 'en', {
* title: 'My plugin',
* selectOption: 'Please select an option'
* } );
*
* @param {String} pluginName The name of the plugin to which the provided translation
* should be attached.
* @param {String} languageCode The code of the language translation provided.
* @param {Object} languageEntries An object that contains pairs of label and
* the respective translation.
*/
CKEDITOR.plugins.setLang = function( pluginName, languageCode, languageEntries ) {
var plugin = this.get( pluginName ),
pluginLangEntries = plugin.langEntries || ( plugin.langEntries = {} ),
pluginLang = plugin.lang || ( plugin.lang = [] );
if ( pluginLang.split )
pluginLang = pluginLang.split( ',' );
if ( CKEDITOR.tools.indexOf( pluginLang, languageCode ) == -1 )
pluginLang.push( languageCode );
pluginLangEntries[ languageCode ] = languageEntries;
};
/**
* Virtual class that illustrates the API of {@link CKEDITOR.editor} instance plugins dictionary.
*
* Such object contains references to all plugins used by a related editor instance.
*
* See {@link CKEDITOR.editor#property-plugins} for example use.
*
* This class is not really a part of the API, so its constructor can not be called.
*
* @abstract
* @class CKEDITOR.editor.plugins
*/