diff options
author | Valerio Virgillito | 2012-01-29 00:26:20 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-30 16:53:32 -0800 |
commit | ad81ae4c61eb5857cd444ef0caf5b0b33e8072ba (patch) | |
tree | fc8cfda018d6fd09d13796c0680e6dbcb423ea7c /node_modules/ninja-components/hottextunit.reel/hottextunit.js | |
parent | 36e7379c7c282fc3e1b5b86b0b0ed59be60c4253 (diff) | |
download | ninja-ad81ae4c61eb5857cd444ef0caf5b0b33e8072ba.tar.gz |
Moved the ninja components out of the Montage folder
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'node_modules/ninja-components/hottextunit.reel/hottextunit.js')
-rw-r--r-- | node_modules/ninja-components/hottextunit.reel/hottextunit.js | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/node_modules/ninja-components/hottextunit.reel/hottextunit.js b/node_modules/ninja-components/hottextunit.reel/hottextunit.js new file mode 100644 index 00000000..8d468ce8 --- /dev/null +++ b/node_modules/ninja-components/hottextunit.reel/hottextunit.js | |||
@@ -0,0 +1,185 @@ | |||
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 | var Montage = require("montage").Montage, | ||
8 | HotText = require("ui/hottext.reel").HotText; | ||
9 | |||
10 | var HotTextUnit = exports.HotTextUnit = Montage.create(HotText, { | ||
11 | |||
12 | numericField: { | ||
13 | enumerable: false, | ||
14 | value:null | ||
15 | }, | ||
16 | |||
17 | unitsField: { | ||
18 | enumerable: false, | ||
19 | value:null | ||
20 | }, | ||
21 | |||
22 | inputField: { | ||
23 | enumerable: false, | ||
24 | value:null | ||
25 | }, | ||
26 | |||
27 | _units: { | ||
28 | enumerable: false, | ||
29 | value: "px" | ||
30 | }, | ||
31 | |||
32 | units: { | ||
33 | serializable: true, | ||
34 | enumerable: true, | ||
35 | get: function() { | ||
36 | return this._units; | ||
37 | }, | ||
38 | set: function(value) { | ||
39 | if (value !== this._units) { | ||
40 | if(this._acceptableUnits.indexOf(value) !== -1) | ||
41 | { | ||
42 | this._units = value; | ||
43 | this.needsDraw = true; | ||
44 | |||
45 | this._setEventFlags("change", false); | ||
46 | this._dispatchActionEvent(); | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | }, | ||
51 | |||
52 | // Some controls will only support certain units | ||
53 | // For example, Oval would specify an innerRadius with acceptableUnits = ["%"] | ||
54 | // and Stroke Size with acceptableUnits = ["px", "pt", "%"] | ||
55 | _acceptableUnits: { | ||
56 | enumerable: false, | ||
57 | value: ["px"] | ||
58 | }, | ||
59 | |||
60 | |||
61 | acceptableUnits: { | ||
62 | serializable: true, | ||
63 | enumerable: true, | ||
64 | get: function() { | ||
65 | return this._acceptableUnits; | ||
66 | }, | ||
67 | set: function(value) { | ||
68 | if (value !== this._acceptableUnits) { | ||
69 | this._acceptableUnits = value; | ||
70 | } | ||
71 | } | ||
72 | }, | ||
73 | |||
74 | // We don't want to handle every input; we only want to handle input from tab or enter | ||
75 | // Thus, we don't listen for an input event; we call this from handleKeydown | ||
76 | handleInput: { | ||
77 | enumerable: false, | ||
78 | value: function() { | ||
79 | var inputString = this.inputField.value; | ||
80 | |||
81 | // Ignore all whitespace, digits, negative sign and "." when looking for units label | ||
82 | // The units must come after one or more digits | ||
83 | var objRegExp = /(\-*\d+\.*\d*)(\s*)(\w*\%*)/; | ||
84 | var unitsString = inputString.replace(objRegExp, "$3"); | ||
85 | if(unitsString) | ||
86 | { | ||
87 | var noSpaces = /(\s*)(\S*)(\s*)/; | ||
88 | // strip out spaces and convert to lower case | ||
89 | var match = (unitsString.replace(noSpaces, "$2")).toLowerCase(); | ||
90 | if(match) | ||
91 | { | ||
92 | Object.getPropertyDescriptor(this, "units").set.call(this, match); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | this._setEventFlags("change", false); | ||
97 | // Moving this call to after setting the value since value changes are dispatching events before units are set | ||
98 | Object.getPropertyDescriptor(this, "value").set.call(this, this.inputFunction(inputString), false); | ||
99 | } | ||
100 | }, | ||
101 | |||
102 | draw: { | ||
103 | enumerable: false, | ||
104 | value: function() { | ||
105 | this.inputField.value = this._value + " " + this._units; | ||
106 | this.numericField.innerText = this._value; | ||
107 | this.unitsField.innerText = " " + this._units; | ||
108 | |||
109 | |||
110 | if(this._hasFocus) | ||
111 | { | ||
112 | this.numericField.classList.add("hide"); | ||
113 | this.unitsField.classList.add("hide"); | ||
114 | |||
115 | this.inputField.classList.remove("hide"); | ||
116 | |||
117 | // if element targeted; balancing demands of multitouch | ||
118 | // with traditional single focus model | ||
119 | this.inputField.addEventListener("keydown", this, false); | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | this.numericField.classList.remove("hide"); | ||
124 | this.unitsField.classList.remove("hide"); | ||
125 | |||
126 | this.inputField.classList.add("hide"); | ||
127 | } | ||
128 | } | ||
129 | }, | ||
130 | |||
131 | didDraw: { | ||
132 | enumerable: false, | ||
133 | value: function() { | ||
134 | if(this._hasFocus) | ||
135 | { | ||
136 | var length = 0; | ||
137 | if(this.labelFunction) | ||
138 | { | ||
139 | length = this.labelFunction(this._value).length; | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | length = this.inputField.value.toString().length; | ||
144 | } | ||
145 | this.inputField.setSelectionRange(0, length); | ||
146 | } | ||
147 | this._valueSyncedWithInputField = true; | ||
148 | } | ||
149 | }, | ||
150 | |||
151 | prepareForDraw: { | ||
152 | value: function() { | ||
153 | this.numericField = document.createElement("span"); | ||
154 | this.numericField.classList.add("underline"); | ||
155 | this.numericField.innerText = this._value; | ||
156 | |||
157 | this.unitsField = document.createElement("span"); | ||
158 | this.unitsField.innerText = " " + this._units; | ||
159 | |||
160 | this.inputField = document.createElement("input"); | ||
161 | this.inputField.value = this._value + " " + this._units; | ||
162 | this.inputField.classList.add("hide"); | ||
163 | |||
164 | this.element.appendChild(this.numericField); | ||
165 | this.element.appendChild(this.unitsField); | ||
166 | this.element.appendChild(this.inputField); | ||
167 | |||
168 | |||
169 | if(this._value) | ||
170 | { | ||
171 | this._numValue = this._value; | ||
172 | } | ||
173 | |||
174 | if(this._enabled) | ||
175 | { | ||
176 | this.element.addEventListener("blur", this); | ||
177 | this.element.addEventListener("focus", this); | ||
178 | |||
179 | this.element.addEventListener("touchstart", this, false); | ||
180 | this.element.addEventListener("mousedown", this, false); | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | }); | ||