1 /*
  2  * CKEditor - The text editor for Internet - http://ckeditor.com
  3  * Copyright (C) 2003-2008 Frederico Caldeira Knabben
  4  *
  5  * == BEGIN LICENSE ==
  6  *
  7  * Licensed under the terms of any of the following licenses at your
  8  * choice:
  9  *
 10  *  - GNU General Public License Version 2 or later (the "GPL")
 11  *    http://www.gnu.org/licenses/gpl.html
 12  *
 13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 14  *    http://www.gnu.org/licenses/lgpl.html
 15  *
 16  *  - Mozilla Public License Version 1.1 or later (the "MPL")
 17  *    http://www.mozilla.org/MPL/MPL-1.1.html
 18  *
 19  * == END LICENSE ==
 20  */
 21 
 22 /**
 23  * Load scripts asynchronously.
 24  * @namespace
 25  * @example
 26  */
 27 CKEDITOR.scriptLoader = (function()
 28 {
 29 	var uniqueScripts = {};
 30 
 31 	return /** @lends CKEDITOR.scriptLoader */ {
 32 		load : function( scriptUrl, callback, scope, noCheck )
 33 		{
 34 			if ( noCheck !== true )
 35 			{
 36 				if ( uniqueScripts[ scriptUrl ] )
 37 					return false;
 38 
 39 				uniqueScripts[ scriptUrl ] = true;
 40 			}
 41 
 42 			// Create the <script> element.
 43 			var script = new CKEDITOR.dom.element( 'script' );
 44 			script.setAttributes( {
 45 				type : 'text/javascript',
 46 				src : scriptUrl } );
 47 
 48 			if ( callback )
 49 			{
 50 				if ( CKEDITOR.env.ie )
 51 				{
 52 					script.$.onreadystatechange = function ()
 53 					{
 54 						if ( script.$.readyState == 'loaded' || script.$.readyState == 'complete' )
 55 							callback.call( scope || CKEDITOR );
 56 					}
 57 				}
 58 				else
 59 				{
 60 					script.$.onload = function()
 61 					{
 62 						callback.call( scope || CKEDITOR );
 63 					}
 64 				}
 65 			}
 66 
 67 			// Append it to <head>.
 68 			script.appendTo( CKEDITOR.dom.element.getHead() );
 69 
 70 			return true;
 71 		},
 72 
 73 		loadCode : function( code )
 74 		{
 75 			// Create the <script> element.
 76 			var script = new CKEDITOR.dom.element( 'script' );
 77 			script.setAttribute( 'type', 'text/javascript' );
 78 
 79 			if ( CKEDITOR.env.ie )
 80 				script.setText( code );
 81 			else
 82 				script.appendText( code );
 83 
 84 			// Append it to <head>.
 85 			script.appendTo( CKEDITOR.dom.element.getHead() );
 86 		}
 87 	};
 88 })();
 89