| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* 2 Copyright (c) 2003-2010, 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.skins} object, which is used to 8 * manage skins loading. 9 */ 10 11 /** 12 * Manages skins loading. 13 * @namespace 14 * @example 15 */ 16 CKEDITOR.skins = (function() 17 { 18 // Holds the list of loaded skins. 19 var loaded = {}; 20 var preloaded = {}; 21 var paths = {}; 22 23 var loadPart = function( editor, skinName, part, callback ) 24 { 25 // Get the skin definition. 26 var skinDefinition = loaded[ skinName ]; 27 28 if ( !editor.skin ) 29 { 30 editor.skin = skinDefinition; 31 32 // Trigger init function if any. 33 if ( skinDefinition.init ) 34 skinDefinition.init( editor ); 35 } 36 37 var appendSkinPath = function( fileNames ) 38 { 39 for ( var n = 0 ; n < fileNames.length ; n++ ) 40 { 41 fileNames[ n ] = CKEDITOR.getUrl( paths[ skinName ] + fileNames[ n ] ); 42 } 43 }; 44 45 function fixCSSTextRelativePath( cssStyleText, baseUrl ) 46 { 47 return cssStyleText.replace( /url\s*\(([\s'"]*)(.*?)([\s"']*)\)/g, 48 function( match, opener, path, closer ) 49 { 50 if ( /^\/|^\w?:/.test( path ) ) 51 return match; 52 else 53 return 'url(' + baseUrl + opener + path + closer + ')'; 54 } ); 55 } 56 57 // Check if we need to preload images from it. 58 if ( !preloaded[ skinName ] ) 59 { 60 var preload = skinDefinition.preload; 61 if ( preload && preload.length > 0 ) 62 { 63 appendSkinPath( preload ); 64 CKEDITOR.imageCacher.load( preload, function() 65 { 66 preloaded[ skinName ] = 1; 67 loadPart( editor, skinName, part, callback ); 68 } ); 69 return; 70 } 71 72 // Mark it as preloaded. 73 preloaded[ skinName ] = 1; 74 } 75 76 // Get the part definition. 77 part = skinDefinition[ part ]; 78 var partIsLoaded = !part || !!part._isLoaded; 79 80 // Call the callback immediately if already loaded. 81 if ( partIsLoaded ) 82 callback && callback(); 83 else 84 { 85 // Put the callback in a queue. 86 var pending = part._pending || ( part._pending = [] ); 87 pending.push( callback ); 88 89 // We may have more than one skin part load request. Just the first 90 // one must do the loading job. 91 if ( pending.length > 1 ) 92 return; 93 94 // Check whether the "css" and "js" properties have been defined 95 // for that part. 96 var cssIsLoaded = !part.css || !part.css.length; 97 var jsIsLoaded = !part.js || !part.js.length; 98 99 // This is the function that will trigger the callback calls on 100 // load. 101 var checkIsLoaded = function() 102 { 103 if ( cssIsLoaded && jsIsLoaded ) 104 { 105 // Mark the part as loaded. 106 part._isLoaded = 1; 107 108 // Call all pending callbacks. 109 for ( var i = 0 ; i < pending.length ; i++ ) 110 { 111 if ( pending[ i ] ) 112 pending[ i ](); 113 } 114 } 115 }; 116 117 // Load the "css" pieces. 118 if ( !cssIsLoaded ) 119 { 120 var cssPart = part.css; 121 122 if ( CKEDITOR.tools.isArray( cssPart ) ) 123 { 124 appendSkinPath( cssPart ); 125 for ( var c = 0 ; c < cssPart.length ; c++ ) 126 CKEDITOR.document.appendStyleSheet( cssPart[ c ] ); 127 } 128 else 129 { 130 cssPart = fixCSSTextRelativePath( 131 cssPart, CKEDITOR.getUrl( paths[ skinName ] ) ); 132 // Processing Inline CSS part. 133 CKEDITOR.document.appendStyleText( cssPart ); 134 } 135 136 part.css = cssPart; 137 138 cssIsLoaded = 1; 139 } 140 141 // Load the "js" pieces. 142 if ( !jsIsLoaded ) 143 { 144 appendSkinPath( part.js ); 145 CKEDITOR.scriptLoader.load( part.js, function() 146 { 147 jsIsLoaded = 1; 148 checkIsLoaded(); 149 }); 150 } 151 152 // We may have nothing to load, so check it immediately. 153 checkIsLoaded(); 154 } 155 }; 156 157 return /** @lends CKEDITOR.skins */ { 158 159 /** 160 * Registers a skin definition. 161 * @param {String} skinName The skin name. 162 * @param {Object} skinDefinition The skin definition. 163 * @example 164 */ 165 add : function( skinName, skinDefinition ) 166 { 167 loaded[ skinName ] = skinDefinition; 168 169 skinDefinition.skinPath = paths[ skinName ] 170 || ( paths[ skinName ] = 171 CKEDITOR.getUrl( 172 '_source/' + // @Packager.RemoveLine 173 'skins/' + skinName + '/' ) ); 174 }, 175 176 /** 177 * Loads a skin part. Skins are defined in parts, which are basically 178 * separated CSS files. This function is mainly used by the core code and 179 * should not have much use out of it. 180 * @param {String} skinName The name of the skin to be loaded. 181 * @param {String} skinPart The skin part to be loaded. Common skin parts 182 * are "editor" and "dialog". 183 * @param {Function} [callback] A function to be called once the skin 184 * part files are loaded. 185 * @example 186 */ 187 load : function( editor, skinPart, callback ) 188 { 189 var skinName = editor.skinName, 190 skinPath = editor.skinPath; 191 192 if ( loaded[ skinName ] ) 193 loadPart( editor, skinName, skinPart, callback ); 194 else 195 { 196 paths[ skinName ] = skinPath; 197 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( skinPath + 'skin.js' ), function() 198 { 199 loadPart( editor, skinName, skinPart, callback ); 200 }); 201 } 202 } 203 }; 204 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |