      1 ﻿/*
      2 Copyright (c) 2003-2009, 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(
     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 CKEDITOR.plugins.setLang = function( pluginName, languageCode, languageEntries )
     80 {
     81 	var plugin = this.get( pluginName );
     82 	plugin.lang[ languageCode ] = languageEntries;
     83 };
     84