src/js/main.js
changeset 945 7d9f6fd6f904
parent 944 8a6c9e3d0158
child 947 ec4e9ddf9fba
equal deleted inserted replaced
944:8a6c9e3d0158 945:7d9f6fd6f904
     1 /* main file */
       
     2 // Why is it called main ? It only loads the libs !
       
     3 
       
     4 if ( window.IriSP === undefined && window.__IriSP === undefined ) { 
       
     5   /**
       
     6     @class
       
     7     the object under which everything goes.        
       
     8   */
       
     9 	IriSP = {}; 
       
    10   
       
    11   /** Alias to IriSP for backward compatibility */
       
    12 	__IriSP = IriSP;
       
    13 }
       
    14 
       
    15 /* underscore comes bundled with the player and we need 
       
    16    it ASAP, so load it that way
       
    17 */
       
    18 
       
    19 IriSP._ = window._.noConflict();
       
    20 IriSP.underscore = IriSP._;
       
    21 
       
    22 IriSP.getLib = function(lib) {
       
    23     return (
       
    24         IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string"
       
    25         ? IriSP.libFiles.cdn[lib]
       
    26         : (
       
    27             typeof IriSP.libFiles.locations[lib] == "string"
       
    28             ? IriSP.libFiles.locations[lib]
       
    29             : (
       
    30                 typeof IriSP.libFiles.inDefaultDir[lib] == "string"
       
    31                 ? IriSP.libFiles.defaultDir + IriSP.libFiles.inDefaultDir[lib]
       
    32                 : null
       
    33             )
       
    34         )
       
    35     )
       
    36 }
       
    37 
       
    38 IriSP._cssCache = [];
       
    39 
       
    40 IriSP.loadCss = function(_cssFile) {
       
    41     if (typeof _cssFile === "string" && _cssFile && IriSP._(IriSP._cssCache).indexOf(_cssFile) === -1) {
       
    42         IriSP.jQuery("<link>", {
       
    43             rel : "stylesheet",
       
    44             type : "text/css",
       
    45             href : _cssFile
       
    46         }).appendTo('head');
       
    47         IriSP._cssCache.push(_cssFile);
       
    48     }
       
    49 }
       
    50 
       
    51 IriSP.loadLibs = function( config, metadata_url, callback ) {
       
    52     var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait()
       
    53                 .script(IriSP.getLib("jQueryUI"));
       
    54                                    
       
    55     if (config.player.type === "jwplayer" || config.player.type === "allocine") {
       
    56       // load our popcorn.js lookalike
       
    57       $L.script(IriSP.getLib("jwplayer"));
       
    58     } else {
       
    59       // load the real popcorn
       
    60       $L.script(IriSP.getLib("popcorn")).script(IriSP.getLib("popcorn.code"));
       
    61       if (config.player.type === "youtube") {
       
    62         $L.script(IriSP.getLib("popcorn.youtube"));
       
    63       } 
       
    64       if (config.player.type === "vimeo")
       
    65         $L.script(IriSP.getLib("popcorn.vimeo"));
       
    66       
       
    67       /* do nothing for html5 */
       
    68     }       
       
    69     
       
    70     /* widget specific requirements */
       
    71     for (var idx in config.gui.widgets) {
       
    72       if (config.gui.widgets[idx].type === "PolemicWidget" ||
       
    73           config.gui.widgets[idx].type === "StackGraphWidget" ||
       
    74           config.gui.widgets[idx].type === "SparklineWidget") {        
       
    75         $L.script(IriSP.getLib("raphael"));
       
    76       }
       
    77     }
       
    78     
       
    79     // same for modules
       
    80     /*
       
    81     for (var idx in config.modules) {
       
    82       if (config.modules[idx].type === "PolemicWidget")
       
    83         $L.script(IriSP.getLib("raphaelJs"));
       
    84     }
       
    85     */
       
    86     $L.wait(function() {
       
    87         if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") {
       
    88             IriSP.jQuery = window.jQuery.noConflict();
       
    89         }
       
    90         IriSP.loadCss(IriSP.getLib("cssjQueryUI"));
       
    91         IriSP.loadCss(config.gui.css);
       
    92           
       
    93       IriSP.setupDataLoader();
       
    94       IriSP.__dataloader.get(metadata_url, 
       
    95           function(data) {
       
    96             /* save the data so that we could re-use it to
       
    97                configure the video
       
    98             */
       
    99             IriSP.__jsonMetadata = data;
       
   100             callback.call(window) });
       
   101     });
       
   102 };