From d3d28294641694f016126478a804b4329fec10fa Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 17 Sep 2011 14:02:17 +0000 Subject: [PATCH] fix Ox.formatColor() --- source/Ox.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/source/Ox.js b/source/Ox.js index 02731320..aec3cb7e 100644 --- a/source/Ox.js +++ b/source/Ox.js @@ -2405,7 +2405,7 @@ Ox.formatArea = function(num, dec) { Ox.formatColor (strange one) @*/ Ox.formatColor = function(val, type) { - var background, color; + var background, color, element; if (type == 'hue') { background = Ox.rgb(val, 1, 0.25).map(function(val) { return Math.round(val); @@ -2427,38 +2427,36 @@ Ox.formatColor = function(val, type) { return Math.round(val * 255); }); color = Ox.range(3).map(function() { - var v = val * 255; + var v = Math.round(val * 255); return val < 0.5 ? 128 + v : 255 - v; }); + Ox.print('COLOR', color) } - return Ox.element('
') + element = Ox.element('
') .css({ borderRadius: '4px', padding: '0 3px 1px 3px', - background: Ox.isNumber(background[0]) - ? 'rgb(' + background.join(', ') + ')' - : Ox.print([/*'moz', 'o', */'webkit'].map(function(browser) { - return '-' + browser + '-linear-gradient(left, ' - + background.map(function(rgb, i) { - return 'rgb(' + rgb.join(', ') + ') ' - + Math.round(i * 100 / 6) + '%'; - }).join(', ') - + ')'; - }).join(', ')) && - [/*'moz', 'o', */'webkit'].map(function(browser) { - return '-' + browser + '-linear-gradient(left, ' - + background.map(function(rgb, i) { - return 'rgb(' + rgb.join(', ') + ') ' - + Math.round(i * 100 / 6) + '%'; - }).join(', ') - + ')'; - }).join(', '), color: 'rgb(' + color.join(', ') + ')', overflow: 'hidden', textOverflow: 'ellipsis', //textShadow: 'black 1px 1px 1px' }) .html(Ox.formatNumber(val, 3)); + if (Ox.isNumber(background[0])) { + element.css({background: 'rgb(' + background.join(', ') + ')'}); + } else { + ['moz', 'o', 'webkit'].forEach(function(browser) { + element.css({ + background: '-' + browser + '-linear-gradient(left, ' + + background.map(function(rgb, i) { + return 'rgb(' + rgb.join(', ') + ') ' + + Math.round(i * 100 / 6) + '%'; + }).join(', ') + + ')' + }); + }); + } + return element }; /*@