Mimimum syndical pour en faire un produit zope / cmf.
[ckeditor.git] / _source / core / plugins.js
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html 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 * @namespace
14 * @augments CKEDITOR.resourceManager
15 * @example
16 */
17 CKEDITOR.plugins = new CKEDITOR.resourceManager(
18 '_source/' + // @Packager.RemoveLine
19 'plugins/', 'plugin' );
20
21 // PACKAGER_RENAME( CKEDITOR.plugins )
22
23 CKEDITOR.plugins.load = CKEDITOR.tools.override( CKEDITOR.plugins.load, function( originalLoad )
24 {
25 return function( name, callback, scope )
26 {
27 var allPlugins = {};
28
29 var loadPlugins = function( names )
30 {
31 originalLoad.call( this, names, function( plugins )
32 {
33 CKEDITOR.tools.extend( allPlugins, plugins );
34
35 var requiredPlugins = [];
36 for ( var pluginName in plugins )
37 {
38 var plugin = plugins[ pluginName ],
39 requires = plugin && plugin.requires;
40
41 if ( requires )
42 {
43 for ( var i = 0 ; i < requires.length ; i++ )
44 {
45 if ( !allPlugins[ requires[ i ] ] )
46 requiredPlugins.push( requires[ i ] );
47 }
48 }
49 }
50
51 if ( requiredPlugins.length )
52 loadPlugins.call( this, requiredPlugins );
53 else
54 {
55 // Call the "onLoad" function for all plugins.
56 for ( pluginName in allPlugins )
57 {
58 plugin = allPlugins[ pluginName ];
59 if ( plugin.onLoad && !plugin.onLoad._called )
60 {
61 plugin.onLoad();
62 plugin.onLoad._called = 1;
63 }
64 }
65
66 // Call the callback.
67 if ( callback )
68 callback.call( scope || window, allPlugins );
69 }
70 }
71 , this);
72
73 };
74
75 loadPlugins.call( this, name );
76 };
77 });
78
79 /**
80 * Loads a specific language file, or auto detect it. A callback is
81 * then called when the file gets loaded.
82 * @param {String} pluginName The name of the plugin to which the provided translation
83 * should be attached.
84 * @param {String} languageCode The code of the language translation provided.
85 * @param {Object} languageEntries An object that contains pairs of label and
86 * the respective translation.
87 * @example
88 * CKEDITOR.plugins.setLang( 'myPlugin', 'en', {
89 * title : 'My plugin',
90 * selectOption : 'Please select an option'
91 * } );
92 */
93 CKEDITOR.plugins.setLang = function( pluginName, languageCode, languageEntries )
94 {
95 var plugin = this.get( pluginName ),
96 pluginLangEntries = plugin.langEntries || ( plugin.langEntries = {} ),
97 pluginLang = plugin.lang || ( plugin.lang = [] );
98
99 if ( CKEDITOR.tools.indexOf( pluginLang, languageCode ) == -1 )
100 pluginLang.push( languageCode );
101
102 pluginLangEntries[ languageCode ] = languageEntries;
103 };