1 IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) { |
1 IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) { |
2 IriSP.Widget.call(this, Popcorn, config, Serializer); |
2 IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
3 this.__counter = 0; |
|
4 this.__oldList = []; |
3 }; |
5 }; |
4 |
6 |
5 |
7 |
6 IriSP.AnnotationsListWidget.prototype = new IriSP.Widget(); |
8 IriSP.AnnotationsListWidget.prototype = new IriSP.Widget(); |
7 |
9 |
16 var _this = this; |
18 var _this = this; |
17 |
19 |
18 var view_type = this._serializer.getContributions(); |
20 var view_type = this._serializer.getContributions(); |
19 var annotations = this._serializer._data.annotations; |
21 var annotations = this._serializer._data.annotations; |
20 var currentTime = this._Popcorn.currentTime(); |
22 var currentTime = this._Popcorn.currentTime(); |
21 |
23 |
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 |
|
28 var list = []; |
24 var list = []; |
29 |
25 |
30 if (typeof(view_type) === "undefined") { |
26 if (typeof(view_type) === "undefined") { |
31 console.log("no type suitable for display"); |
27 console.log("no type suitable for display"); |
32 return; |
28 return; |
56 obj["end"] = IriSP.msToTime(annotation.end); |
52 obj["end"] = IriSP.msToTime(annotation.end); |
57 |
53 |
58 list.push(obj); |
54 list.push(obj); |
59 } |
55 } |
60 |
56 |
61 var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list}); |
57 var idList = IriSP.underscore.pluck(list, "id").sort(); |
62 this.selector.html(widgetMarkup); |
58 |
|
59 if (idList.length !== this.__oldList.length) { |
|
60 var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list}); |
|
61 this.selector.html(widgetMarkup); |
|
62 } |
|
63 |
|
64 var res = 1; |
|
65 for (var i = 0; i < idList.length; i++) { |
|
66 if (idList[i] !== this.__oldList[i]) |
|
67 res = 0; |
|
68 break; |
|
69 } |
|
70 |
|
71 this.__oldList = idList; /* save for next call */ |
|
72 |
|
73 /* the two lists are equal, no need to redraw */ |
|
74 if (res === 1) { |
|
75 return; |
|
76 } else { |
|
77 var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list}); |
|
78 this.selector.html(widgetMarkup); |
|
79 } |
|
80 |
63 }; |
81 }; |
64 |
82 |
65 IriSP.AnnotationsListWidget.prototype.draw = function() { |
83 IriSP.AnnotationsListWidget.prototype.draw = function() { |
66 |
84 |
67 this.drawList(); |
85 this.drawList(); |
68 this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.redraw)); |
86 this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.drawList)); |
69 this._Popcorn.listen("seeked", IriSP.wrap(this, this.redraw)); |
87 this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw)); |
70 }; |
88 }; |
71 |
89 |
72 IriSP.AnnotationsListWidget.prototype.redraw = function() { |
90 IriSP.AnnotationsListWidget.prototype.redraw = function() { |
|
91 /* we use some kind of counter to mitigate the fact that the function |
|
92 is supposed to be called at every timeupdate */ |
|
93 /* if (this.__counter < 4) { |
|
94 this.__counter++; |
|
95 } else { |
|
96 this.drawList(); |
|
97 this.__counter = 0; |
|
98 }*/ |
|
99 |
73 this.drawList(); |
100 this.drawList(); |
74 }; |
101 }; |