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