| author | hamidouk |
| Thu, 24 Nov 2011 14:50:57 +0100 | |
| branch | popcorn-port |
| changeset 322 | 6fc87426ecd4 |
| parent 316 | 3b11a798f5e4 |
| child 324 | abe961b7f295 |
| permissions | -rw-r--r-- |
|
289
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
1 |
IriSP.SliderWidget = function(Popcorn, config, Serializer) { |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
2 |
IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
3 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
4 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
5 |
IriSP.SliderWidget.prototype = new IriSP.Widget(); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
6 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
7 |
IriSP.SliderWidget.prototype.draw = function() { |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
8 |
var self = this; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
9 |
|
| 316 | 10 |
this.selector.append(Mustache.to_html(IriSP.sliderWidget_template, {})); |
|
289
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
11 |
|
| 316 | 12 |
this.sliderBackground = this.selector.find(".Ldt-sliderBackground"); |
13 |
this.sliderForeground = this.selector.find(".Ldt-sliderForeground"); |
|
14 |
this.positionMarker = this.selector.find(".Ldt-sliderPositionMarker"); |
|
|
289
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
15 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
16 |
// a special variable to stop methods from tinkering |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
17 |
// with the positionMarker when the user is dragging it |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
18 |
this.draggingOngoing = false; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
19 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
20 |
this.positionMarker.draggable({axis: "x", |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
21 |
start: IriSP.wrap(this, this.positionMarkerDraggingStartedHandler), |
|
322
6fc87426ecd4
fixed slider bug where the slider could be dragged out of his parent div.
hamidouk
parents:
316
diff
changeset
|
22 |
stop: IriSP.wrap(this, this.positionMarkerDraggedHandler), |
|
6fc87426ecd4
fixed slider bug where the slider could be dragged out of his parent div.
hamidouk
parents:
316
diff
changeset
|
23 |
containment: "parent" |
|
6fc87426ecd4
fixed slider bug where the slider could be dragged out of his parent div.
hamidouk
parents:
316
diff
changeset
|
24 |
}); |
|
289
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
25 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
26 |
this.sliderBackground.click(function(event) { self.clickHandler.call(self, event); }); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
27 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
28 |
this.selector.hover(IriSP.wrap(this, this.mouseOverHandler), IriSP.wrap(this, this.mouseOutHandler)); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
29 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater)); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
30 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
31 |
|
|
322
6fc87426ecd4
fixed slider bug where the slider could be dragged out of his parent div.
hamidouk
parents:
316
diff
changeset
|
32 |
/* update the slider and the position marker as time passes */ |
|
289
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
33 |
IriSP.SliderWidget.prototype.sliderUpdater = function() { |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
34 |
if(this.draggingOngoing) |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
35 |
return; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
36 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
37 |
var time = this._Popcorn.currentTime(); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
38 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
39 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
40 |
var percent = ((time / duration) * 100).toFixed(2); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
41 |
this.sliderForeground.css("width", percent + "%"); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
42 |
this.positionMarker.css("left", percent + "%"); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
43 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
44 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
45 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
46 |
IriSP.SliderWidget.prototype.clickHandler = function(event) { |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
47 |
/* this piece of code is a little bit convoluted - here's how it works : |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
48 |
we want to handle clicks on the progress bar and convert those to seeks in the media. |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
49 |
However, jquery only gives us a global position, and we want a number of pixels relative |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
50 |
to our container div, so we get the parent position, and compute an offset to this position, |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
51 |
and finally compute the progress ratio in the media. |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
52 |
Finally we multiply this ratio with the duration to get the correct time |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
53 |
*/ |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
54 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
55 |
var parentOffset = this.sliderBackground.parent().offset(); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
56 |
var width = this.sliderBackground.width(); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
57 |
var relX = event.pageX - parentOffset.left; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
58 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
59 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
60 |
var newTime = ((relX / width) * duration).toFixed(2); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
61 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
62 |
this._Popcorn.currentTime(newTime); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
63 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
64 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
65 |
/* handles mouse over the slider */ |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
66 |
IriSP.SliderWidget.prototype.mouseOverHandler = function(event) { |
| 316 | 67 |
/* this.sliderBackground.animate({"padding-top": "10px", "margin-top": "-10px"}, 100); |
68 |
this.sliderForeground.animate({"margin-top": "-10px"}, 100); */ |
|
|
289
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
69 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
70 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
71 |
/* handles when the mouse leaves the slider */ |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
72 |
IriSP.SliderWidget.prototype.mouseOutHandler = function(event) { |
| 316 | 73 |
/* this.sliderBackground.animate({"padding-top": "5", "margin-top": "0px"}, 100); |
74 |
this.sliderForeground.animate({"padding-top": "5px"}, 50); */ |
|
|
289
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
75 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
76 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
77 |
// called when the user starts dragging the position indicator |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
78 |
IriSP.SliderWidget.prototype.positionMarkerDraggingStartedHandler = function(event, ui) { |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
79 |
this.draggingOngoing = true; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
80 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
81 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
82 |
IriSP.SliderWidget.prototype.positionMarkerDraggedHandler = function(event, ui) { |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
83 |
var width = this.sliderBackground.width(); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
84 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
85 |
var newTime = ((ui.offset.left / width) * duration).toFixed(2); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
86 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
87 |
this._Popcorn.currentTime(newTime); |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
88 |
|
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
89 |
this.draggingOngoing = false; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
90 |
}; |
|
c0e399fbf3fb
due to a np++ crash, some files where created in with windows line endings.
hamidouk
parents:
260
diff
changeset
|
91 |