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