src/js/init.js
branchnew-model
changeset 870 2c025db10a10
parent 868 a525cc2214e7
child 874 38b65761a7d5
equal deleted inserted replaced
868:a525cc2214e7 870:2c025db10a10
    17 IriSP.Metadataplayer.prototype.toString = function() {
    17 IriSP.Metadataplayer.prototype.toString = function() {
    18     return 'A Metadataplayer in DIV #' + this.config.gui.container;
    18     return 'A Metadataplayer in DIV #' + this.config.gui.container;
    19 }
    19 }
    20 
    20 
    21 IriSP.Metadataplayer.prototype.loadLibs = function() {
    21 IriSP.Metadataplayer.prototype.loadLibs = function() {
    22     console.log("Loading Libs");
       
    23     // Localize jQuery variable
    22     // Localize jQuery variable
    24     IriSP.jQuery = null;
    23     IriSP.jQuery = null;
    25     var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait().script(IriSP.getLib("jQueryUI"));
    24     var $L = $LAB.script(IriSP.getLib("jQuery")).script(IriSP.getLib("swfObject")).wait().script(IriSP.getLib("jQueryUI"));
    26 
    25 
    27     if(this.config.player.type === "jwplayer" || this.config.player.type === "allocine" || this.config.player.type === "dailymotion") {
    26     if(this.config.player.type === "jwplayer" || this.config.player.type === "allocine" || this.config.player.type === "dailymotion") {
    50     }
    49     }
    51     
    50     
    52     var _this = this;
    51     var _this = this;
    53     
    52     
    54     $L.wait(function() {
    53     $L.wait(function() {
    55         console.log("jQuery is loaded");
       
    56         IriSP.jQuery = window.jQuery.noConflict(true);
    54         IriSP.jQuery = window.jQuery.noConflict(true);
    57 
    55 
    58         var css_link_jquery = IriSP.jQuery("<link>", {
    56         var css_link_jquery = IriSP.jQuery("<link>", {
    59             rel : "stylesheet",
    57             rel : "stylesheet",
    60             type : "text/css",
    58             type : "text/css",
    63         var css_link_custom = IriSP.jQuery("<link>", {
    61         var css_link_custom = IriSP.jQuery("<link>", {
    64             rel : "stylesheet",
    62             rel : "stylesheet",
    65             type : "text/css",
    63             type : "text/css",
    66             href : _this.config.gui.css
    64             href : _this.config.gui.css
    67         });
    65         });
    68         console.log('Appending CSS');
       
    69 
    66 
    70         css_link_jquery.appendTo('head');
    67         css_link_jquery.appendTo('head');
    71         css_link_custom.appendTo('head');
    68         css_link_custom.appendTo('head');
    72         
    69         
    73         console.log(_this);
       
    74         _this.onLibsLoaded();
    70         _this.onLibsLoaded();
    75         
    71         
    76     });
    72     });
    77 }
    73 }
    78 
    74 
    81         _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format];
    77         _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format];
    82     }
    78     }
    83     if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") {
    79     if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") {
    84         _metadataInfo.url = _metadataInfo.src;
    80         _metadataInfo.url = _metadataInfo.src;
    85     }
    81     }
    86     console.log(_metadataInfo);
       
    87     if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") {
    82     if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") {
    88         return this.sourceManager.remoteSource(_metadataInfo);
    83         return this.sourceManager.remoteSource(_metadataInfo);
    89     } else {
    84     } else {
    90         return this.sourceManager.newLocalSource(_metadataInfo);
    85         return this.sourceManager.newLocalSource(_metadataInfo);
    91     }
    86     }
    92 }
    87 }
    93 
    88 
    94 IriSP.Metadataplayer.prototype.onLibsLoaded = function() {
    89 IriSP.Metadataplayer.prototype.onLibsLoaded = function() {
    95     console.log("Libs Loaded");
       
    96     this.videoData = this.loadMetadata(this.video_metadata);
    90     this.videoData = this.loadMetadata(this.video_metadata);
    97     console.log(this.videoData);
       
    98     this.$ = IriSP.jQuery('#' + this.config.gui.container);
    91     this.$ = IriSP.jQuery('#' + this.config.gui.container);
    99     this.$.css({
    92     this.$.css({
   100         "width": this.config.gui.width,
    93         "width": this.config.gui.width,
   101         "clear": "both"
    94         "clear": "both"
   102     });
    95     });
   103     if (typeof this.config.gui.height !== "undefined") {
    96     if (typeof this.config.gui.height !== "undefined") {
   104         this.$.css("height", this.config.gui.height);
    97         this.$.css("height", this.config.gui.height);
   105     }
    98     }
   106       
    99       
   107     var _this = this;
   100     var _this = this;
   108     console.log("calling OnLoad");
       
   109     this.videoData.onLoad(function() {
   101     this.videoData.onLoad(function() {
   110         _this.onVideoDataLoaded();
   102         _this.onVideoDataLoaded();
   111     });
   103     });
   112 }
   104 }
   113 
   105 
   114 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
   106 IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() {
   115     console.log("Video Data Loaded");
   107     console.log("Video Data Loaded");
   116     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   108     if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") {
   117         var _media = this.videoData.currentMedia;
   109         var _media = this.videoData.currentMedia;
       
   110         console.log(_media);
   118         if (typeof _media !== "undefined") {
   111         if (typeof _media !== "undefined") {
   119             config.player.video = _media.video;
   112             this.config.player.video = _media.video;
   120             if (typeof _media.streamer !== "undefined") {
   113             if (typeof _media.streamer !== "undefined") {
   121                 config.player.streamer = _media.streamer;
   114                 this.config.player.streamer = _media.streamer;
   122                 config.player.video = _media.video.replace(_media.streamer,'');
   115                 this.config.player.video = _media.video.replace(_media.streamer,'');
   123             }
   116             }
   124         }
   117         }
   125         
   118         
   126     }
   119     }
   127     this.configurePopcorn(config.player);
   120     this.configurePopcorn();
   128     this.widgets = [];
   121     this.widgets = [];
       
   122     console.log("Now instantiating widgets");
   129     for(var i = 0; i < this.config.gui.widgets.length; i++) {
   123     for(var i = 0; i < this.config.gui.widgets.length; i++) {
   130         this.widgets.push(new IriSP.Widgets[_config.type](this, this.config.gui.widgets[i]));
   124         var _widget = this.config.gui.widgets[i];
       
   125         if (typeof IriSP[_widget.type] !== "undefined") {
       
   126             this.widgets.push(new IriSP[_widget.type](this, _widget));
       
   127         } else {
       
   128             console.log("Error, Call to Undefined Widget Type");
       
   129         }
   131     };
   130     };
   132     this.$('.Ldt-loader').detach();
   131     this.$.find('.Ldt-loader').detach();
   133 }
   132 }
   134 
   133 
   135 IriSP.Metadataplayer.prototype.configurePopcorn = function() {
   134 IriSP.Metadataplayer.prototype.configurePopcorn = function() {
   136     var pop,
   135     var pop,
   137         ret = this.layoutDivs(),
   136         ret = this.layoutDivs("video"),
   138         containerDiv = ret[0],
   137         containerDiv = ret[0],
   139         spacerDiv = ret[1];
   138         spacerDiv = ret[1];
   140 
   139 
   141     /* insert one pixel of margin between the video and the first widget,
   140     /* insert one pixel of margin between the video and the first widget,
   142      * using the spacer.
   141      * using the spacer.
   143      */
   142      */
   144     IriSP.jQuery("#" + spacerDiv).css("height", Math.max(1, this.config.gui.spacer_div_height) + "px");
   143     IriSP.jQuery("#" + spacerDiv).css("height", Math.max(1, this.config.gui.spacer_div_height) + "px");
   145 
   144     
   146     switch(options.type) {
   145     console.log(this.config.player);
       
   146 
       
   147     switch(this.config.player.type) {
   147         /*
   148         /*
   148          todo : dynamically create the div/video tag which
   149          todo : dynamically create the div/video tag which
   149          will contain the video.
   150          will contain the video.
   150          */
   151          */
   151         case "html5":
   152         case "html5":
   152             var tmpId = Popcorn.guid("video");
   153             var tmpId = Popcorn.guid("video");
   153             IriSP.jQuery("#" + containerDiv).append("<video src='" + options.video + "' id='" + tmpId + "'></video>");
   154             IriSP.jQuery("#" + containerDiv).append("<video src='" + this.config.player.video + "' id='" + tmpId + "'></video>");
   154 
   155 
   155             if(options.hasOwnProperty("width"))
   156             if(options.hasOwnProperty("width"))
   156                 IriSP.jQuery("#" + containerDiv).css("width", options.width);
   157                 IriSP.jQuery("#" + containerDiv).css("width", this.config.player.width);
   157 
   158 
   158             if(options.hasOwnProperty("height"))
   159             if(options.hasOwnProperty("height"))
   159                 IriSP.jQuery("#" + containerDiv).css("height", options.height);
   160                 IriSP.jQuery("#" + containerDiv).css("height", this.config.player.height);
   160             pop = Popcorn("#" + tmpId);
   161             pop = Popcorn("#" + tmpId);
   161             break;
   162             break;
   162 
   163 
   163         case "jwplayer":
   164         case "jwplayer":
   164             var opts = IriSP.jQuery.extend({}, options);
   165             var opts = IriSP.jQuery.extend({}, this.config.player);
   165             delete opts.container;
   166             delete opts.container;
   166             delete opts.type;
   167             delete opts.type;
   167             opts.file = opts.video;
   168             opts.file = opts.video;
   168             delete opts.video;
   169             delete opts.video;
   169 
   170 
   170             if(!options.hasOwnProperty("flashplayer")) {
   171             if(!opts.hasOwnProperty("flashplayer")) {
   171                 opts.flashplayer = IriSP.jwplayer_swf_path;
   172                 opts.flashplayer = IriSP.jwplayer_swf_path;
   172             }
   173             }
   173 
   174 
   174             if(!options.hasOwnProperty("controlbar.position")) {
   175             if(!opts.hasOwnProperty("controlbar.position")) {
   175                 opts["controlbar.position"] = "none";
   176                 opts["controlbar.position"] = "none";
   176             }
   177             }
   177             pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
   178             pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
   178             break;
   179             break;
   179 
   180 
   180         case "youtube":
   181         case "youtube":
   181             var opts = IriSP.jQuery.extend({}, options);
   182             var opts = IriSP.jQuery.extend({}, this.config.player);
   182             delete opts.container;
   183             delete opts.container;
   183             opts.controls = 0;
   184             opts.controls = 0;
   184             opts.autostart = false;
   185             opts.autostart = false;
   185             // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
   186             // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
   186             IriSP.jQuery("#" + containerDiv).css({
   187             IriSP.jQuery("#" + containerDiv).css({
   189             })
   190             })
   190             pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
   191             pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
   191             break;
   192             break;
   192 
   193 
   193         case "dailymotion":
   194         case "dailymotion":
   194             pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, options);
   195             pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, this.config.player);
   195             break;
   196             break;
   196 
   197 
   197         case "allocine":
   198         case "allocine":
   198             /* pass the options as-is to the allocine player and let it handle everything */
   199             /* pass the options as-is to the allocine player and let it handle everything */
   199             pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options);
   200             pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, this.config.player);
   200             break;
   201             break;
   201         
   202         
   202         default:
   203         default:
   203             pop = undefined;
   204             pop = undefined;
   204     };
   205     };
   212 */
   213 */
   213 IriSP.Metadataplayer.prototype.layoutDivs = function(_name) {
   214 IriSP.Metadataplayer.prototype.layoutDivs = function(_name) {
   214     if (typeof(_name) === "undefined") {
   215     if (typeof(_name) === "undefined") {
   215        _name = "";
   216        _name = "";
   216     }
   217     }
   217     var newDiv = IriSP.guid(this.container + "_widget_" + _name + "_"),
   218     var newDiv = IriSP._.uniqueId(this.config.gui.container + "_widget_" + _name + "_"),
   218         spacerDiv = IriSP.guid("LdtPlayer_spacer_"),
   219         spacerDiv = IriSP._.uniqueId("LdtPlayer_spacer_"),
   219         divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative; clear: both;'></div>",
   220         divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative; clear: both;'></div>",
   220         spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}}px;'></div>",
   221         spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}}px;'></div>",
   221         divHtml = Mustache.to_html( divTempl,
   222         divHtml = Mustache.to_html( divTempl,
   222             {
   223             {
   223                 id: newDiv,
   224                 id: newDiv,
   225             }),
   226             }),
   226         spacerHtml = Mustache.to_html( spacerTempl,
   227         spacerHtml = Mustache.to_html( spacerTempl,
   227             {
   228             {
   228                 spacer_id: spacerDiv,
   229                 spacer_id: spacerDiv,
   229                 width: this.config.gui.width,
   230                 width: this.config.gui.width,
   230                 spacer_div_height: this.config.gui.height
   231                 spacer_div_height: this.config.gui.spacer_div_height
   231             });
   232             });
   232             
   233             
   233     this.$.append(divCode);
   234     this.$.append(divHtml);
   234     this.$.append(spacerCode);
   235     this.$.append(spacerHtml);
   235 
   236 
   236     return [newDiv, spacerDiv];
   237     return [newDiv, spacerDiv];
   237 };
   238 };