2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 The `core-range` element is used for managing a numeric value within a given
12 range. It has no visual appearance and is typically used in conjunction with
15 One can build a progress bar using `core-range` like this:
17 <core-range min="0" max="200" value="100" ratio="{{ratio}}"></core-range>
18 <div class="progress-bar" style="width: {{ratio}}%;"></div>
20 @group Polymer Core Elements
26 <link rel=
"import" href=
"../polymer/polymer.html">
28 <polymer-element name=
"core-range" attributes=
"value min max step ratio">
31 Polymer('core-range', {
34 * The number that represents the current value.
43 * The number that indicates the minimum value of the range.
52 * The number that indicates the maximum value of the range.
61 * Specifies the value granularity of the range's value.
70 * Returns the ratio of the value.
79 'value min max step': 'update'
82 calcRatio: function(value
) {
83 return (this.clampValue(value
) - this.min
) / (this.max
- this.min
);
86 clampValue: function(value
) {
87 return Math
.min(this.max
, Math
.max(this.min
, this.calcStep(value
)));
90 calcStep: function(value
) {
91 return this.step
? (Math
.round(value
/ this.step
) / (1 / this.step
)) : value
;
94 validateValue: function() {
95 var v
= this.clampValue(this.value
);
96 this.value
= this.oldValue
= isNaN(v
) ? this.oldValue
: v
;
97 return this.value
!== v
;
101 this.validateValue();
102 this.ratio
= this.calcRatio(this.value
) * 100;