|
1 /* |
|
2 The Slider Widget shows time position and allows seek |
|
3 */ |
|
4 |
|
5 IriSP.Widgets.Slice = function(player, config) { |
|
6 IriSP.Widgets.Widget.call(this, player, config); |
|
7 this.sliding = false; |
|
8 }; |
|
9 |
|
10 IriSP.Widgets.Slice.prototype = new IriSP.Widgets.Widget(); |
|
11 |
|
12 IriSP.Widgets.Slice.prototype.defaults = { |
|
13 start_visible : false, |
|
14 live_update : true, |
|
15 /* Shall the bounds change each time |
|
16 the Annotation Widget sends an update (true) |
|
17 or only when "show" is triggered (false) ? |
|
18 - true is to be recommended when the widget is permanently displayed. |
|
19 */ |
|
20 override_bounds : true |
|
21 /* Can the Annotation Widget bounds be overriden ? */ |
|
22 }; |
|
23 |
|
24 IriSP.Widgets.Slice.prototype.draw = function() { |
|
25 |
|
26 this.$slider = IriSP.jQuery('<div>') |
|
27 .addClass("Ldt-Slice") |
|
28 |
|
29 this.$.append(this.$slider); |
|
30 |
|
31 this.min = 0; |
|
32 this.max = this.source.getDuration().valueOf(); |
|
33 |
|
34 var _this = this, |
|
35 _currentTime; |
|
36 |
|
37 this.$slider.slider({ |
|
38 range: true, |
|
39 values: [0, 0], |
|
40 min: 0, |
|
41 max: this.max, |
|
42 change: function(event, ui) { |
|
43 _this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{ |
|
44 widget:_this.type, |
|
45 time:Math.floor((ui.values[0]+ui.values[1])/2) |
|
46 }); |
|
47 _this.player.popcorn.trigger("IriSP.Slice.boundsChanged",[ui.values[0], ui.values[1]]); |
|
48 }, |
|
49 start: function() { |
|
50 _this.sliding = true; |
|
51 if (!_this.player.popcorn.media.paused) { |
|
52 _this.player.popcorn.pause(); |
|
53 } |
|
54 _currentTime = _this.player.popcorn.currentTime(); |
|
55 }, |
|
56 slide: function(event, ui) { |
|
57 if (!_this.override_bounds && (ui.value < _this.min || ui.value > _this.max)) { |
|
58 return false; |
|
59 } |
|
60 _this.player.popcorn.currentTime(ui.value / 1000); |
|
61 }, |
|
62 stop: function() { |
|
63 _this.sliding = false; |
|
64 _this.player.popcorn.currentTime(_currentTime); |
|
65 } |
|
66 }); |
|
67 this.$slider.find(".ui-slider-handle:first").addClass("Ldt-Slice-left-handle"); |
|
68 this.$slider.find(".ui-slider-handle:last").addClass("Ldt-Slice-right-handle"); |
|
69 if (this.start_visible) { |
|
70 this.show(); |
|
71 } else { |
|
72 this.hide(); |
|
73 } |
|
74 this.bindPopcorn("IriSP.Slice.show","show"); |
|
75 this.bindPopcorn("IriSP.Slice.hide","hide"); |
|
76 this.bindPopcorn("IriSP.Annotation.boundsChanged","storeBounds"); |
|
77 this.player.popcorn.trigger("IriSP.Annotation.getBounds"); |
|
78 }; |
|
79 |
|
80 IriSP.Widgets.Slice.prototype.show = function() { |
|
81 this.$slider.show(); |
|
82 this.player.popcorn.trigger("IriSP.Arrow.takeover",this.type); |
|
83 this.$slider.slider("values", [this.min, this.max]); |
|
84 } |
|
85 |
|
86 IriSP.Widgets.Slice.prototype.hide = function() { |
|
87 this.$slider.hide(); |
|
88 this.player.popcorn.trigger("IriSP.Arrow.release"); |
|
89 } |
|
90 |
|
91 IriSP.Widgets.Slice.prototype.storeBounds = function(_values) { |
|
92 if (!this.player.popcorn.media.paused && (this.min != _values[0] || this.max != _values[1])) { |
|
93 this.min = _values[0]; |
|
94 this.max = _values[1]; |
|
95 if (this.live_update && !this.sliding) { |
|
96 this.$slider.slider("values", [this.min, this.max]); |
|
97 } |
|
98 } |
|
99 } |