144 IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
144 IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
145 this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
145 this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
146 }; |
146 }; |
147 |
147 |
148 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
148 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
|
149 var result = null; |
149 if (typeof this.annotation_type === "undefined") { |
150 if (typeof this.annotation_type === "undefined") { |
150 return this.media.getAnnotations(); |
151 result = this.media.getAnnotations(); |
151 } |
152 } else if (this.annotation_type.elementType === "annotationType") { |
152 if (this.annotation_type.elementType === "annotationType") { |
153 result = this.annotation_type.getAnnotations(); |
153 return this.annotation_type.getAnnotations(); |
154 } else { |
154 } |
155 result = this.media.getAnnotationsByTypeTitle(this.annotation_type); |
155 return this.media.getAnnotationsByTypeTitle(this.annotation_type); |
156 } |
|
157 if (typeof this.annotation_filter !== "undefined") { |
|
158 return this.annotation_filter(result); |
|
159 } else { |
|
160 return result; |
|
161 } |
156 }; |
162 }; |
157 |
163 |
158 IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
164 IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
159 var _time = this.media.getCurrentTime(); |
165 var _time = this.media.getCurrentTime(); |
160 return this.getWidgetAnnotations().filter(function(_annotation) { |
166 return this.getWidgetAnnotations().filter(function(_annotation) { |
194 _this.__subwidgets[key] = _widget; |
200 _this.__subwidgets[key] = _widget; |
195 }); |
201 }); |
196 }); |
202 }); |
197 }; |
203 }; |
198 |
204 |
|
205 /* |
|
206 * Position the player to the next/previous annotations based on current player position |
|
207 * |
|
208 * Parameter: offset: -1 for previous annotation, +1 for next annotation |
|
209 */ |
|
210 IriSP.Widgets.Widget.prototype.navigate = function(offset) { |
|
211 // offset is normally either -1 (previous slide) or +1 (next slide) |
|
212 var _this = this; |
|
213 var currentTime = _this.media.getCurrentTime(); |
|
214 var annotations = _this.source.getAnnotations().sortBy(function(_annotation) { |
|
215 return _annotation.begin; |
|
216 }); |
|
217 for (var i = 0; i < annotations.length; i++) { |
|
218 if (annotations[i].begin <= currentTime && currentTime < annotations[i].end) { |
|
219 // Found a current annotation - clamp i+offset value to [0, length - 1] |
|
220 i = Math.min(annotations.length - 1, Math.max(0, i + offset)); |
|
221 _this.media.setCurrentTime(annotations[i].begin); |
|
222 break; |
|
223 } |
|
224 }; |
|
225 }; |
|
226 |
|
227 |
199 /** |
228 /** |
200 * This method responsible of drawing a widget on screen. |
229 * This method responsible of drawing a widget on screen. |
201 */ |
230 */ |
202 IriSP.Widgets.Widget.prototype.draw = function() { |
231 IriSP.Widgets.Widget.prototype.draw = function() { |
203 /* implemented by "sub-classes" */ |
232 /* implemented by "sub-classes" */ |