From 104fc91a81695c920140fd836011d27f2ac5809f Mon Sep 17 00:00:00 2001 From: Miles Date: Sun, 24 Apr 2011 12:43:17 -0700 Subject: [PATCH 1/3] Support for IE's ARGB syntax (#aarrggbb) --- lib/less/tree/color.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/less/tree/color.js b/lib/less/tree/color.js index d4c6f3eb1..38d34f85a 100644 --- a/lib/less/tree/color.js +++ b/lib/less/tree/color.js @@ -15,6 +15,11 @@ tree.Color = function (rgb, a) { this.rgb = rgb.match(/.{2}/g).map(function (c) { return parseInt(c, 16); }); + } else if (rgb.length == 8) { + this.alpha = parseInt(rgb.substring(0,2), 16) / 255.0; + this.rgb = rgb.substr(2).match(/.{2}/g).map(function (c) { + return parseInt(c, 16); + }); } else { this.rgb = rgb.split('').map(function (c) { return parseInt(c + c, 16); From 24cc747e5e7b4ed7833791a89ee3c3ccc05ebd4a Mon Sep 17 00:00:00 2001 From: Miles Date: Wed, 3 Aug 2011 14:52:35 -0700 Subject: [PATCH 2/3] Added a modified version of Felipe Gasper's IE<9 style injection error fix. --- lib/less/browser.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/less/browser.js b/lib/less/browser.js index ae2667d97..cba4c3b61 100644 --- a/lib/less/browser.js +++ b/lib/less/browser.js @@ -101,8 +101,14 @@ function loadStyles() { for (var i = 0; i < styles.length; i++) { if (styles[i].type.match(typePattern)) { new(less.Parser)().parse(styles[i].innerHTML || '', function (e, tree) { - styles[i].type = 'text/css'; - styles[i].innerHTML = tree.toCSS(); + var css = tree.toCSS(); + var style = styles[i]; + try { + style.innerHTML = css; + } catch (_) { + style.styleSheets.cssText = css; + } + style.type = 'text/css'; }); } } From 71f15ac00015f2e14067b1bd3399d83bfba9d3d2 Mon Sep 17 00:00:00 2001 From: Miles Elam Date: Wed, 3 Aug 2011 21:02:10 -0700 Subject: [PATCH 3/3] ARGB input removed. ARGB output added with the function argb(Color). --- lib/less/functions.js | 4 ++++ lib/less/tree/color.js | 13 ++++++++----- test/css/colors.css | 6 ++++++ test/less/colors.less | 6 ++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/less/functions.js b/lib/less/functions.js index 804b9e6f9..2889f112f 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -147,6 +147,10 @@ tree.functions = { message: "math functions take numbers as parameters" }; } + }, + argb: function (color) { + return new(tree.Anonymous)(color.toARGB()); + } }; diff --git a/lib/less/tree/color.js b/lib/less/tree/color.js index 38d34f85a..bb7646a5c 100644 --- a/lib/less/tree/color.js +++ b/lib/less/tree/color.js @@ -15,11 +15,6 @@ tree.Color = function (rgb, a) { this.rgb = rgb.match(/.{2}/g).map(function (c) { return parseInt(c, 16); }); - } else if (rgb.length == 8) { - this.alpha = parseInt(rgb.substring(0,2), 16) / 255.0; - this.rgb = rgb.substr(2).match(/.{2}/g).map(function (c) { - return parseInt(c, 16); - }); } else { this.rgb = rgb.split('').map(function (c) { return parseInt(c + c, 16); @@ -91,6 +86,14 @@ tree.Color.prototype = { h /= 6; } return { h: h * 360, s: s, l: l, a: a }; + }, + toARGB: function () { + var argb = [Math.round(this.alpha * 255)].concat(this.rgb); + return '#' + argb.map(function (i) { + i = Math.round(i); + i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16); + return i.length === 1 ? '0' + i : i; + }).join(''); } }; diff --git a/test/css/colors.css b/test/css/colors.css index 373781df3..540f9b065 100644 --- a/test/css/colors.css +++ b/test/css/colors.css @@ -7,6 +7,9 @@ #yelow #rgba { color: rgba(255, 238, 170, 0.1); } +#yelow #argb { + color: #1affeeaa; +} #blue #short { color: #00f; } @@ -16,6 +19,9 @@ #blue #rgba { color: rgba(0, 0, 255, 0.1); } +#blue #argb { + color: #1a0000ff; +} #alpha #hsla { color: rgba(61, 45, 41, 0.6); } diff --git a/test/less/colors.less b/test/less/colors.less index 5c90bcbb5..5744e1677 100644 --- a/test/less/colors.less +++ b/test/less/colors.less @@ -8,6 +8,9 @@ #rgba { color: rgba(255, 238, 170, 0.1); } + #argb { + color: argb(rgba(255, 238, 170, 0.1)); + } } #blue { @@ -20,6 +23,9 @@ #rgba { color: rgba(0, 0, 255, 0.1); } + #argb { + color: argb(rgba(0, 0, 255, 0.1)); + } } #alpha #hsla {