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 this.lastSearchValue = ""; |
|
6 }; |
|
7 |
|
8 IriSP.Widgets.Controller.prototype = new IriSP.Widgets.Widget(); |
|
9 |
|
10 IriSP.Widgets.Controller.prototype.defaults = { |
|
11 disable_annotate_btn: false, |
|
12 disable_search_btn: false, |
|
13 disable_ctrl_f: false, |
|
14 disable_fullscreen : true, |
|
15 always_show_search: false, |
|
16 enable_quiz_toggle: undefined |
|
17 }; |
|
18 |
|
19 IriSP.Widgets.Controller.prototype.template = |
|
20 '<div class="Ldt-Ctrl">' |
|
21 + '<div class="Ldt-Ctrl-Left">' |
|
22 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Play Ldt-Ctrl-Play-PlayState Ldt-TraceMe" title="{{l10n.play_pause}}"></div>' |
|
23 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
24 + '{{^disable_annotate_btn}}' |
|
25 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Annotate Ldt-TraceMe" title="{{l10n.annotate}}"></div>' |
|
26 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
27 + '{{/disable_annotate_btn}}' |
|
28 + '{{^disable_search_btn}}' |
|
29 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-SearchBtn Ldt-TraceMe" title="{{l10n.search}}"></div>' |
|
30 + '{{/disable_search_btn}}' |
|
31 + '<div class="Ldt-Ctrl-Search">' |
|
32 + '<input placeholder="{{ l10n.search }}" type="search" class="Ldt-Ctrl-SearchInput Ldt-TraceMe"></input>' |
|
33 + '</div>' |
|
34 + '<div class="Ldt-Ctrl-Quiz-Enable Ldt-TraceMe" title="Activer/Désactiver le quiz"></div>' |
|
35 + '<div class="Ldt-Ctrl-Quiz-Create Ldt-TraceMe" ></div>' |
|
36 + '</div>' |
|
37 + '<div class="Ldt-Ctrl-Right">' |
|
38 + '{{^disable_fullscreen}}<div class="Ldt-Ctrl-Fullscreen-Button Ldt-TraceMe" title="Passer le lecteur en plein-écran"></div{{/disable_fullscreen}}' |
|
39 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
40 + '<div class="Ldt-Ctrl-Time">' |
|
41 + '<div class="Ldt-Ctrl-Time-Elapsed" title="{{l10n.elapsed_time}}">00:00</div>' |
|
42 + '<div class="Ldt-Ctrl-Time-Separator">/</div>' |
|
43 + '<div class="Ldt-Ctrl-Time-Total" title="{{l10n.total_time}}">00:00</div>' |
|
44 + '</div>' |
|
45 + '<div class="Ldt-Ctrl-spacer"></div>' |
|
46 + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Sound Ldt-Ctrl-Sound-Full Ldt-TraceMe" title="{{l10n.mute_unmute}}"></div>' |
|
47 + '</div>' |
|
48 + '<div class="Ldt-Ctrl-Volume-Control" title="{{l10n.volume_control}}">' |
|
49 + '<div class="Ldt-Ctrl-Volume-Bar"></div>' |
|
50 + '</div>' |
|
51 + '</div>'; |
|
52 |
|
53 IriSP.Widgets.Controller.prototype.messages = { |
|
54 en: { |
|
55 play_pause: "Play/Pause", |
|
56 mute_unmute: "Mute/Unmute", |
|
57 play: "Play", |
|
58 pause: "Pause", |
|
59 mute: "Mute", |
|
60 unmute: "Unmute", |
|
61 annotate: "Annotate", |
|
62 search: "Search", |
|
63 elapsed_time: "Elapsed time", |
|
64 total_time: "Total duration", |
|
65 volume: "Volume", |
|
66 volume_control: "Volume control", |
|
67 enable_quiz: "Enable quiz" |
|
68 }, |
|
69 fr: { |
|
70 play_pause: "Lecture/Pause", |
|
71 mute_unmute: "Couper/Activer le son", |
|
72 play: "Lecture", |
|
73 pause: "Pause", |
|
74 mute: "Couper le son", |
|
75 unmute: "Activer le son", |
|
76 annotate: "Annoter", |
|
77 search: "Rechercher", |
|
78 elapsed_time: "Temps écoulé", |
|
79 total_time: "Durée totale", |
|
80 volume: "Niveau sonore", |
|
81 volume_control: "Réglage du niveau sonore", |
|
82 enable_quiz: "Activer le quiz" |
|
83 } |
|
84 }; |
|
85 |
|
86 IriSP.Widgets.Controller.prototype.draw = function() { |
|
87 var _this = this; |
|
88 this.renderTemplate(); |
|
89 |
|
90 // Define blocks |
|
91 this.$playButton = this.$.find(".Ldt-Ctrl-Play"); |
|
92 this.$searchBlock = this.$.find(".Ldt-Ctrl-Search"); |
|
93 this.$searchInput = this.$.find(".Ldt-Ctrl-SearchInput"); |
|
94 this.$volumeBar = this.$.find(".Ldt-Ctrl-Volume-Bar"); |
|
95 |
|
96 // handle events |
|
97 this.onMediaEvent("play","playButtonUpdater"); |
|
98 this.onMediaEvent("pause","playButtonUpdater"); |
|
99 this.onMediaEvent("volumechange","volumeUpdater"); |
|
100 this.onMediaEvent("timeupdate","timeDisplayUpdater"); |
|
101 this.onMediaEvent("loadedmetadata","volumeUpdater"); |
|
102 |
|
103 // handle clicks |
|
104 this.$playButton.click(this.functionWrapper("playHandler")); |
|
105 |
|
106 if (this.enable_quiz_toggle !== undefined) { |
|
107 if (this.enable_quiz_toggle) { |
|
108 this.$.find(".Ldt-Ctrl-Quiz-Enable").addClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
109 this.$.find(".Ldt-Ctrl-Quiz-Create").addClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
110 // this.player.trigger("QuizCreator.show"); |
|
111 this.$.find("#QuizEditContainer").show(); |
|
112 } |
|
113 else |
|
114 { |
|
115 this.$.find(".Ldt-Ctrl-Quiz-Enable").removeClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
116 this.$.find(".Ldt-Ctrl-Quiz-Create").removeClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
117 this.player.trigger("QuizCreator.hide"); |
|
118 this.$.find("#QuizEditContainer").hide(); |
|
119 } |
|
120 } else { |
|
121 this.$.find(".Ldt-Ctrl-Quiz-Enable").hide(); |
|
122 } |
|
123 |
|
124 this.$.find(".Ldt-Ctrl-Annotate").click(function() { |
|
125 _this.player.trigger("CreateAnnotation.toggle"); |
|
126 }); |
|
127 this.$.find(".Ldt-Ctrl-SearchBtn").click(this.functionWrapper("searchButtonHandler")); |
|
128 |
|
129 this.$searchInput.keyup(this.functionWrapper("searchHandler")); |
|
130 this.$searchInput.on("search", this.functionWrapper("searchHandler")); |
|
131 |
|
132 // Fullscreen handling |
|
133 this.$.find(".Ldt-Ctrl-Fullscreen-Button").click(this.functionWrapper("toggleFullscreen")); |
|
134 var fullscreen_event_name = IriSP.getFullscreenEventname(); |
|
135 if (fullscreen_event_name) { |
|
136 document.addEventListener(fullscreen_event_name, function() { |
|
137 if (IriSP.isFullscreen() && IriSP.getFullscreenElement() == _this.$[0]) { |
|
138 _this.$.addClass("Ldt-Fullscreen-Element"); |
|
139 } else { |
|
140 _this.$.removeClass("Ldt-Fullscreen-Element"); |
|
141 } |
|
142 }); |
|
143 }; |
|
144 |
|
145 // Quiz activation |
|
146 this.$.find(".Ldt-Ctrl-Quiz-Enable").click(this.functionWrapper("toggleQuiz")); |
|
147 this.$.find(".Ldt-Ctrl-Quiz-Create").click(this.functionWrapper("createQuiz")); |
|
148 |
|
149 var _volctrl = this.$.find(".Ldt-Ctrl-Volume-Control"); |
|
150 this.$.find('.Ldt-Ctrl-Sound') |
|
151 .click(this.functionWrapper("muteHandler")) |
|
152 .mouseover(function() { |
|
153 _volctrl.show(); |
|
154 }) |
|
155 .mouseout(function() { |
|
156 _volctrl.hide(); |
|
157 }); |
|
158 _volctrl.mouseover(function() { |
|
159 _volctrl.show(); |
|
160 }).mouseout(function() { |
|
161 _volctrl.hide(); |
|
162 }); |
|
163 |
|
164 // Handle CTRL-F |
|
165 if (!this.disable_ctrl_f) { |
|
166 var _fKey = "F".charCodeAt(0), |
|
167 _lastCtrlFTime = 0; |
|
168 IriSP.jQuery(document).keydown(function(_event) { |
|
169 if (_event.keyCode === _fKey && (_event.ctrlKey || _event.metaKey)) { |
|
170 var _time = IriSP.jQuery.now(); |
|
171 if (_time - _lastCtrlFTime > 2000) { |
|
172 _this.searchButtonHandler(); |
|
173 } |
|
174 _lastCtrlFTime = _time; |
|
175 return false; |
|
176 } |
|
177 }); |
|
178 } |
|
179 |
|
180 // Allow Volume Cursor Dragging |
|
181 this.$volumeBar.slider({ |
|
182 slide: function(event, ui) { |
|
183 _this.$volumeBar.attr("title",_this.l10n.volume+': ' + ui.value + '%'); |
|
184 _this.media.setVolume(ui.value / 100); |
|
185 }, |
|
186 stop: this.functionWrapper("volumeUpdater") |
|
187 }); |
|
188 |
|
189 // trigger an IriSP.Player.MouseOver to the widgets that are interested (i.e : sliderWidget) |
|
190 this.$.hover( |
|
191 function() { |
|
192 _this.player.trigger("Player.MouseOver"); |
|
193 }, |
|
194 function() { |
|
195 _this.player.trigger("Player.MouseOut"); |
|
196 }); |
|
197 |
|
198 this.timeDisplayUpdater(new IriSP.Model.Time(0)); |
|
199 |
|
200 var annotations = this.source.getAnnotations(); |
|
201 annotations.on("search", function(_text) { |
|
202 _this.$searchInput.val(_text); |
|
203 _this.showSearchBlock(); |
|
204 }); |
|
205 annotations.on("found", function(_text) { |
|
206 _this.$searchInput.css('background-color','#e1ffe1'); |
|
207 }); |
|
208 annotations.on("not-found", function(_text) { |
|
209 _this.$searchInput.css('background-color', "#d62e3a"); |
|
210 }); |
|
211 annotations.on("search-cleared", function() { |
|
212 _this.hideSearchBlock(); |
|
213 }); |
|
214 if (_this.always_show_search) { |
|
215 _this.showSearchBlock(); |
|
216 } |
|
217 }; |
|
218 |
|
219 /* Update the elasped time div */ |
|
220 IriSP.Widgets.Controller.prototype.timeDisplayUpdater = function(_time) { |
|
221 |
|
222 // we get it at each call because it may change. |
|
223 var _totalTime = this.media.duration; |
|
224 this.$.find(".Ldt-Ctrl-Time-Elapsed").html(_time.toString()); |
|
225 this.$.find(".Ldt-Ctrl-Time-Total").html(_totalTime.toString()); |
|
226 }; |
|
227 |
|
228 /* update the icon of the button - separate function from playHandler |
|
229 because in some cases (for instance, when the user directly clicks on |
|
230 the jwplayer window) we have to change the icon without playing/pausing |
|
231 */ |
|
232 IriSP.Widgets.Controller.prototype.playButtonUpdater = function() { |
|
233 if (this.media.getPaused()) { |
|
234 /* the background sprite is changed by adding/removing the correct classes */ |
|
235 this.$playButton |
|
236 .attr("title", this.l10n.play) |
|
237 .removeClass("Ldt-Ctrl-Play-PauseState") |
|
238 .addClass("Ldt-Ctrl-Play-PlayState"); |
|
239 } else { |
|
240 this.$playButton |
|
241 .attr("title", this.l10n.pause) |
|
242 .removeClass("Ldt-Ctrl-Play-PlayState") |
|
243 .addClass("Ldt-Ctrl-Play-PauseState"); |
|
244 } |
|
245 }; |
|
246 |
|
247 //FullScreen |
|
248 IriSP.Widgets.Controller.prototype.toggleFullscreen = function() { |
|
249 if (IriSP.isFullscreen()) { |
|
250 IriSP.setFullScreen(this.$[0], false); |
|
251 } else { |
|
252 IriSP.setFullScreen(this.$[0], true); |
|
253 } |
|
254 }; |
|
255 |
|
256 //Quiz |
|
257 IriSP.Widgets.Controller.prototype.createQuiz = function() { |
|
258 this.player.trigger("Quiz.hide"); |
|
259 this.media.pause(); |
|
260 this.player.trigger("QuizCreator.create"); |
|
261 }; |
|
262 |
|
263 IriSP.Widgets.Controller.prototype.toggleQuiz = function() { |
|
264 this.enable_quiz_toggle = !this.enable_quiz_toggle; |
|
265 if (this.enable_quiz_toggle) { |
|
266 $(".Ldt-Ctrl-Quiz-Enable").addClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
267 $(".Ldt-Ctrl-Quiz-Create").addClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
268 this.player.trigger("Quiz.activate"); |
|
269 } |
|
270 else |
|
271 { |
|
272 $(".Ldt-Ctrl-Quiz-Enable").removeClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
273 $(".Ldt-Ctrl-Quiz-Create").removeClass("Ldt-Ctrl-Quiz-Toggle-Active"); |
|
274 this.player.trigger("Quiz.deactivate"); |
|
275 this.player.trigger("QuizCreator.hide"); |
|
276 } |
|
277 }; |
|
278 |
|
279 IriSP.Widgets.Controller.prototype.playHandler = function() { |
|
280 if (this.media.getPaused()) { |
|
281 this.media.play(); |
|
282 } else { |
|
283 this.media.pause(); |
|
284 } |
|
285 }; |
|
286 |
|
287 IriSP.Widgets.Controller.prototype.muteHandler = function() { |
|
288 this.media.setMuted(!this.media.getMuted()); |
|
289 }; |
|
290 |
|
291 IriSP.Widgets.Controller.prototype.volumeUpdater = function() { |
|
292 var _muted = this.media.getMuted(), |
|
293 _vol = this.media.getVolume(); |
|
294 if (_vol === false) { |
|
295 _vol = .5; |
|
296 } |
|
297 var _soundCtl = this.$.find(".Ldt-Ctrl-Sound"); |
|
298 _soundCtl.removeClass("Ldt-Ctrl-Sound-Mute Ldt-Ctrl-Sound-Half Ldt-Ctrl-Sound-Full"); |
|
299 if (_muted) { |
|
300 _soundCtl.attr("title", this.l10n.unmute) |
|
301 .addClass("Ldt-Ctrl-Sound-Mute"); |
|
302 } else { |
|
303 _soundCtl.attr("title", this.l10n.mute) |
|
304 .addClass(_vol < .5 ? "Ldt-Ctrl-Sound-Half" : "Ldt-Ctrl-Sound-Full" ); |
|
305 } |
|
306 this.$volumeBar.slider("value", _muted ? 0 : 100 * _vol); |
|
307 }; |
|
308 |
|
309 IriSP.Widgets.Controller.prototype.showSearchBlock = function() { |
|
310 this.$searchBlock.animate({ width:"160px" }, 200); |
|
311 this.$searchInput.css('background-color','#fff'); |
|
312 this.$searchInput.focus(); |
|
313 }; |
|
314 |
|
315 IriSP.Widgets.Controller.prototype.hideSearchBlock = function() { |
|
316 if (! this.always_show_search) { |
|
317 this.$searchBlock.animate( { width: 0 }, 200); |
|
318 } |
|
319 }; |
|
320 |
|
321 /** react to clicks on the search button */ |
|
322 IriSP.Widgets.Controller.prototype.searchButtonHandler = function() { |
|
323 if ( !this.$searchBlock.width() ) { |
|
324 this.showSearchBlock(); |
|
325 var _val = this.$searchInput.val(); |
|
326 if (_val) { |
|
327 this.source.getAnnotations().search(_val); |
|
328 } |
|
329 } else { |
|
330 this.hideSearchBlock(); |
|
331 } |
|
332 }; |
|
333 |
|
334 /** this handler is called whenever the content of the search |
|
335 field changes */ |
|
336 IriSP.Widgets.Controller.prototype.searchHandler = function() { |
|
337 if ( !this.$searchBlock.width() ) { |
|
338 this.$searchBlock.css({ width:"160px" }); |
|
339 this.$searchInput.css('background-color','#fff'); |
|
340 } |
|
341 var _val = this.$searchInput.val(); |
|
342 this._positiveMatch = false; |
|
343 |
|
344 // do nothing if the search field is empty, instead of highlighting everything. |
|
345 if (_val !== this.lastSearchValue) { |
|
346 if (_val) { |
|
347 this.source.getAnnotations().search(_val); |
|
348 } else { |
|
349 this.source.getAnnotations().trigger("clear-search"); |
|
350 this.$searchInput.css('background-color',''); |
|
351 } |
|
352 } |
|
353 this.lastSearchValue = _val; |
|
354 }; |
|