src/js/widgets.js
branchplayers-as-widgets
changeset 959 ee11ed1b739e
parent 958 2aa7fdb0762a
child 965 eadb7290c325
equal deleted inserted replaced
958:2aa7fdb0762a 959:ee11ed1b739e
    45     /* Getting metadata */
    45     /* Getting metadata */
    46     this.source = player.loadMetadata(this.metadata);
    46     this.source = player.loadMetadata(this.metadata);
    47     
    47     
    48     /* Call draw when loaded */
    48     /* Call draw when loaded */
    49     this.source.onLoad(function() {
    49     this.source.onLoad(function() {
    50         _this.media = this.getCurrentMedia();
    50         if (_this.media_id) {
       
    51             _this.media = this.getElement(_this.media_id);
       
    52         } else {
       
    53             var _mediaopts = {
       
    54                 is_mashup: _this.is_mashup || false
       
    55             }
       
    56             _this.media = this.getCurrentMedia(_mediaopts);
       
    57         }
       
    58         
    51         _this.draw();
    59         _this.draw();
    52     });
    60     });
    53    
    61    
    54     /* Adding classes and html attributes */
    62     /* Adding classes and html attributes */
    55     this.$ = IriSP.jQuery('#' + this.container);
    63     this.$ = IriSP.jQuery('#' + this.container);
   107 IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) {
   115 IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) {
   108     this.player.on(_eventName, this.getFunctionOrName(_functionOrName));
   116     this.player.on(_eventName, this.getFunctionOrName(_functionOrName));
   109 }
   117 }
   110 
   118 
   111 IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) {
   119 IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) {
   112     if (typeof this.media === "undefined" || typeof this.media.on === "undefined") {
       
   113         console.log("Error on widget "+this.type, this.media);
       
   114     }
       
   115     this.media.on(_eventName, this.getFunctionOrName(_functionOrName));
   120     this.media.on(_eventName, this.getFunctionOrName(_functionOrName));
   116 }
   121 }
   117 
   122 
   118 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() {
   123 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() {
   119     return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations();
   124     return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations();
   124     return this.getWidgetAnnotations().filter(function(_annotation) {
   129     return this.getWidgetAnnotations().filter(function(_annotation) {
   125         return _annotation.begin <= _time && _annotation.end > _time;
   130         return _annotation.begin <= _time && _annotation.end > _time;
   126     });
   131     });
   127 }
   132 }
   128 
   133 
   129 IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _propname, _widgetoptions) {
   134 IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) {
   130     var _id = _selector.attr("id"),
   135     var _id = _selector.attr("id"),
   131         _this = this,
   136         _this = this,
   132         _type = _widgetoptions.type,
   137         _type = _widgetoptions.type,
   133         $L = $LAB;
   138         $L = $LAB;
   134     if (typeof _id == "undefined") {
   139     if (typeof _id == "undefined") {
   141             $L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j]));
   146             $L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j]));
   142         }
   147         }
   143     }
   148     }
   144     $L.wait(function() {
   149     $L.wait(function() {
   145         _this.player.loadWidget(_widgetoptions, function(_widget) {
   150         _this.player.loadWidget(_widgetoptions, function(_widget) {
   146             _this[_propname] = _widget;
   151             if (_propname) {
       
   152                 _this[_propname] = _widget;
       
   153             }
   147         });
   154         });
   148     });
   155     });
   149 }
   156 }
   150 
   157 
   151 /**
   158 /**