OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @typedef {?{ | 6 * @typedef {?{ |
7 * url: string, | 7 * url: string, |
8 * title: string, | 8 * title: string, |
9 * artist: string, | 9 * artist: string, |
10 * artwork: Object, | 10 * artwork: Object, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 this.set('tracks.' + this.currentTrackIndex + '.active', true); | 159 this.set('tracks.' + this.currentTrackIndex + '.active', true); |
160 }, | 160 }, |
161 | 161 |
162 /** | 162 /** |
163 * Invoked when the track element is clicked. | 163 * Invoked when the track element is clicked. |
164 * @param {Event} event Click event. | 164 * @param {Event} event Click event. |
165 */ | 165 */ |
166 trackClicked: function(event) { | 166 trackClicked: function(event) { |
167 var index = ~~event.currentTarget.getAttribute('index'); | 167 var index = ~~event.currentTarget.getAttribute('index'); |
168 var track = this.tracks[index]; | 168 var track = this.tracks[index]; |
169 if (track) | 169 if (track) { |
170 this.selectTrack(track); | 170 if (event.target.classList.contains('icon')) { |
171 // If the play icon on the track is clicked, change the current track | |
172 // and start playing it regardless of current play state. | |
173 this.selectTrack(track, true /* force to play */); | |
174 } else { | |
175 this.selectTrack(track, false /* force to play */); | |
176 } | |
177 } | |
171 }, | 178 }, |
172 | 179 |
173 /** | 180 /** |
174 * Invoked when the window is resized. | 181 * Invoked when the window is resized. |
175 * @private | 182 * @private |
176 */ | 183 */ |
177 onWindowResize_: function() { | 184 onWindowResize_: function() { |
178 this.ensureTrackInViewport_(this.currentTrackIndex); | 185 this.ensureTrackInViewport_(this.currentTrackIndex); |
179 }, | 186 }, |
180 | 187 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 } | 250 } |
244 | 251 |
245 if (!keepCurrentTrack) | 252 if (!keepCurrentTrack) |
246 this.currentTrackIndex = this.playOrder[0]; | 253 this.currentTrackIndex = this.playOrder[0]; |
247 }, | 254 }, |
248 | 255 |
249 /** | 256 /** |
250 * Sets the current track. | 257 * Sets the current track. |
251 * @param {!TrackInfo} track TrackInfo to be set as the current | 258 * @param {!TrackInfo} track TrackInfo to be set as the current |
252 * track. | 259 * track. |
260 * @param {boolean} forcePlay True if the track should be played regardless | |
yawano
2015/11/18 18:17:29
small optional nit: forcePlay -> forceToPlay.
fukino
2015/11/19 02:14:39
Done.
| |
261 * of the current play state (paused/played). | |
253 */ | 262 */ |
254 selectTrack: function(track) { | 263 selectTrack: function(track, forcePlay) { |
255 var index = -1; | 264 var index = -1; |
256 for (var i = 0; i < this.tracks.length; i++) { | 265 for (var i = 0; i < this.tracks.length; i++) { |
257 if (this.tracks[i].url === track.url) { | 266 if (this.tracks[i].url === track.url) { |
258 index = i; | 267 index = i; |
259 break; | 268 break; |
260 } | 269 } |
261 } | 270 } |
262 if (index >= 0) { | 271 if (index >= 0) { |
263 // TODO(yoshiki): Clean up the flow and the code around here. | 272 // TODO(yoshiki): Clean up the flow and the code around here. |
264 if (this.currentTrackIndex == index) | 273 if (this.currentTrackIndex === index) { |
265 this.replayCurrentTrack(); | 274 this.replayCurrentTrack(); |
266 else | 275 } else { |
267 this.currentTrackIndex = index; | 276 this.currentTrackIndex = index; |
277 if (forcePlay) | |
278 this.fire('play'); | |
279 } | |
268 } | 280 } |
269 }, | 281 }, |
270 | 282 |
271 /** | 283 /** |
272 * Request to replay the current music. | 284 * Request to replay the current music. |
273 */ | 285 */ |
274 replayCurrentTrack: function() { | 286 replayCurrentTrack: function() { |
275 this.fire('replay'); | 287 this.fire('replay'); |
276 }, | 288 }, |
277 | 289 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 | 328 |
317 var newTrackIndex = this.playOrder[newPlayOrder]; | 329 var newTrackIndex = this.playOrder[newPlayOrder]; |
318 console.assert( | 330 console.assert( |
319 (0 <= newTrackIndex && newTrackIndex < this.tracks.length), | 331 (0 <= newTrackIndex && newTrackIndex < this.tracks.length), |
320 'Insufficient TrackList.playOrder. New Play Order: ' + newPlayOrder); | 332 'Insufficient TrackList.playOrder. New Play Order: ' + newPlayOrder); |
321 | 333 |
322 return newTrackIndex; | 334 return newTrackIndex; |
323 }, | 335 }, |
324 }); | 336 }); |
325 })(); // Anonymous closure | 337 })(); // Anonymous closure |
OLD | NEW |