src/js/widgets.js
branchplayers-as-widgets
changeset 957 4da0a5740b6c
parent 927 977a39c4ee80
child 958 2aa7fdb0762a
--- a/src/js/widgets.js	Fri Sep 14 10:38:04 2012 +0900
+++ b/src/js/widgets.js	Mon Sep 17 00:17:06 2012 +0900
@@ -47,6 +47,7 @@
     
     /* Call draw when loaded */
     this.source.onLoad(function() {
+        _this.media = this.getCurrentMedia();
         _this.draw();
     });
    
@@ -88,21 +89,38 @@
             return _function.apply(_this, Array.prototype.slice.call(arguments, 0));
         }
     } else {
-        console.log("Error, Unknown function IriSP." + this.type + "." + _name)
+        console.log("Error, Unknown function IriSP.Widgets" + this.type + "." + _name)
+    }
+}
+
+IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) {
+    switch (typeof _functionOrName) {
+        case "function":
+            return _functionOrName;
+        case "string":
+            return this.functionWrapper(_functionOrName);
+        default:
+            return undefined;
     }
 }
 
-IriSP.Widgets.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) {
-    this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName))
+IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) {
+    this.player.on(_eventName, this.getFunctionOrName(_functionOrName));
+}
+
+IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) {
+    if (typeof this.media === "undefined" || typeof this.media.on === "undefined") {
+        console.log("Error on widget "+this.type, this.media);
+    }
+    this.media.on(_eventName, this.getFunctionOrName(_functionOrName));
 }
 
 IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() {
-    var _curmedia = this.source.currentMedia;
-    return typeof this.annotation_type !== "undefined" && this.annotation_type ? _curmedia.getAnnotationsByTypeTitle(this.annotation_type) : _curmedia.getAnnotations();
+    return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations();
 }
 
 IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() {
-    var _time = Math.floor(this.player.popcorn.currentTime() * 1000);
+    var _time = this.media.getCurrentTime();
     return this.getWidgetAnnotations().filter(function(_annotation) {
         return _annotation.begin <= _time && _annotation.end > _time;
     });