diff options
Diffstat (limited to 'node_modules/montage/ui/text-slider.reel/text-slider.js')
-rw-r--r-- | node_modules/montage/ui/text-slider.reel/text-slider.js | 473 |
1 files changed, 473 insertions, 0 deletions
diff --git a/node_modules/montage/ui/text-slider.reel/text-slider.js b/node_modules/montage/ui/text-slider.reel/text-slider.js new file mode 100644 index 00000000..6582bbf2 --- /dev/null +++ b/node_modules/montage/ui/text-slider.reel/text-slider.js | |||
@@ -0,0 +1,473 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /*global require,exports */ | ||
7 | |||
8 | /** | ||
9 | @module "montage/ui/text-slider.reel" | ||
10 | @requires montage/core/core | ||
11 | @requires montage/ui/component | ||
12 | @requires montage/ui/composer/press-composer | ||
13 | */ | ||
14 | var Montage = require("montage").Montage, | ||
15 | Component = require("ui/component").Component, | ||
16 | PressComposer = require("ui/composer/press-composer").PressComposer; | ||
17 | |||
18 | /** | ||
19 | <p>Provides a way for users to quickly and easily manipulate numeric values. | ||
20 | It takes the form of a numeric value with a dotted underline, optionally | ||
21 | followed by a unit. | ||
22 | |||
23 | <p>When the user clicks and drags on the numeric value | ||
24 | it increases when dragged up or right, and decreases when dragged down or | ||
25 | left. If the user holds Control or Shift while dragging the value will | ||
26 | change by a smaller or larger amount respectively.</p> | ||
27 | |||
28 | <p>If the user clicks without dragging then the component enters "edit mode" | ||
29 | and turns into a textfield where the user can directly edit the value. If | ||
30 | user presses the Up or Down arrows in edit mode the value will increase or | ||
31 | decrease respectively. If the user holds Control or Shift while pressing an | ||
32 | arrow the value will change by a smaller or larger amount respectively.</p> | ||
33 | |||
34 | @class module:"montage/ui/text-slider.reel".TextSlider | ||
35 | @extends module:montage/ui/component.Component | ||
36 | */ | ||
37 | var TextSlider = exports.TextSlider = Montage.create(Component, /** @lends module:"montage/ui/text-slider.reel".TextSlider# */ { | ||
38 | |||
39 | // Properties | ||
40 | |||
41 | _converter: { | ||
42 | enumerable: false, | ||
43 | value: null | ||
44 | }, | ||
45 | /** | ||
46 | A converter that converts from a numeric value to the display value, for | ||
47 | example to convert to hexadecimal. You may also want to use a converter | ||
48 | that returns <code>value.toFixed(<i>n</i>)</code> to prevent precision errors from | ||
49 | being displayed to the user. | ||
50 | @type {object} | ||
51 | @default null | ||
52 | */ | ||
53 | converter: { | ||
54 | serializable: true, | ||
55 | get: function() { | ||
56 | return this._converter; | ||
57 | }, | ||
58 | set: function(value) { | ||
59 | if (this._converter !== value) { | ||
60 | this._converter = value; | ||
61 | this.needsDraw = true; | ||
62 | } | ||
63 | } | ||
64 | }, | ||
65 | |||
66 | _value: { | ||
67 | enumerable: false, | ||
68 | value: 0 | ||
69 | }, | ||
70 | /** | ||
71 | The value of the TextSlider. | ||
72 | @type {Number} | ||
73 | @default 0 | ||
74 | */ | ||
75 | value: { | ||
76 | serializable: true, | ||
77 | get: function() { | ||
78 | return this._value; | ||
79 | }, | ||
80 | set: function(value) { | ||
81 | if (isNaN(value = parseFloat(value))) { | ||
82 | return false; | ||
83 | } | ||
84 | |||
85 | // != null also checking for undefined | ||
86 | if (this._minValue != null && value < this._minValue) { | ||
87 | value = this._minValue; | ||
88 | } else if (this._maxValue != null && value > this._maxValue) { | ||
89 | value = this._maxValue; | ||
90 | } | ||
91 | |||
92 | if (this._value !== value) { | ||
93 | this._value = value; | ||
94 | this.needsDraw = true; | ||
95 | } | ||
96 | } | ||
97 | }, | ||
98 | |||
99 | /** | ||
100 | The value of the TextSlider converted using {@link converter} for display. | ||
101 | Setting this will call <code>revert</code> on the converter and set | ||
102 | {@link value}. | ||
103 | @type {String} | ||
104 | @default "0" | ||
105 | */ | ||
106 | convertedValue: { | ||
107 | dependencies: ["value", "converter"], | ||
108 | get: function() { | ||
109 | // TODO catch errors from conversion? | ||
110 | return (this._converter) ? this._converter.convert(this._value) : this._value; | ||
111 | }, | ||
112 | set: function(value) { | ||
113 | if (this._converter) { | ||
114 | this.value = this._converter.revert(value); | ||
115 | } else { | ||
116 | this.value = value; | ||
117 | } | ||
118 | } | ||
119 | }, | ||
120 | |||
121 | _minValue: { | ||
122 | enumerable: false, | ||
123 | value: null | ||
124 | }, | ||
125 | /** | ||
126 | The minimum value the TextSlider can take. If set to <code>null</code> there | ||
127 | is no minimum. | ||
128 | @type {number|null} | ||
129 | @default null | ||
130 | */ | ||
131 | minValue: { | ||
132 | serializable: true, | ||
133 | get: function() { | ||
134 | return this._minValue; | ||
135 | }, | ||
136 | set: function(value) { | ||
137 | if (this._minValue !== value) { | ||
138 | this._minValue = value; | ||
139 | |||
140 | this.value = this._value; | ||
141 | |||
142 | this.needsDraw = true; | ||
143 | } | ||
144 | } | ||
145 | }, | ||
146 | _maxValue: { | ||
147 | enumerable: false, | ||
148 | value: null | ||
149 | }, | ||
150 | /** | ||
151 | The maximum value the TextSlider can take. If set to <code>null</code> there | ||
152 | is no maximum. | ||
153 | @type {number|null} | ||
154 | @default null | ||
155 | */ | ||
156 | maxValue: { | ||
157 | serializable: true, | ||
158 | get: function() { | ||
159 | return this._maxValue; | ||
160 | }, | ||
161 | set: function(value) { | ||
162 | if (this._maxValue !== value) { | ||
163 | this._maxValue = value; | ||
164 | |||
165 | this.value = this._value; | ||
166 | |||
167 | this.needsDraw = true; | ||
168 | } | ||
169 | } | ||
170 | }, | ||
171 | |||
172 | /** | ||
173 | The small amount to increase/decrease the value by. Used when the user | ||
174 | holds the Control key and drags or presses the Up arrow in input mode. | ||
175 | @type {Number} | ||
176 | @default 0.1 | ||
177 | */ | ||
178 | smallStepSize: { | ||
179 | serializable: true, | ||
180 | enumerable: false, | ||
181 | value: 0.1 | ||
182 | }, | ||
183 | /** | ||
184 | The amount to increase/decrease the value by. Used per pixel when the user | ||
185 | drags the TextSlider or presses the Up arrow in input mode. | ||
186 | @type {Number} | ||
187 | @default 1 | ||
188 | */ | ||
189 | stepSize: { | ||
190 | serializable: true, | ||
191 | enumerable: false, | ||
192 | value: 1 | ||
193 | }, | ||
194 | /** | ||
195 | The large amount to increase/decrease the value by. Used when the user | ||
196 | holds the Shift key and drags or presses the Up arrow in input mode. | ||
197 | @type {Number} | ||
198 | @default 10 | ||
199 | */ | ||
200 | largeStepSize: { | ||
201 | serializable: true, | ||
202 | enumerable: false, | ||
203 | value: 10 | ||
204 | }, | ||
205 | |||
206 | _unit: { | ||
207 | enumerable: false, | ||
208 | value: null | ||
209 | }, | ||
210 | /** | ||
211 | The unit the value is in. This will be appended to the {@link convertedValue} | ||
212 | for display. | ||
213 | @type {String|null} | ||
214 | @default null | ||
215 | */ | ||
216 | unit: { | ||
217 | serializable: true, | ||
218 | get: function() { | ||
219 | return this._unit; | ||
220 | }, | ||
221 | set: function(va |