Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Cpyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 (function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 /** | |
| 9 * Move |target| element above |anchor| element, in order to match the | |
|
mtomasz
2014/01/27 01:09:24
nit: Move -> Moves
yoshiki
2014/01/27 07:12:08
Done.
| |
| 10 * bottom lines. | |
| 11 * @param {HTMLElement} target Target element. | |
| 12 * @param {HTMLElement} anchor Anchor element. | |
| 13 */ | |
| 14 function matchBottomLine(target, anchor) { | |
| 15 var targetRect = target.getBoundingClientRect(); | |
| 16 var anchorRect = anchor.getBoundingClientRect(); | |
| 17 | |
| 18 var pos = { | |
| 19 left: anchorRect.left + anchorRect.width / 2 - targetRect.width / 2, | |
| 20 bottom: window.innerHeight - anchorRect.bottom, | |
| 21 }; | |
| 22 | |
| 23 target.style.position = 'fixed'; | |
| 24 target.style.left = pos.left + 'px'; | |
| 25 target.style.bottom = pos.bottom + 'px'; | |
| 26 } | |
| 27 | |
| 28 /** | |
| 29 * Convert the time into human friendly string. | |
| 30 * @param {number} time Time to be converted. | |
| 31 * @return {string} String representation of the given time | |
| 32 */ | |
| 33 function time2string(time) { | |
| 34 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); | |
| 35 } | |
| 36 | |
| 37 Polymer('control-panel', { | |
| 38 /** | |
| 39 * Initialize an element. This method is called automatically when the | |
| 40 * element is ready. | |
| 41 */ | |
| 42 ready: function() { | |
| 43 this.$.volumeSlider.value = this.volume || 50; | |
| 44 this.$.playlistButton.querySelector('input').checked = | |
| 45 this.playlistExpanded; | |
| 46 }, | |
| 47 | |
| 48 /** | |
| 49 * Current elapsed time in the current music in millisecond. | |
| 50 * @type {number} | |
| 51 */ | |
| 52 time: 0, | |
| 53 | |
| 54 /** | |
| 55 * String representation of 'time'. | |
| 56 * @type {number} | |
| 57 * @private | |
| 58 */ | |
| 59 get timeString_() { | |
| 60 return time2string(this.time); | |
| 61 }, | |
| 62 | |
| 63 /** | |
| 64 * Total length of the current music in millisecond. | |
| 65 * @type {number} | |
| 66 */ | |
| 67 duration: 0, | |
| 68 | |
| 69 /** | |
| 70 * String representation of 'duration'. | |
| 71 * @type {string} | |
| 72 * @private | |
| 73 */ | |
| 74 get durationString_() { | |
| 75 return time2string(this.duration); | |
| 76 }, | |
| 77 | |
| 78 /** | |
| 79 * Current volume. Must be between 0 to 100. | |
| 80 * @type {number} | |
| 81 */ | |
| 82 volume: 50, | |
| 83 | |
| 84 /** | |
| 85 * Flag whether the playlist is expanded or not. | |
| 86 * @type {boolean} | |
| 87 */ | |
| 88 playlistExpanded: true, | |
| 89 | |
| 90 /** | |
| 91 * Flag whether the volume slider is expanded or not. | |
| 92 * @type {boolean} | |
| 93 */ | |
| 94 volumeSliderShown: false, | |
| 95 | |
| 96 /** | |
| 97 * Flag to enable shuffle mode. | |
| 98 * @type {boolean} | |
| 99 */ | |
| 100 shuffle: false, | |
| 101 | |
| 102 /* | |
| 103 * Flag to enable repeat mode. | |
| 104 * @type {boolean} | |
| 105 */ | |
| 106 repeat: false, | |
| 107 | |
| 108 /* | |
| 109 * Flag if the audio is playing or paused. True if playing, or false paused. | |
| 110 * @type {boolean} | |
| 111 */ | |
| 112 playing: false, | |
| 113 | |
| 114 /** | |
| 115 * Invoked when the 'playlistExpanded' property is changed. | |
| 116 * @param {boolean} oldValue old value. | |
| 117 * @param {boolean} newValue new value. | |
| 118 */ | |
| 119 playlistExpandedChanged: function(oldValue, newValue) { | |
| 120 this.$.playlistButton.querySelector('input').checked = !!newValue; | |
| 121 }, | |
| 122 | |
| 123 /** | |
| 124 * Invoked when the 'duration' property is changed. | |
| 125 * @param {number} oldValue old value. | |
| 126 * @param {number} newValue new value. | |
| 127 */ | |
| 128 durationChanged: function(oldValue, newValue) { | |
| 129 // Reset the current playback position. | |
| 130 this.time = 0; | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 134 * Invoked when the next button is clicked. | |
| 135 */ | |
| 136 nextClick: function() { | |
| 137 this.fire('next-clicked'); | |
| 138 }, | |
| 139 | |
| 140 /** | |
| 141 * Invoked when the play button is clicked. | |
| 142 */ | |
| 143 playClick: function() { | |
| 144 this.playing = !this.playing; | |
| 145 }, | |
| 146 | |
| 147 /** | |
| 148 * Invoked when the previous button is clicked. | |
| 149 */ | |
| 150 previousClick: function() { | |
| 151 this.fire('next-clicked'); | |
| 152 }, | |
| 153 | |
| 154 /** | |
| 155 * Invoked the volume button is clicked. | |
| 156 * @type {Event} event The event. | |
| 157 */ | |
| 158 volumeButtonClick: function(event) { | |
| 159 if (this.volumeSliderShown) { | |
| 160 matchBottomLine(this.$.volumeContainer, this.$.volumeButton); | |
| 161 this.$.volumeContainer.style.visibility = 'visible'; | |
| 162 } else { | |
| 163 this.$.volumeContainer.style.visibility = 'hidden'; | |
| 164 } | |
| 165 event.stopPropagation(); | |
| 166 }, | |
| 167 | |
| 168 /** | |
| 169 * Invoked the value of the volume slider is changed. | |
| 170 * @type {number} | |
| 171 */ | |
| 172 volumeSliderChanged: function() { | |
| 173 this.volume = this.$.volumeSlider.value; | |
| 174 this.fire('volume-changed'); | |
| 175 }, | |
| 176 }); | |
| 177 })(); // Anonymous closure | |
| OLD | NEW |