src/js/init.js
branchnew-model
changeset 875 43629caa77bc
parent 874 38b65761a7d5
child 881 f11b234497f7
equal deleted inserted replaced
874:38b65761a7d5 875:43629caa77bc
     3 */
     3 */
     4 
     4 
     5 /* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */
     5 /* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */
     6 
     6 
     7 IriSP.Metadataplayer = function(config, video_metadata) {
     7 IriSP.Metadataplayer = function(config, video_metadata) {
     8     IriSP._.defaults(config.gui, IriSP.guiDefaults);
     8     for (var key in IriSP.guiDefaults) {
       
     9         if (IriSP.guiDefaults.hasOwnProperty(key) && !config.gui.hasOwnProperty('key')) {
       
    10             config.gui[key] = IriSP.guiDefaults[key]
       
    11         }
       
    12     }
     9     var _container = document.getElementById(config.gui.container);
    13     var _container = document.getElementById(config.gui.container);
    10     _container.innerHTML = IriSP.templToHTML(IriSP.loading_template, config.gui);
    14     _container.innerHTML = '<div class="Ldt-Loader">Loading... Chargement...</div>';
    11     this.video_metadata = video_metadata;
    15     this.video_metadata = video_metadata;
    12     this.sourceManager = new IriSP.Model.Directory();
    16     this.sourceManager = new IriSP.Model.Directory();
    13     this.config = config;
    17     this.config = config;
    14     this.loadLibs();
    18     this.loadLibs();
    15 }
    19 }
    19 }
    23 }
    20 
    24 
    21 IriSP.Metadataplayer.prototype.loadLibs = function() {
    25 IriSP.Metadataplayer.prototype.loadLibs = function() {
    22     // Localize jQuery variable
    26     // Localize jQuery variable
    23     IriSP.jQuery = null;
    27     IriSP.jQuery = null;
    24     var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait().script(IriSP.getLib("jQueryUI"));
    28     var $L = $LAB.script(IriSP.getLib("underscore")).script(IriSP.getLib("Mustache")).script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait().script(IriSP.getLib("jQueryUI"));
    25 
    29 
    26     if(this.config.player.type === "jwplayer" || this.config.player.type === "allocine" || this.config.player.type === "dailymotion") {
    30     if(this.config.player.type === "jwplayer" || this.config.player.type === "allocine" || this.config.player.type === "dailymotion") {
    27         // load our popcorn.js lookalike
    31         // load our popcorn.js lookalike
    28         $L.script(IriSP.getLib("jwplayer"));
    32         $L.script(IriSP.getLib("jwplayer"));
    29     } else {
    33     } else {
    38         }
    42         }
    39     }
    43     }
    40 
    44 
    41     /* widget specific requirements */
    45     /* widget specific requirements */
    42     for(var _i = 0; _i < this.config.gui.widgets.length; _i++) {
    46     for(var _i = 0; _i < this.config.gui.widgets.length; _i++) {
    43         if(this.config.gui.widgets[_i].type === "StackGraphWidget" || this.config.gui.widgets[_i].type === "SparklineWidget") {
    47         if(this.config.gui.widgets[_i].type === "Sparkline") {
    44             $L.script(IriSP.getLib("raphael"));
    48             $L.script(IriSP.getLib("raphael"));
    45         }
    49         }
    46         if(this.config.gui.widgets[_i].type === "TraceWidget") {
    50         if(this.config.gui.widgets[_i].type === "TraceWidget") {
    47             $L.script(IriSP.getLib("tracemanager"))
    51             $L.script(IriSP.getLib("tracemanager"))
    48         }
    52         }
    50     
    54     
    51     var _this = this;
    55     var _this = this;
    52     
    56     
    53     $L.wait(function() {
    57     $L.wait(function() {
    54         IriSP.jQuery = window.jQuery.noConflict(true);
    58         IriSP.jQuery = window.jQuery.noConflict(true);
    55 
    59         IriSP._ = window._.noConflict();
    56         var css_link_jquery = IriSP.jQuery("<link>", {
    60         
    57             rel : "stylesheet",
    61         IriSP.loadCss(IriSP.getLib("cssjQueryUI"))
    58             type : "text/css",
    62         IriSP.loadCss(_this.config.gui.css);
    59             href : IriSP.getLib("cssjQueryUI")
       
    60         });
       
    61         var css_link_custom = IriSP.jQuery("<link>", {
       
    62             rel : "stylesheet",
       
    63             type : "text/css",
       
    64             href : _this.config.gui.css
       
    65         });
       
    66 
       
    67         css_link_jquery.appendTo('head');
       
    68         css_link_custom.appendTo('head');
       
    69         
    63         
    70         _this.onLibsLoaded();
    64         _this.onLibsLoaded();
    71         
    65         
    72     });
    66     });
    73 }
    67 }
    74 
    68 
    75 IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) {
       
    76     if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") {
       
    77         _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format];
       
    78     }
       
    79     if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") {
       
    80         _metadataInfo.url = _metadataInfo.src;
       
    81     }
       
    82     if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") {
       
    83         return this.sourceManager.remoteSource(_metadataInfo);
       
    84     } else {
       
    85         return this.sourceManager.newLocalSource(_metadataInfo);
       
    86     }
       
    87 }
       
    88 
       
    89 IriSP.Metadataplayer.prototype.onLibsLoaded = function() {
    69 IriSP.Metadataplayer.prototype.onLibsLoaded = function() {
       
    70     console.log('OnLibsLoaded');
    90     this.videoData = this.loadMetadata(this.video_metadata);
    71     this.videoData = this.loadMetadata(this.video_metadata);
    91     this.$ = IriSP.jQuery('#' + this.config.gui.container);
    72     this.$ = IriSP.jQuery('#' + this.config.gui.container);
    92     this.$.css({
    73     this.$.css({
    93         "width": this.config.gui.width,
    74         "width": this.config.gui.width,
    94         "clear": "both"
    75         "clear": "both"
    99       
    80       
   100     var _this = this;
    81     var _this = this;
   101     this.videoData.onLoad(function() {
    82     this.videoData.onLoad(function() {
   102         _this.onVideoDataLoaded();
    83         _this.onVideoDataLoaded();
   103     });
    84     });
       
    85 }
       
    86 
       
    87 IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) {
       
    88     if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") {
       
    89         _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format];
       
    90     }
       
    91     if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") {
       
    92         _metadataInfo.url = _metadataInfo.src;
       
    93     }
       
    94     if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") {
       
    95         return this.sourceManager.remoteSource(_metadataInfo);
       
    96     } else {
       
    97         return this.sourceManager.newLocalSource(_metadataInfo);
       
    98     }
   104 }
    99 }
   105 
   100 
   106 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
   101 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
   107     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   102     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   108         var _media = this.videoData.currentMedia;
   103         var _media = this.videoData.currentMedia;
   115         }
   110         }
   116         
   111         
   117     }
   112     }
   118     this.configurePopcorn();
   113     this.configurePopcorn();
   119     this.widgets = [];
   114     this.widgets = [];
       
   115     var _this = this;
   120     for(var i = 0; i < this.config.gui.widgets.length; i++) {
   116     for(var i = 0; i < this.config.gui.widgets.length; i++) {
   121         var _widget = this.config.gui.widgets[i];
   117         this.loadWidget(this.config.gui.widgets[i], function(_widget) {
   122         if (typeof IriSP[_widget.type] !== "undefined") {
   118             _this.widgets.push(_widget)
   123             this.widgets.push(new IriSP[_widget.type](this, _widget));
   119         });
   124         } else {
       
   125             console.log("Error, Call to Undefined Widget Type : "+_widget.type);
       
   126         }
       
   127     };
   120     };
   128     this.$.find('.Ldt-loader').detach();
   121     this.$.find('.Ldt-Loader').detach();
       
   122 }
       
   123 
       
   124 IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) {
       
   125     /* Creating containers if needed */
       
   126     if (typeof _widgetConfig.container === "undefined") {
       
   127         var _divs = this.layoutDivs(_widgetConfig.type);
       
   128         _widgetConfig.container = _divs[0];
       
   129     }
       
   130     
       
   131     var _this = this;
       
   132     
       
   133     if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") {
       
   134         IriSP._.defer(function() {
       
   135             _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
       
   136         });
       
   137     } else {
       
   138         /* Loading Widget CSS   */
       
   139         IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css');
       
   140         /* Loading Widget JS    */
       
   141         $LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() {
       
   142             _callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig));
       
   143         });
       
   144     }
   129 }
   145 }
   130 
   146 
   131 IriSP.Metadataplayer.prototype.configurePopcorn = function() {
   147 IriSP.Metadataplayer.prototype.configurePopcorn = function() {
   132     var pop,
   148     var pop,
   133         ret = this.layoutDivs("video"),
   149         ret = this.layoutDivs("video"),