aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-09 16:39:38 -0800
committerValerio Virgillito2012-02-09 16:39:38 -0800
commitb2155233351966ff579db41a7b85be554c643a97 (patch)
treedb6b9c79e27b3de81f7bca25c3cb7252409d3aaa /js/lib
parentcebd27bd649d01c8b8713651df3878da14b5e9a8 (diff)
parentf0a833b589cd3bcd3ba26037070c06e945ef6e29 (diff)
downloadninja-b2155233351966ff579db41a7b85be554c643a97.tar.gz
Merge branch 'code-cleanup' of https://github.com/mencio/ninja-internal into feature-branch
Diffstat (limited to 'js/lib')
-rw-r--r--js/lib/NJUtils.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js
index d6548871..0e886ae7 100644
--- a/js/lib/NJUtils.js
+++ b/js/lib/NJUtils.js
@@ -183,6 +183,27 @@ exports.NJUtils = Object.create(Object.prototype, {
183 183
184 }, 184 },
185 185
186 // Returns the numerical value and unit string from a string.
187 // Useful for element properties.
188 // 100px will return the following array: [100, px]
189 getValueAndUnits: {
190 value: function(input) {
191 var numberValue = parseFloat(input);
192
193 // Ignore all whitespace, digits, negative sign and "." when looking for units label
194 // The units must come after one or more digits
195 var objRegExp = /(\-*\d+\.*\d*)(\s*)(\w*\%*)/;
196 var unitsString = input.replace(objRegExp, "$3");
197 if(unitsString) {
198 var noSpaces = /(\s*)(\S*)(\s*)/;
199 // strip out spaces and convert to lower case
200 var match = (unitsString.replace(noSpaces, "$2")).toLowerCase();
201 }
202
203 return [numberValue, match];
204 }
205 },
206
186 /* ================= Style methods ================= */ 207 /* ================= Style methods ================= */
187 208
188 ///// Get computed height of element 209 ///// Get computed height of element