src/widgets/Annotation.js
branchplayers-as-widgets
changeset 957 4da0a5740b6c
parent 927 977a39c4ee80
child 959 ee11ed1b739e
equal deleted inserted replaced
956:7c1d08cf6956 957:4da0a5740b6c
    49 }
    49 }
    50 
    50 
    51 IriSP.Widgets.Annotation.prototype.draw = function() {
    51 IriSP.Widgets.Annotation.prototype.draw = function() {
    52     this.renderTemplate();
    52     this.renderTemplate();
    53     this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), "socialWidget", { type: "Social" });
    53     this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), "socialWidget", { type: "Social" });
    54     this.bindPopcorn("timeupdate","onTimeupdate");
    54     this.onMediaEvent("timeupdate","onTimeupdate");
    55     this.bindPopcorn("IriSP.Annotation.hide","hide");
    55     this.onMdpEvent("Annotation.hide","hide");
    56     this.bindPopcorn("IriSP.Annotation.show","show");
    56     this.onMdpEvent("Annotation.show","show");
    57     this.bindPopcorn("IriSP.Annotation.minimize","minimize");
    57     this.onMdpEvent("Annotation.minimize","minimize");
    58     this.bindPopcorn("IriSP.Annotation.maximize","maximize");
    58     this.onMdpEvent("Annotation.maximize","maximize");
    59     this.bindPopcorn("IriSP.Annotation.getBounds","sendBounds");
    59     this.onMdpEvent("Annotation.getBounds","sendBounds");
    60     this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize"));
    60     this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize"));
    61     this.onTimeupdate();
    61     this.onTimeupdate();
    62 }
    62 }
    63 
    63 
    64 IriSP.Widgets.Annotation.prototype.onTimeupdate = function() {
    64 IriSP.Widgets.Annotation.prototype.onTimeupdate = function(_time) {
    65     var _time = Math.floor(this.player.popcorn.currentTime() * 1000),
    65     var _list = this.getWidgetAnnotationsAtTime();
    66         _list = this.getWidgetAnnotationsAtTime();
       
    67     if (_list.length) {
    66     if (_list.length) {
    68         if (_list[0].id !== this.lastAnnotation) {
    67         if (_list[0].id !== this.lastAnnotation) {
    69             this.drawAnnotation(_list[0]);
    68             this.drawAnnotation(_list[0]);
    70             this.bounds = [ _list[0].begin.valueOf(), _list[0].end.valueOf() ];
    69             this.bounds = [ _list[0].begin.valueOf(), _list[0].end.valueOf() ];
    71         }
    70         }
    72         this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{widget: this.type, time: ( _list[0].begin + _list[0].end ) / 2});
    71         this.player.trigger("Arrow.updatePosition",{widget: this.type, time: ( _list[0].begin + _list[0].end ) / 2});
    73     }
    72     }
    74     else {
    73     else {
    75         this.lastAnnotation = false;
    74         this.lastAnnotation = false;
    76         this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty");
    75         this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty");
    77         this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{widget: this.type, time: _time});
    76         this.player.trigger("Arrow.updatePosition",{widget: this.type, time: _time});
    78         this.bounds = [ _time, _time ];
    77         this.bounds = [ _time, _time ];
    79     }
    78     }
    80     this.sendBounds();
    79     this.sendBounds();
    81 }
    80 }
    82 
    81 
    83 IriSP.Widgets.Annotation.prototype.sendBounds = function() {
    82 IriSP.Widgets.Annotation.prototype.sendBounds = function() {
    84     this.player.popcorn.trigger("IriSP.Annotation.boundsChanged",this.bounds);
    83     this.player.trigger("Annotation.boundsChanged",this.bounds);
    85 }
    84 }
    86 
    85 
    87 IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) {
    86 IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) {
    88     this.lastAnnotation = _annotation.id;
    87     this.lastAnnotation = _annotation.id;
    89     var _url = (typeof _annotation.url !== "undefined" 
    88     var _url = (typeof _annotation.url !== "undefined" 
   105                 _el.detach();
   104                 _el.detach();
   106             }
   105             }
   107         });
   106         });
   108     
   107     
   109         this.$.find('.Ldt-Annotation-TagLabel').click(function() {
   108         this.$.find('.Ldt-Annotation-TagLabel').click(function() {
   110             _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   109             _this.player.trigger("search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   111         });
   110         });
   112     } else {
   111     } else {
   113         this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock");
   112         this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock");
   114     }
   113     }
   115     this.$.find(".Ldt-Annotation-Title").html(_annotation.title);
   114     this.$.find(".Ldt-Annotation-Title").html(_annotation.title);