src/js/widgets/annotationsListWidget.js
branchpopcorn-port
changeset 602 b35862f9b0b0
parent 599 a5a5e70d46a7
child 603 58dfdafb5410
equal deleted inserted replaced
601:02b857c0c9f1 602:b35862f9b0b0
    15 IriSP.AnnotationsListWidget.prototype.drawList = function() {
    15 IriSP.AnnotationsListWidget.prototype.drawList = function() {
    16   var _this = this;
    16   var _this = this;
    17 
    17 
    18   var view_type = this._serializer.getContributions();
    18   var view_type = this._serializer.getContributions();
    19   var annotations = this._serializer._data.annotations;
    19   var annotations = this._serializer._data.annotations;
       
    20   var currentTime = this._Popcorn.currentTime();
       
    21   
       
    22   /* happens when the player hasn't yet loaded */
       
    23   if (typeof(currentTime) === "undefined") {
       
    24     window.setTimeout(IriSP.wrap(this, this.drawList), 4000);
       
    25     return;
       
    26   }
       
    27   
    20   var list = [];
    28   var list = [];
    21 
    29 
    22   if (typeof(view_type) === "undefined") {
    30   if (typeof(view_type) === "undefined") {
    23     console.log("not type suitable for display");
    31     console.log("no type suitable for display");
    24     return;
    32     return;
    25   }
    33   }
    26 
    34 
       
    35   console.log(currentTime);
    27   for (i = 0; i < annotations.length; i++) {
    36   for (i = 0; i < annotations.length; i++) {
    28     var annotation = annotations[i];
    37     var annotation = annotations[i];
    29 
    38 
    30     /* filter the annotations whose type is not the one we want */
    39     /* filter the annotations whose type is not the one we want */
    31     if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
    40     if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
    32           && annotation.meta["id-ref"] != view_type) {
    41           && annotation.meta["id-ref"] != view_type) {
    33         continue;
    42         continue;
    34     }
    43     }
    35 
    44 
       
    45     /* only get the annotations happening in the current chapter */
       
    46     if (annotation.begin > currentTime || annotation.end <= currentTime) {
       
    47         continue;
       
    48     }
       
    49     
    36     var a = annotation;
    50     var a = annotation;
    37     var obj = {};
    51     var obj = {};
    38 
    52 
    39     obj["id"] = a.id;
    53     obj["id"] = a.id;
    40     obj["title"] = a.content.title;
    54     obj["title"] = a.content.title;
    51 
    65 
    52 IriSP.AnnotationsListWidget.prototype.draw = function() {
    66 IriSP.AnnotationsListWidget.prototype.draw = function() {
    53 
    67 
    54   this.drawList();
    68   this.drawList();
    55   this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.redraw));
    69   this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.redraw));
       
    70   this._Popcorn.listen("seeked", IriSP.wrap(this, this.redraw));
    56 };
    71 };
    57 
    72 
    58 IriSP.AnnotationsListWidget.prototype.redraw = function() {
    73 IriSP.AnnotationsListWidget.prototype.redraw = function() {
    59   this.drawList();
    74   this.drawList();
    60 };
    75 };