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 _this.draw(); |
51 _this.draw(); |
51 }); |
52 }); |
52 |
53 |
53 /* Adding classes and html attributes */ |
54 /* Adding classes and html attributes */ |
54 this.$ = IriSP.jQuery('#' + this.container); |
55 this.$ = IriSP.jQuery('#' + this.container); |
86 if (typeof _function !== "undefined") { |
87 if (typeof _function !== "undefined") { |
87 return function() { |
88 return function() { |
88 return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
89 return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
89 } |
90 } |
90 } else { |
91 } else { |
91 console.log("Error, Unknown function IriSP." + this.type + "." + _name) |
92 console.log("Error, Unknown function IriSP.Widgets" + this.type + "." + _name) |
92 } |
93 } |
93 } |
94 } |
94 |
95 |
95 IriSP.Widgets.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) { |
96 IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
96 this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName)) |
97 switch (typeof _functionOrName) { |
|
98 case "function": |
|
99 return _functionOrName; |
|
100 case "string": |
|
101 return this.functionWrapper(_functionOrName); |
|
102 default: |
|
103 return undefined; |
|
104 } |
|
105 } |
|
106 |
|
107 IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
|
108 this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
109 } |
|
110 |
|
111 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)); |
97 } |
116 } |
98 |
117 |
99 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
118 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
100 var _curmedia = this.source.currentMedia; |
119 return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations(); |
101 return typeof this.annotation_type !== "undefined" && this.annotation_type ? _curmedia.getAnnotationsByTypeTitle(this.annotation_type) : _curmedia.getAnnotations(); |
|
102 } |
120 } |
103 |
121 |
104 IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
122 IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
105 var _time = Math.floor(this.player.popcorn.currentTime() * 1000); |
123 var _time = this.media.getCurrentTime(); |
106 return this.getWidgetAnnotations().filter(function(_annotation) { |
124 return this.getWidgetAnnotations().filter(function(_annotation) { |
107 return _annotation.begin <= _time && _annotation.end > _time; |
125 return _annotation.begin <= _time && _annotation.end > _time; |
108 }); |
126 }); |
109 } |
127 } |
110 |
128 |