diff options
author | Jose Antonio Marquez | 2012-02-10 15:33:20 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-10 15:33:20 -0800 |
commit | f7f445e8ced728d04de4bf1c5711f6756488a71e (patch) | |
tree | b09f00c28ff7123354af40509283ddec846f438d /js/lib | |
parent | 632a5daca17acb774b9344ccc0e9107f1643924c (diff) | |
parent | 48977780443d97b9e97b047066639c9056788041 (diff) | |
download | ninja-f7f445e8ced728d04de4bf1c5711f6756488a71e.tar.gz |
Merge branch 'refs/heads/NinjaInternal' into FileIO
Conflicts:
js/ninja.reel/ninja.html
js/stage/stage.reel/stage.html
Diffstat (limited to 'js/lib')
-rwxr-xr-x | js/lib/NJUtils.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 74039e64..8daafa42 100755 --- 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 |