From c8720030e315d8c440354f54cf48f0c1464d72cb Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 9 Feb 2012 16:31:15 -0800 Subject: deleted old utils file and move single method into NJUtils Signed-off-by: Valerio Virgillito --- js/lib/NJUtils.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'js/lib/NJUtils.js') 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, { }, + // Returns the numerical value and unit string from a string. + // Useful for element properties. + // 100px will return the following array: [100, px] + getValueAndUnits: { + value: function(input) { + var numberValue = parseFloat(input); + + // Ignore all whitespace, digits, negative sign and "." when looking for units label + // The units must come after one or more digits + var objRegExp = /(\-*\d+\.*\d*)(\s*)(\w*\%*)/; + var unitsString = input.replace(objRegExp, "$3"); + if(unitsString) { + var noSpaces = /(\s*)(\S*)(\s*)/; + // strip out spaces and convert to lower case + var match = (unitsString.replace(noSpaces, "$2")).toLowerCase(); + } + + return [numberValue, match]; + } + }, + /* ================= Style methods ================= */ ///// Get computed height of element -- cgit v1.2.3