| 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 (function() { | 5 (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** |
| 9 * Moves |target| element above |anchor| element, in order to match the |
| 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 |
| 8 Polymer({ | 28 Polymer({ |
| 9 is: 'control-panel', | 29 is: 'control-panel', |
| 10 | 30 |
| 11 properties: { | 31 properties: { |
| 12 /** | 32 /** |
| 13 * Flag whether the audio is playing or paused. True if playing, or false | 33 * Flag whether the audio is playing or paused. True if playing, or false |
| 14 * paused. | 34 * paused. |
| 15 */ | 35 */ |
| 16 playing: { | 36 playing: { |
| 17 type: Boolean, | 37 type: Boolean, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 value: false, | 90 value: false, |
| 71 notify: true | 91 notify: true |
| 72 }, | 92 }, |
| 73 | 93 |
| 74 /** | 94 /** |
| 75 * Whether the volume slider is expanded or not. | 95 * Whether the volume slider is expanded or not. |
| 76 */ | 96 */ |
| 77 volumeSliderShown: { | 97 volumeSliderShown: { |
| 78 type: Boolean, | 98 type: Boolean, |
| 79 value: false, | 99 value: false, |
| 80 notify: true, | 100 observer: 'volumeSliderShownChanged', |
| 81 reflectToAttribute: true | 101 notify: true |
| 82 }, | 102 }, |
| 83 | 103 |
| 84 /** | 104 /** |
| 85 * Whether the knob of time slider is being dragged. | 105 * Whether the knob of time slider is being dragged. |
| 86 */ | 106 */ |
| 87 dragging: { | 107 dragging: { |
| 88 type: Boolean, | 108 type: Boolean, |
| 89 value: false, | 109 value: false, |
| 90 notify: true | 110 notify: true |
| 91 } | 111 } |
| 92 }, | 112 }, |
| 93 | 113 |
| 94 /** | 114 /** |
| 95 * Initializes an element. This method is called automatically when the | 115 * Initializes an element. This method is called automatically when the |
| 96 * element is ready. | 116 * element is ready. |
| 97 */ | 117 */ |
| 98 ready: function() { | 118 ready: function() { |
| 119 var onFocusoutBound = this.onVolumeControllerFocusout_.bind(this); |
| 120 |
| 121 this.$.volumeSlider.addEventListener('focusout', onFocusoutBound); |
| 122 this.$.volumeButton.addEventListener('focusout', onFocusoutBound); |
| 123 |
| 99 this.$.timeSlider.addEventListener('value-change', function() { | 124 this.$.timeSlider.addEventListener('value-change', function() { |
| 100 if (this.dragging) | 125 if (this.dragging) |
| 101 this.dragging = false; | 126 this.dragging = false; |
| 102 }.bind(this)); | 127 }.bind(this)); |
| 103 this.$.timeSlider.addEventListener('immediate-value-change', function() { | 128 this.$.timeSlider.addEventListener('immediate-value-change', function() { |
| 104 if (!this.dragging) | 129 if (!this.dragging) |
| 105 this.dragging = true; | 130 this.dragging = true; |
| 106 }.bind(this)); | 131 }.bind(this)); |
| 107 }, | 132 }, |
| 108 | 133 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 121 }, | 146 }, |
| 122 | 147 |
| 123 /** | 148 /** |
| 124 * Invoked when the previous button is clicked. | 149 * Invoked when the previous button is clicked. |
| 125 */ | 150 */ |
| 126 previousClick: function() { | 151 previousClick: function() { |
| 127 this.fire('previous-clicked'); | 152 this.fire('previous-clicked'); |
| 128 }, | 153 }, |
| 129 | 154 |
| 130 /** | 155 /** |
| 156 * Invoked when the property 'volumeSliderShown' changes. |
| 157 * @param {boolean} shown |
| 158 */ |
| 159 volumeSliderShownChanged: function(shown) { |
| 160 this.showVolumeController_(shown); |
| 161 }, |
| 162 |
| 163 /** |
| 164 * Invoked when the focus goes out of the volume elements. |
| 165 * @param {!UIEvent} event The focusout event. |
| 166 * @private |
| 167 */ |
| 168 onVolumeControllerFocusout_: function(event) { |
| 169 if (this.volumeSliderShown) { |
| 170 // If the focus goes out of the volume, hide the volume control. |
| 171 if (!event.relatedTarget || |
| 172 (!this.$.volumeButton.contains(event.relatedTarget) && |
| 173 !this.$.volumeSlider.contains(event.relatedTarget))) { |
| 174 this.volumeSliderShown = false; |
| 175 } |
| 176 } |
| 177 }, |
| 178 |
| 179 /** |
| 180 * Shows/hides the volume controller. |
| 181 * @param {boolean} show True to show the controller, false to hide. |
| 182 * @private |
| 183 */ |
| 184 showVolumeController_: function(show) { |
| 185 if (show) { |
| 186 matchBottomLine(this.$.volumeContainer, this.$.volumeButton); |
| 187 this.$.volumeContainer.style.visibility = 'visible'; |
| 188 } else { |
| 189 this.$.volumeContainer.style.visibility = 'hidden'; |
| 190 } |
| 191 }, |
| 192 |
| 193 /** |
| 131 * Converts the time into human friendly string. | 194 * Converts the time into human friendly string. |
| 132 * @param {number} time Time to be converted. | 195 * @param {number} time Time to be converted. |
| 133 * @return {string} String representation of the given time | 196 * @return {string} String representation of the given time |
| 134 */ | 197 */ |
| 135 time2string_: function(time) { | 198 time2string_: function(time) { |
| 136 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); | 199 return ~~(time / 60000) + ':' + ('0' + ~~(time / 1000 % 60)).slice(-2); |
| 137 }, | 200 }, |
| 138 | 201 |
| 139 /** | 202 /** |
| 140 * Converts the time and duration into human friendly string. | 203 * Converts the time and duration into human friendly string. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 156 | 219 |
| 157 /** | 220 /** |
| 158 * Computes style for '.filled' element of progress bar. | 221 * Computes style for '.filled' element of progress bar. |
| 159 * @return {string} | 222 * @return {string} |
| 160 */ | 223 */ |
| 161 computeProgressBarStyle_: function(time, duration) { | 224 computeProgressBarStyle_: function(time, duration) { |
| 162 return 'width: ' + (time / duration * 100) + '%;'; | 225 return 'width: ' + (time / duration * 100) + '%;'; |
| 163 } | 226 } |
| 164 }); | 227 }); |
| 165 })(); // Anonymous closure | 228 })(); // Anonymous closure |
| OLD | NEW |