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.
8 Polymer('volume-controller', {
10 * Initializes an element. This method is called automatically when the
14 this.style
.width
= this.width
+ 'px';
15 this.style
.height
= this.height
+ 'px';
17 this.$.rawValueInput
.style
.width
= this.height
+ 'px';
18 this.$.rawValueInput
.style
.height
= this.width
+ 'px';
19 this.$.rawValueInput
.style
.webkitTransformOrigin
=
20 (this.width
/ 2) + 'px ' +
21 (this.width
/ 2 - 2) + 'px';
23 var barLeft
= (this.width
/ 2 - 1);
24 this.$.bar
.style
.left
= barLeft
+ 'px';
25 this.$.bar
.style
.right
= barLeft
+ 'px';
27 this.addEventListener('keydown', this.onKeyDown_
.bind(this));
31 * Registers handlers for changing of external variables
34 'model.volume': 'onVolumeChanged',
38 * Model object of the Audio Player.
39 * @type {AudioPlayerModel}
44 * Invoked when the model changed.
45 * @param {AudioPlayerModel} oldValue Old Value.
46 * @param {AudioPlayerModel} newValue New Value.
48 modelChanged: function(oldValue
, newValue
) {
49 this.onVolumeChanged((oldValue
|| {}).volume
, (newValue
|| {}).volume
);
53 * Volume. 0 is silent, and 100 is maximum.
59 * Volume. 1000 is silent, and 0 is maximum.
65 * Height of the element in pixels. Must be specified before ready() is
66 * called. Dynamic change is not supported.
72 * Width of the element in pixels. Must be specified before ready() is
73 * called. Dynamic change is not supported.
79 * Invoked when the 'volume' value in the model is changed.
80 * @param {number} oldValue Old value.
81 * @param {number} newValue New value.
83 onVolumeChanged: function(oldValue
, newValue
) {
84 if (oldValue
!= newValue
)
85 this.rawValue
= 100 - newValue
;
89 * Invoked when the 'rawValue' property is changed.
90 * @param {number} oldValue Old value.
91 * @param {number} newValue New value.
93 rawValueChanged: function(oldValue
, newValue
) {
94 if (oldValue
!= newValue
)
95 this.model
.volume
= 100 - newValue
;
99 * Invoked when the 'keydown' event is fired.
100 * @param {Event} event The event object.
102 onKeyDown_: function(event
) {
103 switch (event
.keyIdentifier
) {
104 // Prevents the default behavior. These key should be handled in
105 // <audio-player> element.
110 event
.preventDefault();
115 })(); // Anonymous closure