diff options
Diffstat (limited to 'node_modules/montage/ui/bluemoon/checkbox.reel/checkbox.js')
-rw-r--r-- | node_modules/montage/ui/bluemoon/checkbox.reel/checkbox.js | 452 |
1 files changed, 452 insertions, 0 deletions
diff --git a/node_modules/montage/ui/bluemoon/checkbox.reel/checkbox.js b/node_modules/montage/ui/bluemoon/checkbox.reel/checkbox.js new file mode 100644 index 00000000..58e5154d --- /dev/null +++ b/node_modules/montage/ui/bluemoon/checkbox.reel/checkbox.js | |||
@@ -0,0 +1,452 @@ | |||
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 | /** | ||
7 | @module "montage/ui/bluemoon/checkbox.reel" | ||
8 | @requires montage/core/core | ||
9 | @requires montage/ui/component | ||
10 | */ | ||
11 | var Montage = require("montage").Montage, | ||
12 | Component = require("ui/component").Component; | ||
13 | /** | ||
14 | @class module:"montage/ui/bluemoon/checkbox.reel".Checkbox | ||
15 | @extends module:montage/ui/component.Component | ||
16 | */ | ||
17 | exports.Checkbox = Montage.create(Component,/** @lends "module:montage/ui/bluemoon/checkbox.reel".Checkbox# */ { | ||
18 | // Configuration | ||
19 | /** | ||
20 | The distance (squared) beyond which a touch will be considered. | ||
21 | @type {Number} | ||
22 | @default 256 | ||
23 | */ | ||
24 | touchMovementThreshold: { | ||
25 | enumerable: false, | ||
26 | value: 256 | ||
27 | }, | ||
28 | // Elements | ||
29 | /** | ||
30 | Description TODO | ||
31 | @private | ||
32 | */ | ||
33 | _nativeCheckbox: { | ||
34 | enumerable: false, | ||
35 | value: null | ||
36 | }, | ||
37 | /** | ||
38 | Description TODO | ||
39 | @private | ||
40 | */ | ||
41 | _background: { | ||
42 | enumerable: false, | ||
43 | value: null | ||
44 | }, | ||
45 | /** | ||
46 | Description TODO | ||
47 | @private | ||
48 | */ | ||
49 | _button: { | ||
50 | enumerable: false, | ||
51 | value: null | ||
52 | }, | ||
53 | /** | ||
54 | Description TODO | ||
55 | @private | ||
56 | */ | ||
57 | _checkmark: { | ||
58 | enumerable: false, | ||
59 | value: null | ||
60 | }, | ||
61 | // Event Handling APIs | ||
62 | /** | ||
63 | Description TODO | ||
64 | @function | ||
65 | @param {Event Handler} event handleMousedown | ||
66 | */ | ||
67 | handleMousedown: { | ||
68 | enumerable: false, | ||
69 | value: function (event) { | ||
70 | event.preventDefault(); | ||
71 | |||
72 | if (!this._disabled) { | ||
73 | this._acknowledgeIntent("mouse"); | ||
74 | } | ||
75 | } | ||
76 | }, | ||
77 | /** | ||
78 | Description TODO | ||
79 | @function | ||
80 | @param {Event Handler} event handleMouseup | ||
81 | */ | ||
82 | handleMouseup: { | ||
83 | value: function(event) { | ||
84 | this._interpretInteraction(event); | ||
85 | } | ||
86 | }, | ||
87 | /** | ||
88 | Description TODO | ||
89 | @private | ||
90 | */ | ||
91 | _touchX: { | ||
92 | enumerable: false, | ||
93 | value: null | ||
94 | }, | ||
95 | /** | ||
96 | Description TODO | ||
97 | @private | ||
98 | */ | ||
99 | _touchY: { | ||
100 | enumerable: false, | ||
101 | value: null | ||
102 | }, | ||
103 | /** | ||
104 | Description TODO | ||
105 | @function | ||
106 | @param {Event Handler} event handleTouchstart | ||
107 | */ | ||
108 | handleTouchstart: { | ||
109 | enumerable: false, | ||
110 | value: function (event) { | ||
111 | |||
112 | if (this._disabled || this._observedPointer !== null) { | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | event.preventDefault(); | ||
117 | |||
118 | this._acknowledgeIntent(event.targetTouches[0].identifier); | ||
119 | this._touchX = event.targetTouches[0].clientX; | ||
120 | this._touchY = event.targetTouches[0].clientY; | ||
121 | } | ||
122 | }, | ||
123 | /** | ||
124 | Description TODO | ||
125 | @function | ||
126 | @param {Event Handler} event handleTouchmove | ||
127 | */ | ||
128 | handleTouchmove: { | ||
129 | enumerable: false, | ||
130 | value: function (event) { | ||
131 | var i = 0, length = event.touches.length, xDistance, yDistance; | ||
132 | |||
133 | while ((i < length) && (event.touches[i].identifier !== this._observedPointer)) { | ||
134 | i++; | ||
135 | } | ||
136 | |||
137 | if (i < length) { | ||
138 | xDistance = this._touchX - event.touches[i].clientX; | ||
139 | yDistance = this._touchY - event.touches[i].clientY; | ||
140 | |||
141 | var squaredDist = (xDistance * xDistance) + (yDistance * yDistance); | ||
142 | |||
143 | if (squaredDist > this.touchMovementThreshold) { | ||
144 | event.preventDefault(); | ||
145 | |||
146 | this._releaseInterest(); | ||
147 | |||
148 | this.active = false; | ||
149 | this.needsDraw = true; | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | }, | ||
154 | /** | ||
155 | Description TODO | ||
156 | @function | ||
157 | @param {Event Handler} event handleTouchend | ||
158 | */ | ||
159 | handleTouchend: { | ||
160 | enumerable: false, | ||
161 | value: function (event) { | ||
162 | var i = 0, | ||
163 | changedTouchCount = event.changedTouches.length; | ||
164 | |||
165 | for (; i < changedTouchCount; i++) { | ||
166 | if (event.changedTouches[i].identifier === this._observedPointer) { | ||
167 | this._interpretInteraction(event); | ||
168 | return; | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | }, | ||
173 | /** | ||
174 | Description TODO | ||
175 | @function | ||
176 | @param {Event Handler} event handleTouchcancel | ||
177 | */ | ||
178 | handleTouchcancel: { | ||
179 | value: function(event) { | ||
180 | |||
181 | var i = 0, | ||
182 | changedTouchCount = event.changedTouches.length; | ||
183 | |||
184 | for (; i < changedTouchCount; i++) { | ||
185 | if (event.changedTouches[i].identifier === this._observedPointer) { | ||
186 | this._releaseInterest(); | ||
187 | |||
188 | this.active = false; | ||
189 | this.needsDraw = true; | ||
190 | |||
191 | return; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | } | ||
196 | }, | ||
197 | |||
198 | // Internal state management | ||
199 | /** | ||
200 | Description TODO | ||
201 | @private | ||
202 | */ | ||
203 | _active: { | ||
204 | enumerable: false, | ||
205 | value: false | ||
206 | }, | ||
207 | /** | ||
208 | Description TODO | ||
209 | @type {Function} | ||
210 | @default {Boolean} false | ||
211 | */ | ||
212 | active: { | ||
213 | get: function() { | ||
214 | return this._active; | ||
215 | }, | ||
216 | set: function(value) { | ||
217 | if (value === this._active) { | ||
218 | return; | ||
219 | } | ||