|
1 /* Displays Play and Pause buttons, Search Button and Form, Volume Control */ |
|
2 |
|
3 IriSP.Widgets.Controller = function(player, config) { |
|
4 IriSP.Widgets.Widget.call(this, player, config); |
|
5 |
|
6 this._searchLastValue = ""; |
|
7 }; |
|
8 |
|
9 IriSP.Widgets.Controller.prototype = new IriSP.Widgets.Widget(); |
|
10 |
|
11 IriSP.Widgets.Controller.prototype.defaults = { |
|
12 disable_annotate_btn: false, |
|
13 disable_search_btn: false |
|
14 } |
|
15 |
|
16 IriSP.Widgets.Controller.prototype.template = |
|
17 '<div class="Ldt-Ctrl">' |
|
18 + '<div class="Ldt-Ctrl-Left">' |
|
19 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Play Ldt-Ctrl-Play-PlayState Ldt-TraceMe" title="{{l10n.play_pause}}"></div>' |
|
20 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
21 + '{{^disable_annotate_btn}}' |
|
22 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Annotate Ldt-TraceMe" title="{{l10n.annotate}}"></div>' |
|
23 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
24 + '{{/disable_annotate_btn}}' |
|
25 + '{{^disable_search_btn}}' |
|
26 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-SearchBtn Ldt-TraceMe" title="{{l10n.search}}"></div>' |
|
27 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
28 + '{{/disable_search_btn}}' |
|
29 + '<div class="Ldt-Ctrl-Search">' |
|
30 + '<input class="Ldt-Ctrl-SearchInput Ldt-TraceMe"></input>' |
|
31 + '</div>' |
|
32 + '</div>' |
|
33 + '<div class="Ldt-Ctrl-Right">' |
|
34 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
35 + '<div class="Ldt-Ctrl-Time">' |
|
36 + '<div class="Ldt-Ctrl-Time-Elapsed" title="{{l10n.elapsed_time}}">00:00</div>' |
|
37 + '<div class="Ldt-Ctrl-Time-Separator">/</div>' |
|
38 + '<div class="Ldt-Ctrl-Time-Total" title="{{l10n.total_time}}">00:00</div>' |
|
39 + '</div>' |
|
40 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
41 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Sound Ldt-Ctrl-Sound-Full Ldt-TraceMe" title="{{l10n.mute_unmute}}"></div>' |
|
42 + '</div>' |
|
43 + '<div class="Ldt-Ctrl-Volume-Control" title="{{l10n.volume_control}}">' |
|
44 + '<div class="Ldt-Ctrl-Volume-Bar"></div>' |
|
45 + '</div>' |
|
46 + '</div>'; |
|
47 |
|
48 IriSP.Widgets.Controller.prototype.messages = { |
|
49 en: { |
|
50 play_pause: "Play/Pause", |
|
51 mute_unmute: "Mute/Unmute", |
|
52 play: "Play", |
|
53 pause: "Pause", |
|
54 mute: "Mute", |
|
55 unmute: "Unmute", |
|
56 annotate: "Annotate", |
|
57 search: "Search", |
|
58 elapsed_time: "Elapsed time", |
|
59 total_time: "Total time", |
|
60 volume: "Volume", |
|
61 volume_control: "Volume control" |
|
62 }, |
|
63 fr: { |
|
64 play_pause: "Lecture/Pause", |
|
65 mute_unmute: "Couper/Activer le son", |
|
66 play: "Lecture", |
|
67 pause: "Pause", |
|
68 mute: "Couper le son", |
|
69 unmute: "Activer le son", |
|
70 annotate: "Annoter", |
|
71 search: "Rechercher", |
|
72 elapsed_time: "Durée écoulée", |
|
73 total_time: "Durée totale", |
|
74 volume: "Niveau sonore", |
|
75 volume_control: "Réglage du niveau sonore" |
|
76 } |
|
77 }; |
|
78 |
|
79 IriSP.Widgets.Controller.prototype.draw = function() { |
|
80 var _this = this; |
|
81 this.renderTemplate(); |
|
82 |
|
83 // Define blocks |
|
84 this.$playButton = this.$.find(".Ldt-Ctrl-Play"); |
|
85 this.$searchBlock = this.$.find(".Ldt-Ctrl-Search"); |
|
86 this.$searchInput = this.$.find(".Ldt-Ctrl-SearchInput"); |
|
87 this.$volumeBar = this.$.find(".Ldt-Ctrl-Volume-Bar"); |
|
88 |
|
89 // handle events |
|
90 this.bindPopcorn("play","playButtonUpdater"); |
|
91 this.bindPopcorn("pause","playButtonUpdater"); |
|
92 this.bindPopcorn("volumechange","volumeUpdater"); |
|
93 this.bindPopcorn("timeupdate","timeDisplayUpdater"); |
|
94 this.bindPopcorn("loadedmetadata","timeDisplayUpdater"); |
|
95 this.bindPopcorn("IriSP.search.matchFound","searchMatch"); |
|
96 this.bindPopcorn("IriSP.search.noMatchFound","searchNoMatch"); |
|
97 this.bindPopcorn("IriSP.search.triggeredSearch","triggeredSearch"); |
|
98 |
|
99 // handle clicks |
|
100 this.$playButton.click(this.functionWrapper("playHandler")); |
|
101 |
|
102 this.$.find(".Ldt-Ctrl-Annotate").click(function() { |
|
103 _this.player.popcorn.trigger("IriSP.Player.AnnotateButton.clicked"); |
|
104 }); |
|
105 this.$.find(".Ldt-Ctrl-SearchBtn").click(this.functionWrapper("searchButtonHandler")); |
|
106 |
|
107 this.$searchInput.keyup(this.functionWrapper("searchHandler") ); |
|
108 |
|
109 var _volctrl = this.$.find(".Ldt-Ctrl-Volume-Control"); |
|
110 this.$.find('.Ldt-Ctrl-Sound') |
|
111 .click(this.functionWrapper("muteHandler")) |
|
112 .mouseover(function() { |
|
113 _volctrl.show(); |
|
114 }) |
|
115 .mouseout(function() { |
|
116 _volctrl.hide(); |
|
117 }); |
|
118 _volctrl.mouseover(function() { |
|
119 _volctrl.show(); |
|
120 }).mouseout(function() { |
|
121 _volctrl.hide(); |
|
122 }); |
|
123 |
|
124 |
|
125 // Allow Volume Cursor Dragging |
|
126 this.$volumeBar.slider({ |
|
127 slide: function(event, ui) { |
|
128 _this.$volumeBar.attr("title",_this.l10n.volume+': ' + ui.value + '%'); |
|
129 _this.player.popcorn.volume(ui.value / 100); |
|
130 }, |
|
131 stop: this.functionWrapper("volumeUpdater") |
|
132 }); |
|
133 |
|
134 // trigger an IriSP.Player.MouseOver to the widgets that are interested (i.e : sliderWidget) |
|
135 this.$.hover( |
|
136 function() { |
|
137 _this.player.popcorn.trigger("IriSP.Player.MouseOver"); |
|
138 }, |
|
139 function() { |
|
140 _this.player.popcorn.trigger("IriSP.Player.MouseOut"); |
|
141 }); |
|
142 setTimeout(this.functionWrapper("volumeUpdater"), 1000); |
|
143 /* some players - including jwplayer - save the state of the mute button between sessions */ |
|
144 }; |
|
145 |
|
146 /* Update the elasped time div */ |
|
147 IriSP.Widgets.Controller.prototype.timeDisplayUpdater = function() { |
|
148 var _curTime = this.player.popcorn.roundTime(); |
|
149 if (typeof this._previousSecond !== "undefined" && _curTime === this._previousSecond) { |
|
150 return; |
|
151 } |
|
152 |
|
153 // we get it at each call because it may change. |
|
154 var _totalTime = this.source.getDuration(), |
|
155 _elapsedTime = new IriSP.Model.Time(); |
|
156 |
|
157 _elapsedTime.setSeconds(_curTime); |
|
158 |
|
159 this.$.find(".Ldt-Ctrl-Time-Elapsed").html(_elapsedTime.toString()); |
|
160 this.$.find(".Ldt-Ctrl-Time-Total").html(_totalTime.toString()); |
|
161 this._previousSecond = _curTime; |
|
162 }; |
|
163 |
|
164 /* update the icon of the button - separate function from playHandler |
|
165 because in some cases (for instance, when the user directly clicks on |
|
166 the jwplayer window) we have to change the icon without playing/pausing |
|
167 */ |
|
168 IriSP.Widgets.Controller.prototype.playButtonUpdater = function() { |
|
169 |
|
170 var status = this.player.popcorn.media.paused; |
|
171 |
|
172 if (status) { |
|
173 /* the background sprite is changed by adding/removing the correct classes */ |
|
174 this.$playButton |
|
175 .attr("title", this.l10n.play) |
|
176 .removeClass("Ldt-Ctrl-Play-PauseState") |
|
177 .addClass("Ldt-Ctrl-Play-PlayState"); |
|
178 } else { |
|
179 this.$playButton |
|
180 .attr("title", this.l10n.pause) |
|
181 .removeClass("Ldt-Ctrl-Play-PlayState") |
|
182 .addClass("Ldt-Ctrl-Play-PauseState"); |
|
183 } |
|
184 }; |
|
185 |
|
186 |
|
187 IriSP.Widgets.Controller.prototype.playHandler = function() { |
|
188 |
|
189 var status = this.player.popcorn.media.paused; |
|
190 |
|
191 if (status) { |
|
192 this.player.popcorn.play(); |
|
193 } else { |
|
194 this.player.popcorn.pause(); |
|
195 } |
|
196 }; |
|
197 |
|
198 IriSP.Widgets.Controller.prototype.muteHandler = function() { |
|
199 this.player.popcorn.mute(!this.player.popcorn.muted()); |
|
200 }; |
|
201 |
|
202 IriSP.Widgets.Controller.prototype.volumeUpdater = function() { |
|
203 var _muted = this.player.popcorn.muted(), |
|
204 _vol = this.player.popcorn.volume(); |
|
205 if (_vol === false) { |
|
206 _vol = .5; |
|
207 } |
|
208 var _soundCtl = this.$.find(".Ldt-Ctrl-Sound"); |
|
209 _soundCtl.removeClass("Ldt-Ctrl-Sound-Mute Ldt-Ctrl-Sound-Half Ldt-Ctrl-Sound-Full"); |
|
210 if (_muted) { |
|
211 _soundCtl.attr("title", this.l10n.unmute) |
|
212 .addClass("Ldt-Ctrl-Sound-Mute"); |
|
213 } else { |
|
214 _soundCtl.attr("title", this.l10n.mute) |
|
215 .addClass(_vol < .5 ? "Ldt-Ctrl-Sound-Half" : "Ldt-Ctrl-Sound-Full" ) |
|
216 } |
|
217 this.$volumeBar.slider("value", _muted ? 0 : 100 * _vol); |
|
218 }; |
|
219 |
|
220 IriSP.Widgets.Controller.prototype.showSearchBlock = function() { |
|
221 this.$searchBlock.show("blind", { direction: "horizontal"}, 100); |
|
222 this.$searchInput.css('background-color','#fff'); |
|
223 |
|
224 this.$searchInput.focus(); |
|
225 |
|
226 // we need this variable because some widgets can find a match in |
|
227 // their data while at the same time others don't. As we want the |
|
228 // search field to become green when there's a match, we need a |
|
229 // variable to remember that we had one. |
|
230 this._positiveMatch = false; |
|
231 |
|
232 // tell the world the field is open |
|
233 this.player.popcorn.trigger("IriSP.search.open"); |
|
234 }; |
|
235 |
|
236 IriSP.Widgets.Controller.prototype.hideSearchBlock = function() { |
|
237 this._searchLastValue = this.$searchInput.val(); |
|
238 this.$searchInput.val(''); |
|
239 this.$searchBlock.hide("blind", { direction: "horizontal"}, 75); |
|
240 |
|
241 this._positiveMatch = false; |
|
242 |
|
243 this.player.popcorn.trigger("IriSP.search.closed"); |
|
244 }; |
|
245 |
|
246 /** react to clicks on the search button */ |
|
247 IriSP.Widgets.Controller.prototype.searchButtonHandler = function() { |
|
248 if ( this.$searchBlock.is(":hidden") ) { |
|
249 this.showSearchBlock(); |
|
250 this.$searchInput.val(this._searchLastValue); |
|
251 this.player.popcorn.trigger("IriSP.search", this._searchLastValue); // trigger the search to make it more natural. |
|
252 } else { |
|
253 this.hideSearchBlock(); |
|
254 } |
|
255 }; |
|
256 |
|
257 /** this handler is called whenever the content of the search |
|
258 field changes */ |
|
259 IriSP.Widgets.Controller.prototype.searchHandler = function() { |
|
260 this._searchLastValue = this.$searchInput.val(); |
|
261 this._positiveMatch = false; |
|
262 |
|
263 // do nothing if the search field is empty, instead of highlighting everything. |
|
264 if (this._searchLastValue == "") { |
|
265 this.player.popcorn.trigger("IriSP.search.cleared"); |
|
266 this.$searchInput.css('background-color',''); |
|
267 } else { |
|
268 this.player.popcorn.trigger("IriSP.search", this._searchLastValue); |
|
269 } |
|
270 }; |
|
271 |
|
272 /** |
|
273 handler for the IriSP.search.found message, which is sent by some views when they |
|
274 highlight a match. |
|
275 */ |
|
276 IriSP.Widgets.Controller.prototype.searchMatch = function() { |
|
277 this._positiveMatch = true; |
|
278 this.$searchInput.css('background-color','#e1ffe1'); |
|
279 }; |
|
280 |
|
281 /** the same, except that no value could be found */ |
|
282 IriSP.Widgets.Controller.prototype.searchNoMatch = function() { |
|
283 if (this._positiveMatch !== true) { |
|
284 this.$searchInput.css('background-color', "#d62e3a"); |
|
285 } |
|
286 }; |
|
287 |
|
288 /** react to an IriSP.Player.triggeredSearch - that is, when |
|
289 a widget ask the.Player to do a search on his behalf */ |
|
290 IriSP.Widgets.Controller.prototype.triggeredSearch = function(searchString) { |
|
291 this.showSearchBlock(); |
|
292 this.$searchInput.attr('value', searchString); |
|
293 this.player.popcorn.trigger("IriSP.search", searchString); // trigger the search to make it more natural. |
|
294 }; |
|
295 |
|
296 |