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
3 // found in the LICENSE file.
9 * Moves |target| element above |anchor| element, in order to match the
11 * @param {HTMLElement} target Target element.
12 * @param {HTMLElement} anchor Anchor element.
14 function matchBottomLine(target
, anchor
) {
15 var targetRect
= target
.getBoundingClientRect();
16 var anchorRect
= anchor
.getBoundingClientRect();
19 left
: anchorRect
.left
+ anchorRect
.width
/ 2 - targetRect
.width
/ 2,
20 bottom
: window
.innerHeight
- anchorRect
.bottom
,
23 target
.style
.position
= 'fixed';
24 target
.style
.left
= pos
.left
+ 'px';
25 target
.style
.bottom
= pos
.bottom
+ 'px';
33 * Flag whether the audio is playing or paused. True if playing, or false
43 * Current elapsed time in the current music in millisecond.
52 * Total length of the current music in millisecond.
60 * Whether the shuffle button is ON.
69 * Whether the repeat button is ON.
78 * The audio volume. 0 is silent, and 100 is maximum loud.
86 * Whether the expanded button is ON.
95 * Whether the volume slider is expanded or not.
100 observer
: 'volumeSliderShownChanged',
106 * Initializes an element. This method is called automatically when the
110 var onFocusoutBound
= this.onVolumeControllerFocusout_
.bind(this);
112 this.$.volumeSlider
.addEventListener('focusout', onFocusoutBound
);
113 this.$.volumeButton
.addEventListener('focusout', onFocusoutBound
);
115 // Prevent the time slider from being moved by arrow keys.
116 this.$.timeInput
.addEventListener('keydown', function(event
) {
117 switch (event
.keyCode
) {
118 case 37: // Left arrow
120 case 39: // Right arrow
121 case 40: // Down arrow
122 event
.preventDefault();
129 * Invoked when the next button is clicked.
131 nextClick: function() {
132 this.fire('next-clicked');
136 * Invoked when the play button is clicked.
138 playClick: function() {
139 this.playing
= !this.playing
;
143 * Invoked when the previous button is clicked.
145 previousClick: function() {
146 this.fire('previous-clicked');
150 * Invoked when the property 'volumeSliderShown' changes.
151 * @param {boolean} shown
153 volumeSliderShownChanged: function(shown
) {
154 this.showVolumeController_(shown
);
158 * Invoked when the focus goes out of the volume elements.
159 * @param {!UIEvent} event The focusout event.
162 onVolumeControllerFocusout_: function(event
) {
163 if (this.volumeSliderShown
) {
164 // If the focus goes out of the volume, hide the volume control.
165 if (!event
.relatedTarget
||
166 (event
.relatedTarget
!== this.$.volumeButton
&&
167 event
.relatedTarget
!== this.$.volumeSlider
)) {
168 this.volumeSliderShown
= false;
174 * Shows/hides the volume controller.
175 * @param {boolean} show True to show the controller, false to hide.
178 showVolumeController_: function(show
) {
180 matchBottomLine(this.$.volumeContainer
, this.$.volumeButton
);
181 this.$.volumeContainer
.style
.visibility
= 'visible';
183 this.$.volumeContainer
.style
.visibility
= 'hidden';
188 * Converts the time into human friendly string.
189 * @param {number} time Time to be converted.
190 * @return {string} String representation of the given time
192 time2string_: function(time
) {
193 return ~~(time
/ 60000) + ':' + ('0' + ~~(time
/ 1000 % 60)).slice(-2);
197 * Computes state for play button based on 'playing' property.
200 computePlayState_: function(playing
) {
201 return playing
? "playing" : "ended";
205 * Computes style for '.filled' element of progress bar.
208 computeProgressBarStyle_: function(time
, duration
) {
209 return 'width: ' + (time
/ duration
* 100) + '%;';
212 })(); // Anonymous closure