src/js/main.js
branchpopcorn-port
changeset 505 b1e442d9a1bc
parent 501 63e7b66d2a80
child 511 81eb8e686456
equal deleted inserted replaced
494:cb88c0c8ddfa 505:b1e442d9a1bc
     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.type === "youtube") {
       
    21         $L = $L.script(libs["popcorn.youtube"]);
       
    22       } 
       
    23       if (config.player.type === "vimeo")
       
    24         $L = $L.script(libs["popcorn.vimeo"]);
       
    25       
       
    26       /* do nothing for html5 */
       
    27     }       
       
    28     
       
    29     /* widget specific requirements */
       
    30     for (var idx in config.gui.widgets) {
       
    31       if (config.gui.widgets[idx].type === "PolemicWidget") {        
       
    32         $L.script(libs.raphael);
       
    33       }
       
    34     }
       
    35     
       
    36     // same for modules
       
    37     /*
       
    38     for (var idx in config.modules) {
       
    39       if (config.modules[idx].type === "PolemicWidget")
       
    40         $L.script(libs.raphaelJs);
       
    41     }
       
    42     */
    13 
    43 
    14 		/* FIXME : to refactor using popcorn.getscript ? */
    44     $L.wait(function() {
    15 		/******** Load jQuery if not present *********/
    45       IriSP.jQuery = window.jQuery.noConflict( true );
    16 		if ( window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2' ) {
    46       
    17 			
    47       var css_link_jquery = IriSP.jQuery( "<link>", { 
    18 			var script_tag = document.createElement( 'script' );
    48         rel: "stylesheet", 
    19 			script_tag.setAttribute( "type", "text/javascript" );
    49         type: "text/css", 
    20 			script_tag.setAttribute( "src", libs.jQuery );
    50         href: libs.cssjQueryUI,
    21 			
    51         'class': "dynamic_css"
    22 			script_tag.onload = scriptLibHandler;
    52       } );
    23 			script_tag.onreadystatechange = function () { // Same thing but for IE
    53       var css_link_custom = IriSP.jQuery( "<link>", { 
    24 				if ( this.readyState == 'complete' || this.readyState == 'loaded' ) {
    54         rel: "stylesheet", 
    25 					scriptLibHandler();					
    55         type: "text/css", 
    26 				}
    56         href: config.gui.css,
    27 			};
    57         'class': "dynamic_css"
    28 			
    58       } );
    29 			// Try to find the head, otherwise default to the documentElement
    59       
    30 			( document.getElementsByTagName("head")[0] || document.documentElement ).appendChild( script_tag );
    60       css_link_jquery.appendTo('head');
    31 		} else {
    61       css_link_custom.appendTo('head');
    32 			// The jQuery version on the window is the one we want to use
    62           
    33 			 IriSP.jQuery = window.jQuery;
    63       IriSP.setupDataLoader();
    34 			 scriptLibHandler();
    64       IriSP.__dataloader.get(metadata_url, 
    35 		}
    65           function(data) {
    36 
    66             /* save the data so that we could re-use it to
    37 		/******** Called once jQuery has loaded ******/
    67                configure the video
    38 		function scriptLibHandler() {
    68             */
    39 			
    69             IriSP.__jsonMetadata = data;
    40 			var script_jqUi_tooltip = document.createElement( 'script' );
    70             callback.call(window) });
    41 			script_jqUi_tooltip.setAttribute( "type", "text/javascript" );
    71     });
    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 };
    72 };
   131