Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: ui/file_manager/audio_player/elements/track_list.js

Issue 1176483002: AudioPlayer.app: Migrate to Polymer 1.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/audio_player/elements/track_list.js
diff --git a/ui/file_manager/audio_player/elements/track_list.js b/ui/file_manager/audio_player/elements/track_list.js
index e887f177192195be9d29f5c38ea0e9c91cd0c546..a38e5743ac1c04edd234d0676e48a4aeb6fb8edb 100644
--- a/ui/file_manager/audio_player/elements/track_list.js
+++ b/ui/file_manager/audio_player/elements/track_list.js
@@ -12,6 +12,40 @@
var TrackListElement = function() {};
TrackListElement.prototype = {
+ is: 'track-list',
+
+ properties: {
+ /**
+ * List of tracks.
+ * @type {Array<AudioPlayer.TrackInfo>}
+ */
+ tracks: {
+ type: Array,
+ value: [],
+ observer: 'tracksChanged'
+ },
+
+ /**
+ * Track index of the current track.
+ * If the tracks property is empty, it should be -1. Otherwise, be a valid
+ * track number.
+ */
+ currentTrackIndex: {
+ type: Number,
+ value: -1,
+ observer: 'currentTrackIndexChanged',
+ notify: true
+ },
+
+ /**
+ * Whether shuffling play order is enabled or not.
+ */
+ shuffle: {
+ type: Boolean,
+ observer: 'shuffleChanged'
+ }
+ },
+
/**
* Initializes an element. This method is called automatically when the
* element is ready.
@@ -38,65 +72,37 @@
},
/**
- * Registers handlers for changing of external variables
- */
- observe: {
- 'model.shuffle': 'onShuffleChanged',
- },
-
- /**
- * Model object of the Audio Player.
- * @type {AudioPlayerModel}
- */
- model: null,
-
- /**
- * List of tracks.
- * @type {Array<AudioPlayer.TrackInfo>}
- */
- tracks: [],
-
- /**
* Play order of the tracks. Each value is the index of 'this.tracks'.
* @type {Array<number>}
*/
playOrder: [],
/**
- * Track index of the current track.
- * If the tracks property is empty, it should be -1. Otherwise, be a valid
- * track number.
- *
- * @type {number}
- */
- currentTrackIndex: -1,
-
- /**
* Invoked when 'shuffle' property is changed.
- * @param {boolean} oldValue Old value.
* @param {boolean} newValue New value.
+ * @param {boolean} oldValue Old value.
*/
- onShuffleChanged: function(oldValue, newValue) {
+ shuffleChanged: function(newValue, oldValue) {
this.generatePlayOrder(true /* keep the current track */);
},
/**
* Invoked when the current track index is changed.
- * @param {number} oldValue old value.
* @param {number} newValue new value.
+ * @param {number} oldValue old value.
*/
- currentTrackIndexChanged: function(oldValue, newValue) {
+ currentTrackIndexChanged: function(newValue, oldValue) {
if (oldValue === newValue)
return;
if (!isNaN(oldValue) && 0 <= oldValue && oldValue < this.tracks.length)
- this.tracks[oldValue].active = false;
+ this.set('tracks.' + oldValue + '.active', false);
if (0 <= newValue && newValue < this.tracks.length) {
var currentPlayOrder = this.playOrder.indexOf(newValue);
if (currentPlayOrder !== -1) {
// Success
- this.tracks[newValue].active = true;
+ this.set('tracks.' + newValue + '.active', true);
this.ensureTrackInViewport_(newValue /* trackIndex */);
return;
@@ -112,10 +118,10 @@
/**
* Invoked when 'tracks' property is changed.
- * @param {Array<AudioPlayer.TrackInfo>} oldValue Old value.
* @param {Array<AudioPlayer.TrackInfo>} newValue New value.
+ * @param {Array<AudioPlayer.TrackInfo>} oldValue Old value.
*/
- tracksChanged: function(oldValue, newValue) {
+ tracksChanged: function(newValue, oldValue) {
// Note: Sometimes both oldValue and newValue are null though the actual
// values are not null. Maybe it's a bug of Polymer.
@@ -126,7 +132,7 @@
// Restore the active track.
if (this.currentTrackIndex !== -1 &&
this.currentTrackIndex < this.tracks.length) {
- this.tracks[this.currentTrackIndex].active = true;
+ this.set('tracks.' + this.currentTrackIndex + '.active', true);
}
// Reset play order and current index.
@@ -145,7 +151,7 @@
if (this.tracks.length === 0)
this.currentTrackIndex = -1;
else
- this.tracks[this.currentTrackIndex].active = true;
+ this.set('tracks.' + this.currentTrackIndex + '.active', true);
},
/**
@@ -212,7 +218,7 @@
this.tracks.
map(function(unused, index) { return index; });
- if (this.model && this.model.shuffle) {
+ if (this.shuffle) {
// Randomizes the play order array (Schwarzian-transform algorithm).
this.playOrder = this.playOrder
.map(function(a) {
@@ -312,5 +318,5 @@
},
}; // TrackListElement.prototype for 'track-list'
- Polymer('track-list', TrackListElement.prototype);
+ Polymer(TrackListElement.prototype);
})(); // Anonymous closure

Powered by Google App Engine
This is Rietveld 408576698