From c8ebf8b9f4e4721980f7fa11da3e518e3edadf0e Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 19 Mar 2014 12:51:01 +0000 Subject: [PATCH] added Common.colorToNumber and Common.log --- src/core/Common.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/core/Common.js b/src/core/Common.js index 08f2ecf..d7243f6 100644 --- a/src/core/Common.js +++ b/src/core/Common.js @@ -223,4 +223,45 @@ var Common = {}; return min + Math.random() * (max - min); }; + /** + * Converts a CSS hex colour string into an integer + * @method colorToNumber + * @param {string} colorString + * @return {number} An integer representing the CSS hex string + */ + Common.colorToNumber = function(colorString) { + colorString = colorString.replace('#',''); + + if (colorString.length == 3) { + colorString = colorString.charAt(0) + colorString.charAt(0) + + colorString.charAt(1) + colorString.charAt(1) + + colorString.charAt(2) + colorString.charAt(2); + } + + return parseInt(colorString, 16); + }; + + /** + * A wrapper for console.log, for providing errors and warnings + * @method log + * @param {string} message + * @param {string} type + */ + Common.log = function(message, type) { + if (!console || !console.log) + return; + + var style; + + switch (type) { + case 'warn': + style = 'color: coral'; + break; + case 'error': + style = 'color: red'; + } + + console.log('%c [Matter] ' + type + ': ' + message, style); + }; + })(); \ No newline at end of file