| author | hamidouk |
| Fri, 13 Jan 2012 12:36:32 +0100 | |
| branch | popcorn-port |
| changeset 624 | 177dfeacc7a6 |
| parent 621 | 170a8cd859d5 |
| child 629 | b13bcfd2f9b1 |
| permissions | -rw-r--r-- |
| 585 | 1 |
IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) { |
2 |
IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
3 |
this.__counter = 0; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
4 |
this.__oldList = []; |
| 585 | 5 |
}; |
6 |
||
7 |
||
8 |
IriSP.AnnotationsListWidget.prototype = new IriSP.Widget(); |
|
9 |
||
10 |
IriSP.AnnotationsListWidget.prototype.clear = function() { |
|
11 |
}; |
|
12 |
||
| 588 | 13 |
IriSP.AnnotationsListWidget.prototype.clearWidget = function() { |
| 585 | 14 |
}; |
15 |
||
| 599 | 16 |
/** draw the annotation list */ |
|
607
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
17 |
IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) { |
| 585 | 18 |
var _this = this; |
19 |
||
|
595
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
588
diff
changeset
|
20 |
var view_type = this._serializer.getContributions(); |
| 585 | 21 |
var annotations = this._serializer._data.annotations; |
| 602 | 22 |
var currentTime = this._Popcorn.currentTime(); |
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
23 |
|
| 585 | 24 |
var list = []; |
| 588 | 25 |
|
| 621 | 26 |
if (typeof(view_type) === "undefined") { |
| 585 | 27 |
return; |
28 |
} |
|
| 588 | 29 |
|
| 585 | 30 |
for (i = 0; i < annotations.length; i++) { |
31 |
var annotation = annotations[i]; |
|
32 |
||
33 |
/* filter the annotations whose type is not the one we want */ |
|
34 |
if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
| 615 | 35 |
&& annotation.meta["id-ref"] !== view_type) { |
| 585 | 36 |
continue; |
37 |
} |
|
38 |
||
| 602 | 39 |
/* only get the annotations happening in the current chapter */ |
| 603 | 40 |
if (!(annotation.begin <= currentTime * 1000 && annotation.end > currentTime * 1000)) { |
| 602 | 41 |
continue; |
42 |
} |
|
| 603 | 43 |
|
| 585 | 44 |
var a = annotation; |
45 |
var obj = {}; |
|
| 588 | 46 |
|
| 585 | 47 |
obj["id"] = a.id; |
48 |
obj["title"] = a.content.title; |
|
49 |
obj["desc"] = a.content.description; |
|
| 603 | 50 |
obj["begin"] = IriSP.msToTime(annotation.begin); |
51 |
obj["end"] = IriSP.msToTime(annotation.end); |
|
| 588 | 52 |
|
| 585 | 53 |
list.push(obj); |
54 |
} |
|
|
607
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
55 |
|
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
56 |
var idList = IriSP.underscore.pluck(list, "id").sort(); |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
57 |
|
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
58 |
if (idList.length !== this.__oldList.length) { |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
59 |
var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list}); |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
60 |
this.selector.html(widgetMarkup); |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
61 |
} |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
62 |
|
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
63 |
var res = 1; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
64 |
for (var i = 0; i < idList.length; i++) { |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
65 |
if (idList[i] !== this.__oldList[i]) |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
66 |
res = 0; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
67 |
break; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
68 |
} |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
69 |
|
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
70 |
this.__oldList = idList; /* save for next call */ |
|
607
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
71 |
|
|
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
72 |
if (typeof(force_redraw) !== "undefined") { |
|
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
73 |
console.log("forced redraw"); |
|
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
74 |
var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list}); |
|
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
75 |
this.selector.html(widgetMarkup); |
|
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
76 |
} |
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
77 |
|
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
78 |
/* the two lists are equal, no need to redraw */ |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
79 |
if (res === 1) { |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
80 |
return; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
81 |
} else { |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
82 |
var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list}); |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
83 |
this.selector.html(widgetMarkup); |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
84 |
} |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
85 |
|
| 599 | 86 |
}; |
87 |
||
88 |
IriSP.AnnotationsListWidget.prototype.draw = function() { |
|
89 |
||
90 |
this.drawList(); |
|
|
607
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
91 |
this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, function() { this.redraw(true); })); |
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
92 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw)); |
| 599 | 93 |
}; |
94 |
||
95 |
IriSP.AnnotationsListWidget.prototype.redraw = function() { |
|
96 |
this.drawList(); |
|
| 585 | 97 |
}; |