2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview Defines the {@link CKEDITOR.skins} object, which is used to
\r
8 * manage skins loading.
\r
12 * Manages skins loading.
\r
16 CKEDITOR.skins = (function()
\r
18 // Holds the list of loaded skins.
\r
23 var loadedPart = function( skinName, part, callback )
\r
25 // Get the skin definition.
\r
26 var skinDefinition = loaded[ skinName ];
\r
28 var appendSkinPath = function( fileNames )
\r
30 for ( var n = 0 ; n < fileNames.length ; n++ )
\r
32 fileNames[ n ] = CKEDITOR.getUrl( paths[ skinName ] + fileNames[ n ] );
\r
36 // Check if we need to preload images from it.
\r
37 if ( !preloaded[ skinName ] )
\r
39 var preload = skinDefinition.preload;
\r
40 if ( preload && preload.length > 0 )
\r
42 appendSkinPath( preload );
\r
43 CKEDITOR.imageCacher.load( preload, function()
\r
45 preloaded[ skinName ] = 1;
\r
46 loadedPart( skinName, part, callback );
\r
51 // Mark it as preloaded.
\r
52 preloaded[ skinName ] = 1;
\r
55 // Get the part definition.
\r
56 part = skinDefinition[ part ];
\r
57 var partIsLoaded = !part || !!part._isLoaded;
\r
59 // Call the callback immediately if already loaded.
\r
61 callback && callback();
\r
64 // Put the callback in a queue.
\r
65 var pending = part._pending || ( part._pending = [] );
\r
66 pending.push( callback );
\r
68 // We may have more than one skin part load request. Just the first
\r
69 // one must do the loading job.
\r
70 if ( pending.length > 1 )
\r
73 // Check whether the "css" and "js" properties have been defined
\r
75 var cssIsLoaded = !part.css || !part.css.length;
\r
76 var jsIsLoaded = !part.js || !part.js.length;
\r
78 // This is the function that will trigger the callback calls on
\r
80 var checkIsLoaded = function()
\r
82 if ( cssIsLoaded && jsIsLoaded )
\r
84 // Mark the part as loaded.
\r
87 // Call all pending callbacks.
\r
88 for ( var i = 0 ; i < pending.length ; i++ )
\r
96 // Load the "css" pieces.
\r
99 appendSkinPath( part.css );
\r
101 for ( var c = 0 ; c < part.css.length ; c++ )
\r
102 CKEDITOR.document.appendStyleSheet( part.css[ c ] );
\r
107 // Load the "js" pieces.
\r
110 appendSkinPath( part.js );
\r
111 CKEDITOR.scriptLoader.load( part.js, function()
\r
118 // We may have nothing to load, so check it immediately.
\r
123 return /** @lends CKEDITOR.skins */ {
\r
126 * Registers a skin definition.
\r
127 * @param {String} skinName The skin name.
\r
128 * @param {Object} skinDefinition The skin definition.
\r
131 add : function( skinName, skinDefinition )
\r
133 loaded[ skinName ] = skinDefinition;
\r
135 skinDefinition.skinPath = paths[ skinName ]
\r
136 || ( paths[ skinName ] =
\r
138 '_source/' + // @Packager.RemoveLine
\r
139 'skins/' + skinName + '/' ) );
\r
143 * Loads a skin part. Skins are defined in parts, which are basically
\r
144 * separated CSS files. This function is mainly used by the core code and
\r
145 * should not have much use out of it.
\r
146 * @param {String} skinName The name of the skin to be loaded.
\r
147 * @param {String} skinPart The skin part to be loaded. Common skin parts
\r
148 * are "editor" and "dialog".
\r
149 * @param {Function} [callback] A function to be called once the skin
\r
150 * part files are loaded.
\r
153 load : function( editor, skinPart, callback )
\r
155 var skinName = editor.skinName,
\r
156 skinPath = editor.skinPath;
\r
158 if ( loaded[ skinName ] )
\r
160 loadedPart( skinName, skinPart, callback );
\r
162 // Get the skin definition.
\r
163 var skinDefinition = loaded[ skinName ];
\r
165 // Trigger init function if any.
\r
166 if ( skinDefinition.init )
\r
167 skinDefinition.init( editor );
\r
171 paths[ skinName ] = skinPath;
\r
172 CKEDITOR.scriptLoader.load( skinPath + 'skin.js', function()
\r
174 loadedPart( skinName, skinPart, callback );
\r
176 // Get the skin definition.
\r
177 var skinDefinition = loaded[ skinName ];
\r
179 // Trigger init function if any.
\r
180 if ( skinDefinition.init )
\r
181 skinDefinition.init( editor );
\r