|
8 | 8 | -->
|
9 | 9 |
|
10 | 10 | <!--
|
11 |
| -
|
12 | 11 | The `core-range` element is used for managing a numberic value within a given
|
13 | 12 | range. It has no visual appearance and is typically used in conjunciton with
|
14 | 13 | another element.
|
|
27 | 26 | <link rel="import" href="../polymer/polymer.html">
|
28 | 27 |
|
29 | 28 | <polymer-element name="core-range" attributes="value min max step ratio">
|
| 29 | +<script> |
30 | 30 |
|
31 |
| - <script> |
32 |
| - |
33 |
| - Polymer('core-range', { |
34 |
| - |
35 |
| - /** |
36 |
| - * The number that represents the current value. |
37 |
| - * |
38 |
| - * @attribute value |
39 |
| - * @type number |
40 |
| - * @default 0 |
41 |
| - */ |
42 |
| - value: 0, |
43 |
| - |
44 |
| - /** |
45 |
| - * The number that indicates the minimum value of the range. |
46 |
| - * |
47 |
| - * @attribute min |
48 |
| - * @type number |
49 |
| - * @default 0 |
50 |
| - */ |
51 |
| - min: 0, |
52 |
| - |
53 |
| - /** |
54 |
| - * The number that indicates the maximum value of the range. |
55 |
| - * |
56 |
| - * @attribute max |
57 |
| - * @type number |
58 |
| - * @default 100 |
59 |
| - */ |
60 |
| - max: 100, |
61 |
| - |
62 |
| - /** |
63 |
| - * Specifies the value granularity of the range's value. |
64 |
| - * |
65 |
| - * @attribute step |
66 |
| - * @type number |
67 |
| - * @default 1 |
68 |
| - */ |
69 |
| - step: 1, |
70 |
| - |
71 |
| - /** |
72 |
| - * Returns the ratio of the value. |
73 |
| - * |
74 |
| - * @attribute ratio |
75 |
| - * @type number |
76 |
| - * @default 0 |
77 |
| - */ |
78 |
| - ratio: 0, |
79 |
| - |
80 |
| - observe: { |
81 |
| - 'value min max step': 'update' |
82 |
| - }, |
83 |
| - |
84 |
| - calcRatio: function(value) { |
85 |
| - return (value - this.min) / (this.max - this.min); |
86 |
| - }, |
87 |
| - |
88 |
| - clampValue: function(value) { |
89 |
| - return Math.min(this.max, Math.max(this.min, this.calcStep(value))); |
90 |
| - }, |
91 |
| - |
92 |
| - calcStep: function(value) { |
93 |
| - return this.step ? (Math.round(value / this.step) * this.step) : value; |
94 |
| - }, |
95 |
| - |
96 |
| - validateValue: function() { |
97 |
| - var v = this.clampValue(this.value); |
98 |
| - this.value = this.oldValue = isNaN(v) ? this.oldValue : v; |
99 |
| - return this.value !== v; |
100 |
| - }, |
101 |
| - |
102 |
| - update: function() { |
103 |
| - this.validateValue(); |
104 |
| - this.ratio = this.calcRatio(this.value) * 100; |
105 |
| - } |
106 |
| - |
107 |
| - }); |
| 31 | + Polymer('core-range', { |
| 32 | + |
| 33 | + /** |
| 34 | + * The number that represents the current value. |
| 35 | + * |
| 36 | + * @attribute value |
| 37 | + * @type number |
| 38 | + * @default 0 |
| 39 | + */ |
| 40 | + value: 0, |
| 41 | + |
| 42 | + /** |
| 43 | + * The number that indicates the minimum value of the range. |
| 44 | + * |
| 45 | + * @attribute min |
| 46 | + * @type number |
| 47 | + * @default 0 |
| 48 | + */ |
| 49 | + min: 0, |
| 50 | + |
| 51 | + /** |
| 52 | + * The number that indicates the maximum value of the range. |
| 53 | + * |
| 54 | + * @attribute max |
| 55 | + * @type number |
| 56 | + * @default 100 |
| 57 | + */ |
| 58 | + max: 100, |
| 59 | + |
| 60 | + /** |
| 61 | + * Specifies the value granularity of the range's value. |
| 62 | + * |
| 63 | + * @attribute step |
| 64 | + * @type number |
| 65 | + * @default 1 |
| 66 | + */ |
| 67 | + step: 1, |
| 68 | + |
| 69 | + /** |
| 70 | + * Returns the ratio of the value. |
| 71 | + * |
| 72 | + * @attribute ratio |
| 73 | + * @type number |
| 74 | + * @default 0 |
| 75 | + */ |
| 76 | + ratio: 0, |
| 77 | + |
| 78 | + observe: { |
| 79 | + 'value min max step': 'update' |
| 80 | + }, |
| 81 | + |
| 82 | + calcRatio: function(value) { |
| 83 | + return (value - this.min) / (this.max - this.min); |
| 84 | + }, |
| 85 | + |
| 86 | + clampValue: function(value) { |
| 87 | + return Math.min(this.max, Math.max(this.min, this.calcStep(value))); |
| 88 | + }, |
| 89 | + |
| 90 | + calcStep: function(value) { |
| 91 | + return this.step ? (Math.round(value / this.step) * this.step) : value; |
| 92 | + }, |
| 93 | + |
| 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; |
| 98 | + }, |
| 99 | + |
| 100 | + update: function() { |
| 101 | + this.validateValue(); |
| 102 | + this.ratio = this.calcRatio(this.value) * 100; |
| 103 | + } |
108 | 104 |
|
109 |
| - </script> |
| 105 | + }); |
110 | 106 |
|
| 107 | +</script> |
111 | 108 | </polymer-element>
|
0 commit comments