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';
29 * Converts the time into human friendly string.
30 * @param {number} time Time to be converted.
31 * @return {string} String representation of the given time
33 function time2string(time
) {
34 return ~~(time
/ 60000) + ':' + ('0' + ~~(time
/ 1000 % 60)).slice(-2);
37 Polymer('control-panel', {
39 * Initializes an element. This method is called automatically when the
43 var onFocusoutBound
= this.onVolumeControllerFocusout_
.bind(this);
44 this.$.volumeSlider
.addEventListener('focusout', onFocusoutBound
);
45 this.$.volumeButton
.addEventListener('focusout', onFocusoutBound
);
49 * Model object of the Audio Player.
50 * @type {AudioPlayerModel}
55 * Invoked when the model changed.
56 * @param {AudioPlayerModel} oldValue Old Value.
57 * @param {AudioPlayerModel} newValue New Value.
59 modelChanged: function(oldValue
, newValue
) {
60 this.$.volumeSlider
.model
= newValue
;
64 * Current elapsed time in the current music in millisecond.
70 * String representation of 'time'.
75 return time2string(this.time
);
79 * Total length of the current music in millisecond.
85 * String representation of 'duration'.
89 get durationString_() {
90 return time2string(this.duration
);
94 * Flag whether the volume slider is expanded or not.
97 volumeSliderShown
: false,
100 * Flag whether the audio is playing or paused. True if playing, or false
107 * Invoked when the 'duration' property is changed.
108 * @param {number} oldValue old value.
109 * @param {number} newValue new value.
111 durationChanged: function(oldValue
, newValue
) {
112 // Reset the current playback position.
117 * Invoked when the next button is clicked.
119 nextClick: function() {
120 this.fire('next-clicked');
124 * Invoked when the play button is clicked.
126 playClick: function() {
127 this.playing
= !this.playing
;
131 * Invoked when the previous button is clicked.
133 previousClick: function() {
134 this.fire('previous-clicked');
138 * Invoked the volume button is clicked.
139 * @type {Event} event The event.
141 volumeButtonClick: function(event
) {
142 this.showVolumeController_(this.volumeSliderShown
);
143 event
.stopPropagation();
147 * Invoked when the focus goes out of the volume elements.
148 * @param {FocusEvent} event The focusout event.
151 onVolumeControllerFocusout_: function(event
) {
152 if (this.volumeSliderShown
) {
153 // If the focus goes out of the volume, hide the volume control.
154 if (!event
.relatedTarget
||
155 (event
.relatedTarget
!== this.$.volumeButton
&&
156 event
.relatedTarget
!== this.$.volumeSlider
)) {
157 this.showVolumeController_(false);
158 this.volumeSliderShown
= false;
164 * Shows/hides the volume controller.
165 * @param {boolean} show True to show the controller, false to hide.
168 showVolumeController_: function(show
) {
170 matchBottomLine(this.$.volumeContainer
, this.$.volumeButton
);
171 this.$.volumeContainer
.style
.visibility
= 'visible';
173 this.$.volumeContainer
.style
.visibility
= 'hidden';
177 })(); // Anonymous closure