| author | hamidouk |
| Tue, 31 Jan 2012 16:01:41 +0100 | |
| branch | popcorn-port |
| changeset 754 | b119a956b647 |
| parent 664 | c548eb0be4ef |
| child 803 | 4955d857e304 |
| permissions | -rw-r--r-- |
| 299 | 1 |
IriSP.ArrowWidget = function(Popcorn, config, Serializer) { |
2 |
IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
| 321 | 3 |
|
4 |
this._oldAnnotation = null; |
|
| 563 | 5 |
this._blockArrow = false; |
| 299 | 6 |
}; |
7 |
||
8 |
||
9 |
IriSP.ArrowWidget.prototype = new IriSP.Widget(); |
|
10 |
||
11 |
IriSP.ArrowWidget.prototype.clear = function() { |
|
12 |
||
13 |
}; |
|
14 |
||
15 |
IriSP.ArrowWidget.prototype.clearWidget = function() { |
|
16 |
}; |
|
17 |
||
18 |
IriSP.ArrowWidget.prototype.draw = function() { |
|
19 |
var templ = Mustache.to_html(IriSP.arrowWidget_template, {}); |
|
20 |
this.selector.append(templ); |
|
| 321 | 21 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler)); |
| 563 | 22 |
this._Popcorn.listen("IriSP.ArrowWidget.blockArrow", IriSP.wrap(this, this.blockArrow)); |
23 |
this._Popcorn.listen("IriSP.ArrowWidget.releaseArrow", IriSP.wrap(this, this.releaseArrow)); |
|
24 |
|
|
| 299 | 25 |
}; |
| 305 | 26 |
|
| 321 | 27 |
IriSP.ArrowWidget.prototype.timeUpdateHandler = function(percents) { |
| 563 | 28 |
if (this._blockArrow) |
29 |
return; |
|
30 |
|
|
| 321 | 31 |
var currentTime = this._Popcorn.currentTime(); |
| 664 | 32 |
var currentAnnotation = this._serializer.currentChapitre(currentTime); |
|
754
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
33 |
if (IriSP.null_or_undefined(currentAnnotation)) { |
|
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
34 |
var c_annots = this._serializer.currentAnnotation(currentTime) |
|
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
35 |
if (c_annots.length != 0) |
|
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
36 |
var currentAnnotation = c_annots[0]; // FIXME : use the others ? |
|
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
37 |
else |
|
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
38 |
return; |
|
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
39 |
} |
|
b119a956b647
don't move the arrow widget when there's no annotation at the time.
hamidouk
parents:
664
diff
changeset
|
40 |
|
| 321 | 41 |
/* move the arrow only if the current annotation changes */ |
42 |
if (currentAnnotation != this._oldAnnotation) { |
|
43 |
var begin = (+ currentAnnotation.begin) / 1000; |
|
44 |
var end = (+ currentAnnotation.end) / 1000; |
|
45 |
||
46 |
var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; |
|
47 |
var middle_time = (begin + end) / 2; |
|
|
560
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
48 |
var percents = middle_time / duration; |
| 321 | 49 |
|
50 |
// we need to apply a fix because the arrow has a certain length |
|
51 |
// it's half the length of the arrow (27 / 2). We need to convert |
|
52 |
// it in percents though. |
|
| 664 | 53 |
var totalWidth = this.selector.width(); |
|
560
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
54 |
var pixels = percents * totalWidth; |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
55 |
var correction = (27 / 2); |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
56 |
var corrected_pixels = pixels - correction; |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
57 |
|
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
58 |
/* make sure that the arrow is aligned with the pattern |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
59 |
of the widget under it */ |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
60 |
if (corrected_pixels % 3 != 0) |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
61 |
corrected_pixels -= (corrected_pixels % 3 - 1); |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
62 |
|
| 337 | 63 |
/* don't move out of the screen */ |
|
560
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
64 |
if (corrected_pixels <= 0) |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
65 |
corrected_pixels = 0; |
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
66 |
|
|
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
67 |
if (corrected_pixels <= 15) { |
|
535
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
68 |
var left_edge_img_templ = IriSP.templToHTML("url('{{img_dir}}/left_edge_arrow.png')"); |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
69 |
this.selector.children(".Ldt-arrowWidget").css("background-image", left_edge_img_templ); |
|
560
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
70 |
} else if (corrected_pixels >= totalWidth - 25) { |
|
535
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
71 |
var right_edge_img_templ = IriSP.templToHTML("url('{{img_dir}}/right_edge_arrow.png')"); |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
72 |
this.selector.children(".Ldt-arrowWidget").css("background-image", right_edge_img_templ); |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
73 |
} else { |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
74 |
var img_templ = IriSP.templToHTML("url('{{img_dir}}/arrow.png')"); |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
75 |
this.selector.children(".Ldt-arrowWidget").css("background-image", img_templ); |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
76 |
} |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
77 |
|
|
560
68e91efc5a58
the arrow is now aligned with the pixels under it.
hamidouk
parents:
535
diff
changeset
|
78 |
this.selector.children(".Ldt-arrowWidget").animate({"left" : corrected_pixels + "px"}); |
| 321 | 79 |
|
80 |
this._oldAnnotation = currentAnnotation; |
|
81 |
} |
|
| 563 | 82 |
}; |
83 |
||
84 |
/** Block the arrow for instance when the user is annotating */ |
|
85 |
IriSP.ArrowWidget.prototype.blockArrow = function() { |
|
86 |
this._blockArrow = true; |
|
87 |
}; |
|
88 |
||
89 |
IriSP.ArrowWidget.prototype.releaseArrow = function() { |
|
90 |
this._blockArrow = false; |
|
91 |
}; |