| author | hamidouk |
| Wed, 28 Dec 2011 12:03:29 +0100 | |
| branch | popcorn-port |
| changeset 538 | b778b2f93ef4 |
| parent 535 | 7c25af985344 |
| child 560 | 68e91efc5a58 |
| 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; |
|
| 299 | 5 |
|
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)); |
| 299 | 22 |
}; |
| 305 | 23 |
|
| 321 | 24 |
IriSP.ArrowWidget.prototype.timeUpdateHandler = function(percents) { |
25 |
var currentTime = this._Popcorn.currentTime(); |
|
26 |
var currentAnnotation = this._serializer.currentAnnotations(currentTime)[0]; // FIXME : use the others ? |
|
27 |
||
28 |
/* move the arrow only if the current annotation changes */ |
|
29 |
if (currentAnnotation != this._oldAnnotation) { |
|
30 |
var begin = (+ currentAnnotation.begin) / 1000; |
|
31 |
var end = (+ currentAnnotation.end) / 1000; |
|
32 |
||
33 |
var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; |
|
34 |
var middle_time = (begin + end) / 2; |
|
35 |
var percents = Math.floor((middle_time / duration) * 100); |
|
36 |
||
37 |
// we need to apply a fix because the arrow has a certain length |
|
38 |
// it's half the length of the arrow (27 / 2). We need to convert |
|
39 |
// it in percents though. |
|
40 |
var totalWidth = this.selector.width(); |
|
41 |
var correction = ((27 / 2) / totalWidth) * 100; |
|
42 |
var corrected_percents = percents - correction; |
|
| 337 | 43 |
|
44 |
/* don't move out of the screen */ |
|
45 |
if (corrected_percents <= 0) |
|
46 |
corrected_percents = 0; |
|
47 |
||
|
535
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
48 |
if (corrected_percents <= 5) { |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
49 |
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
|
50 |
this.selector.children(".Ldt-arrowWidget").css("background-image", left_edge_img_templ); |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
51 |
} else if (corrected_percents >= 95) { |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
} else { |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
} |
|
7c25af985344
made the arrowWidget.js changed its arrow at the edges of the screen.
hamidouk
parents:
337
diff
changeset
|
58 |
|
| 321 | 59 |
this.selector.children(".Ldt-arrowWidget").animate({"left" : corrected_percents + "%"}); |
60 |
||
61 |
this._oldAnnotation = currentAnnotation; |
|
62 |
} |
|
| 305 | 63 |
} |