src/js/main.js
branchpopcorn-port
changeset 358 430c1a7a09de
child 453 8568e47379a2
equal deleted inserted replaced
357:6edf399cfa26 358:430c1a7a09de
       
     1 /* main file */
       
     2 
       
     3 if ( window.IriSP === undefined && window.__IriSP === undefined ) { 
       
     4 	var IriSP = {}; 
       
     5 	var __IriSP = IriSP; /* for backward compatibility */
       
     6 }
       
     7 
       
     8 /* crap code will be the first against the wall when the
       
     9    revolution comes */
       
    10 IriSP.loadLibs = function( libs, customCssPath, callback ) {
       
    11 		// Localize jQuery variable
       
    12 		IriSP.jQuery = null;
       
    13 
       
    14 		/* FIXME : to refactor using popcorn.getscript ? */
       
    15 		/******** Load jQuery if not present *********/
       
    16 		if ( window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2' ) {
       
    17 			
       
    18 			var script_tag = document.createElement( 'script' );
       
    19 			script_tag.setAttribute( "type", "text/javascript" );
       
    20 			script_tag.setAttribute( "src", libs.jQuery );
       
    21 			
       
    22 			script_tag.onload = scriptLibHandler;
       
    23 			script_tag.onreadystatechange = function () { // Same thing but for IE
       
    24 				if ( this.readyState == 'complete' || this.readyState == 'loaded' ) {
       
    25 					scriptLibHandler();					
       
    26 				}
       
    27 			};
       
    28 			
       
    29 			// Try to find the head, otherwise default to the documentElement
       
    30 			( document.getElementsByTagName("head")[0] || document.documentElement ).appendChild( script_tag );
       
    31 		} else {
       
    32 			// The jQuery version on the window is the one we want to use
       
    33 			 IriSP.jQuery = window.jQuery;
       
    34 			 scriptLibHandler();
       
    35 		}
       
    36 
       
    37 		/******** Called once jQuery has loaded ******/
       
    38 		function scriptLibHandler() {
       
    39 			
       
    40 			var script_jqUi_tooltip = document.createElement( 'script' );
       
    41 			script_jqUi_tooltip.setAttribute( "type", "text/javascript" );
       
    42 			script_jqUi_tooltip.setAttribute( "src", libs.jQueryToolTip );
       
    43 			script_jqUi_tooltip.onload = scriptLoadHandler;
       
    44 			script_jqUi_tooltip.onreadystatechange = function () { // Same thing but for IE
       
    45 				if ( this.readyState == 'complete' || this.readyState == 'loaded' ) {
       
    46 					scriptLoadHandler( "jquery.tools.min.js loded" );
       
    47 				}
       
    48 			};
       
    49 			
       
    50 			var script_swfObj = document.createElement('script');
       
    51 			script_swfObj.setAttribute( "type","text/javascript" );
       
    52 			script_swfObj.setAttribute( "src",libs.swfObject );
       
    53 			script_swfObj.onload = scriptLoadHandler;
       
    54 			script_swfObj.onreadystatechange = function () { // Same thing but for IE
       
    55 				if ( this.readyState == 'complete' || this.readyState == 'loaded' ) {
       
    56 					scriptLoadHandler( "swfobject.js loded" );
       
    57 				}
       
    58 			};
       
    59 		
       
    60 			var script_jqUi = document.createElement( 'script' );
       
    61 			script_jqUi.setAttribute( "type","text/javascript" );
       
    62 			script_jqUi.setAttribute( "src",libs.jQueryUI );
       
    63 			script_jqUi.onload = scriptLoadHandler;
       
    64 			script_jqUi.onreadystatechange = function () { // Same thing but for IE
       
    65 				if ( this.readyState == 'complete' || this.readyState == 'loaded' ) {
       
    66 					scriptLoadHandler( "jquery-ui.min.js loded" );
       
    67 				}
       
    68 			};
       
    69 		
       
    70 
       
    71 			( document.getElementsByTagName("head")[0] || document.documentElement ).appendChild( script_jqUi_tooltip);
       
    72 			( document.getElementsByTagName("head")[0] || document.documentElement ).appendChild( script_jqUi );
       
    73 			( document.getElementsByTagName("head")[0] || document.documentElement ).appendChild( script_swfObj );
       
    74 			
       
    75 
       
    76 		};
       
    77 
       
    78 		/******** Called once all lib are loaded ******/
       
    79 		var loadLib = 0;
       
    80 		/* FIXME : ugly */
       
    81 		function scriptLoadHandler( Mylib ) {
       
    82 			//alert(Mylib);
       
    83 			loadLib +=1;
       
    84 			if( loadLib===3 ) { 
       
    85 				main(); 			  
       
    86 			}
       
    87 		};
       
    88 
       
    89 		/******** Our main function ********/
       
    90 		function main() { 
       
    91 			
       
    92 
       
    93 			//  Make our own IriSP.jQuery and restore window.jQuery if there was one. 
       
    94 			IriSP.jQuery = window.jQuery.noConflict( true );
       
    95 			// Call our Jquery
       
    96 			IriSP.jQuery( document ).ready( function($) { 
       
    97 				
       
    98 				/******* Load CSS *******/
       
    99 				var css_link_jquery = IriSP.jQuery( "<link>", { 
       
   100 					rel: "stylesheet", 
       
   101 					type: "text/css", 
       
   102 					href: libs.cssjQueryUI,
       
   103 					'class': "dynamic_css"
       
   104 				} );
       
   105 				var css_link_custom = IriSP.jQuery( "<link>", { 
       
   106 					rel: "stylesheet", 
       
   107 					type: "text/css", 
       
   108 					href: customCssPath,
       
   109 					'class': "dynamic_css"
       
   110 				} );
       
   111 				
       
   112 				css_link_jquery.appendTo( 'head' );
       
   113 				css_link_custom.appendTo( 'head' );   
       
   114 
       
   115 				// to see dynamicly loaded css on IE
       
   116 				if ( $.browser.msie ) {
       
   117 					$( '.dynamic_css' ).clone().appendTo( 'head' );
       
   118 				}
       
   119         
       
   120         callback();
       
   121       });
       
   122     }
       
   123 };
       
   124