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