| 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 if (event.target.classList.contains('icon')) { | 170 this.selectTrack(track); |
| 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 } | |
| 178 }, | 171 }, |
| 179 | 172 |
| 180 /** | 173 /** |
| 181 * Invoked when the window is resized. | 174 * Invoked when the window is resized. |
| 182 * @private | 175 * @private |
| 183 */ | 176 */ |
| 184 onWindowResize_: function() { | 177 onWindowResize_: function() { |
| 185 this.ensureTrackInViewport_(this.currentTrackIndex); | 178 this.ensureTrackInViewport_(this.currentTrackIndex); |
| 186 }, | 179 }, |
| 187 | 180 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 243 } |
| 251 | 244 |
| 252 if (!keepCurrentTrack) | 245 if (!keepCurrentTrack) |
| 253 this.currentTrackIndex = this.playOrder[0]; | 246 this.currentTrackIndex = this.playOrder[0]; |
| 254 }, | 247 }, |
| 255 | 248 |
| 256 /** | 249 /** |
| 257 * Sets the current track. | 250 * Sets the current track. |
| 258 * @param {!TrackInfo} track TrackInfo to be set as the current | 251 * @param {!TrackInfo} track TrackInfo to be set as the current |
| 259 * track. | 252 * track. |
| 260 * @param {boolean} forcePlay True if the track should be played regardless | |
| 261 * of the current play state (paused/played). | |
| 262 */ | 253 */ |
| 263 selectTrack: function(track, forcePlay) { | 254 selectTrack: function(track) { |
| 264 var index = -1; | 255 var index = -1; |
| 265 for (var i = 0; i < this.tracks.length; i++) { | 256 for (var i = 0; i < this.tracks.length; i++) { |
| 266 if (this.tracks[i].url === track.url) { | 257 if (this.tracks[i].url === track.url) { |
| 267 index = i; | 258 index = i; |
| 268 break; | 259 break; |
| 269 } | 260 } |
| 270 } | 261 } |
| 271 if (index >= 0) { | 262 if (index >= 0) { |
| 272 // TODO(yoshiki): Clean up the flow and the code around here. | 263 // TODO(yoshiki): Clean up the flow and the code around here. |
| 273 if (this.currentTrackIndex === index) { | 264 if (this.currentTrackIndex == index) |
| 274 this.replayCurrentTrack(); | 265 this.replayCurrentTrack(); |
| 275 } else { | 266 else |
| 276 this.currentTrackIndex = index; | 267 this.currentTrackIndex = index; |
| 277 if (forcePlay) | |
| 278 this.fire('play'); | |
| 279 } | |
| 280 } | 268 } |
| 281 }, | 269 }, |
| 282 | 270 |
| 283 /** | 271 /** |
| 284 * Request to replay the current music. | 272 * Request to replay the current music. |
| 285 */ | 273 */ |
| 286 replayCurrentTrack: function() { | 274 replayCurrentTrack: function() { |
| 287 this.fire('replay'); | 275 this.fire('replay'); |
| 288 }, | 276 }, |
| 289 | 277 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 316 |
| 329 var newTrackIndex = this.playOrder[newPlayOrder]; | 317 var newTrackIndex = this.playOrder[newPlayOrder]; |
| 330 console.assert( | 318 console.assert( |
| 331 (0 <= newTrackIndex && newTrackIndex < this.tracks.length), | 319 (0 <= newTrackIndex && newTrackIndex < this.tracks.length), |
| 332 'Insufficient TrackList.playOrder. New Play Order: ' + newPlayOrder); | 320 'Insufficient TrackList.playOrder. New Play Order: ' + newPlayOrder); |
| 333 | 321 |
| 334 return newTrackIndex; | 322 return newTrackIndex; |
| 335 }, | 323 }, |
| 336 }); | 324 }); |
| 337 })(); // Anonymous closure | 325 })(); // Anonymous closure |
| OLD | NEW |