diff options
author | Valerio Virgillito | 2012-02-02 00:11:51 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-02 15:33:42 -0800 |
commit | a3024011a91d3941f81481dd4d600e9684eb0fd4 (patch) | |
tree | 084b4856910f1db53973dd11617f7ffa03a6dd46 /node_modules/montage/ui/toggle-switch.reel/toggle-switch.js | |
parent | 97255032921178bdfbc25512ddf3e0867e353f7a (diff) | |
download | ninja-a3024011a91d3941f81481dd4d600e9684eb0fd4.tar.gz |
upgrading to Montage v0.6
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/toggle-switch.reel/toggle-switch.js')
-rw-r--r-- | node_modules/montage/ui/toggle-switch.reel/toggle-switch.js | 424 |
1 files changed, 424 insertions, 0 deletions
diff --git a/node_modules/montage/ui/toggle-switch.reel/toggle-switch.js b/node_modules/montage/ui/toggle-switch.reel/toggle-switch.js new file mode 100644 index 00000000..9a27c52b --- /dev/null +++ b/node_modules/montage/ui/toggle-switch.reel/toggle-switch.js | |||
@@ -0,0 +1,424 @@ | |||
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 | |||
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/toggle-switch.reel".ToggleSwitch | ||
15 | @extends module:montage/ui/component.Component | ||
16 | */ | ||
17 | var ToggleSwitch = exports.ToggleSwitch = Montage.create(Component, /** @lends module:"montage/ui/toggle-switch.reel".ToggleSwitch# */ { | ||
18 | |||
19 | |||
20 | _value: { | ||
21 | enumerable: false, | ||
22 | value: false | ||
23 | }, | ||
24 | /** | ||
25 | Description TODO | ||
26 | @type {Function} | ||
27 | @default {Boolean} false | ||
28 | */ | ||
29 | value: { | ||
30 | enumerable: true, | ||
31 | get: function() { | ||
32 | return this._value; | ||
33 | }, | ||
34 | set: function(value) { | ||
35 | if (!this._pressed) { | ||
36 | value = !!value; | ||
37 | if (this._value !== value) { | ||
38 | this._value = value; | ||
39 | window.clearInterval(this._animation); | ||
40 | this._animation = null; | ||
41 | this._speed = 0; | ||
42 | this.needsDraw = true; | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | }, | ||
47 | /** | ||
48 | Description TODO | ||
49 | @private | ||
50 | */ | ||
51 | _toggle: { | ||
52 | enumerable: false, | ||
53 | value: null | ||
54 | }, | ||
55 | /** | ||
56 | Description TODO | ||
57 | @private | ||
58 | */ | ||
59 | _scroll: { | ||
60 | enumerable: false, | ||
61 | value: null | ||
62 | }, | ||
63 | /** | ||
64 | Description TODO | ||
65 | @private | ||
66 | */ | ||
67 | _circle: { | ||
68 | enumerable: false, | ||
69 | value: null | ||
70 | }, | ||
71 | /** | ||
72 | Description TODO | ||
73 | @private | ||
74 | */ | ||
75 | _handlerBg: { | ||
76 | enumerable: false, | ||
77 | value: null | ||
78 | }, | ||
79 | /** | ||
80 | Description TODO | ||
81 | @private | ||
82 | */ | ||
83 | _handler: { | ||
84 | enumerable: false, | ||
85 | value: null | ||
86 | }, | ||
87 | /** | ||
88 | Description TODO | ||
89 | @private | ||
90 | */ | ||
91 | _handlerOnBg: { | ||
92 | enumerable: false, | ||
93 | value: null | ||
94 | }, | ||
95 | /** | ||
96 | Description TODO | ||
97 | @private | ||
98 | */ | ||
99 | _handlerOn: { | ||
100 | enumerable: false, | ||
101 | value: null | ||
102 | }, | ||
103 | /** | ||
104 | Description TODO | ||
105 | @private | ||
106 | */ | ||
107 | _handlerDragArea: { | ||
108 | enumerable: false, | ||
109 | value: null | ||
110 | }, | ||
111 | /** | ||
112 | Description TODO | ||
113 | @private | ||
114 | */ | ||
115 | _pressed: { | ||
116 | enumerable: false, | ||
117 | value: false | ||
118 | }, | ||
119 | /** | ||
120 | Description TODO | ||
121 | @private | ||
122 | */ | ||
123 | _cursorPosition: { | ||
124 | enumerable: false, | ||
125 | value: null | ||
126 | }, | ||
127 | /** | ||
128 | Description TODO | ||
129 | @private | ||
130 | */ | ||
131 | _width: { | ||
132 | enumerable: false, | ||
133 | value: 60 - 22 | ||
134 | }, | ||
135 | /** | ||
136 | Description TODO | ||
137 | @private | ||
138 | */ | ||
139 | _scrollTo: { | ||
140 | enumerable: false, | ||
141 | value: null | ||
142 | }, | ||
143 | /** | ||
144 | Description TODO | ||
145 | @private | ||
146 | */ | ||
147 | _touchIdentifier: { | ||
148 | enumerable: false, | ||
149 | value: null | ||
150 | }, | ||
151 | /** | ||
152 | Description TODO | ||
153 | @private | ||
154 | */ | ||
155 | _speed: { | ||
156 | enumerable: false, | ||
157 | value: 0 | ||
158 | }, | ||
159 | /** | ||
160 | Description TODO | ||
161 | @function | ||
162 | @param {Event} event TODO | ||
163 | */ | ||
164 | handleTouchstart: { | ||
165 | enumerable: false, | ||
166 | value: function (event) { | ||
167 | if (event.target === this._toggle) { | ||
168 | this.value = !this.value; | ||
169 | } else { | ||
170 | this._touchIdentifier = event.targetTouches[0].identifier; | ||
171 | document.addEventListener("touchmove", this, false); | ||
172 | document.addEventListener("touchend", this, false); | ||
173 | this._cursorPosition = event.targetTouches[0].clientX; | ||
174 | |||
175 | if (this._scrollTo < 0) { | ||
176 | this._scrollTo = 0; | ||
177 | } else if (this._scrollTo > this._width) { | ||
178 | this._scrollTo = this._width; | ||
179 | } | ||
180 | window.clearInterval(this._animation); | ||
181 | this._animation = null; | ||
182 | this._pressed = true; | ||
183 | this.needsDraw = true; | ||
184 | } | ||
185 | event.preventDefault(); | ||
186 | event.stopPropagation(); | ||
187 | } | ||
188 | }, | ||
189 | /** | ||
190 | Description TODO | ||
191 | @function | ||
192 | @param {Event} event TODO | ||
193 | */ | ||
194 | handleMousedown: { | ||
195 | enumerable: false, | ||
196 | value: function (event) { | ||
197 | if (event.target === this._toggle) { | ||
198 | this.value = !this.value; | ||
199 | } else { | ||
200 | document.addEventListener("mousemove", this, false); | ||
201 | document.addEventListener("mouseup", this, false); | ||
202 | this._cursorPosition = event.clientX; | ||
203 | |||
204 | if (this._scrollTo < 0) { | ||
205 | this._scrollTo = 0; | ||
206 | } else if (this._scrollTo > this._width) { | ||
207 | this._scrollTo = this._width; | ||
208 | } | ||
209 | window.clearInterval(this._animation); | ||
210 | this._animation = null; | ||
211 | this._pressed = true; | ||
212 | this.needsDraw = true; | ||
213 | } | ||
214 | event.preventDefault(); | ||
215 | event.stopPropagation(); | ||
216 |