src/js/main.js
branchlab-port
changeset 498 cf2a0505cadc
parent 453 8568e47379a2
child 501 63e7b66d2a80
equal deleted inserted replaced
497:f671cbaae9db 498:cf2a0505cadc
     3 if ( window.IriSP === undefined && window.__IriSP === undefined ) { 
     3 if ( window.IriSP === undefined && window.__IriSP === undefined ) { 
     4 	var IriSP = {}; 
     4 	var IriSP = {}; 
     5 	var __IriSP = IriSP; /* for backward compatibility */
     5 	var __IriSP = IriSP; /* for backward compatibility */
     6 }
     6 }
     7 
     7 
     8 /* crap code will be the first against the wall when the
     8 IriSP.loadLibs = function( libs, config, metadata_url, callback ) {
     9    revolution comes */
     9     // Localize jQuery variable
    10 IriSP.loadLibs = function( libs, customCssPath, metadata_url, callback ) {
       
    11 		// Localize jQuery variable
       
    12 		IriSP.jQuery = null;
    10 		IriSP.jQuery = null;
       
    11     var $L = $LAB.script(libs.jQuery).script(libs.swfObject)
       
    12                 .script(libs.jQueryUI)
       
    13                                    
       
    14     if (config.player.type === "jwplayer") {
       
    15       // load our popcorn.js lookalike
       
    16       $L = $L.script(libs.jwplayer);
       
    17     } else {
       
    18       // load the real popcorn
       
    19       $L = $L.script(libs.popcorn).script(libs["popcorn.code"]);
       
    20       if (config.player === "youtube")
       
    21         $L = $L.script(libs["popcorn.youtube"]);
       
    22       if (config.player === "vimeo")
       
    23         $L = $L.script(libs["popcorn.vimeo"]);
       
    24       
       
    25       /* do nothing for html5 */
       
    26     }       
       
    27     
       
    28     /* widget specific requirements */
       
    29     for (var idx in config.gui.widgets) {
       
    30       if (config.gui.widgets[idx].type === "PolemicWidget") {        
       
    31         $L.script(libs.raphael);
       
    32       }
       
    33     }
       
    34     
       
    35     // same for modules
       
    36     /*
       
    37     for (var idx in config.modules) {
       
    38       if (config.modules[idx].type === "PolemicWidget")
       
    39         $L.script(libs.raphaelJs);
       
    40     }
       
    41     */
    13 
    42 
    14 		/* FIXME : to refactor using popcorn.getscript ? */
    43     $L.wait(function() {
    15 		/******** Load jQuery if not present *********/
    44       IriSP.jQuery = window.jQuery.noConflict( true );
    16 		if ( window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2' ) {
    45       
    17 			
    46       var css_link_jquery = IriSP.jQuery( "<link>", { 
    18 			var script_tag = document.createElement( 'script' );
    47         rel: "stylesheet", 
    19 			script_tag.setAttribute( "type", "text/javascript" );
    48         type: "text/css", 
    20 			script_tag.setAttribute( "src", libs.jQuery );
    49         href: libs.cssjQueryUI,
    21 			
    50         'class': "dynamic_css"
    22 			script_tag.onload = scriptLibHandler;
    51       } );
    23 			script_tag.onreadystatechange = function () { // Same thing but for IE
    52       var css_link_custom = IriSP.jQuery( "<link>", { 
    24 				if ( this.readyState == 'complete' || this.readyState == 'loaded' ) {
    53         rel: "stylesheet", 
    25 					scriptLibHandler();					
    54         type: "text/css", 
    26 				}
    55         href: config.gui.css,
    27 			};
    56         'class': "dynamic_css"
    28 			
    57       } );
    29 			// Try to find the head, otherwise default to the documentElement
    58       
    30 			( document.getElementsByTagName("head")[0] || document.documentElement ).appendChild( script_tag );
    59       css_link_jquery.appendTo('head');
    31 		} else {
    60       css_link_custom.appendTo('head');
    32 			// The jQuery version on the window is the one we want to use
    61           
    33 			 IriSP.jQuery = window.jQuery;
    62       IriSP.setupDataLoader();
    34 			 scriptLibHandler();
    63       IriSP.__dataloader.get(metadata_url, 
    35 		}
    64           function(data) {
    36 
    65             /* save the data so that we could re-use it to
    37 		/******** Called once jQuery has loaded ******/
    66                configure the video
    38 		function scriptLibHandler() {
    67             */
    39 			
    68             IriSP.__jsonMetadata = data;
    40 			var script_jqUi_tooltip = document.createElement( 'script' );
    69             callback.call(window) });
    41 			script_jqUi_tooltip.setAttribute( "type", "text/javascript" );
    70     });
    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         IriSP.setupDataLoader();
       
   121         IriSP.__dataloader.get(metadata_url, 
       
   122             function(data) {
       
   123               /* save the data so that we could re-use it to
       
   124                  configure the video
       
   125               */
       
   126               IriSP.__jsonMetadata = data;
       
   127               callback.call(window) });
       
   128       });
       
   129     }
       
   130 };
    71 };
   131