1
0
Fork 0
forked from 0x2620/oxjs

add themed colored elements

This commit is contained in:
rlx 2011-10-26 14:52:03 +00:00
commit 188656bd99
5 changed files with 147 additions and 130 deletions

View file

@ -13,65 +13,6 @@ Ox.formatArea = function(num, dec) {
) + ' ' + (km ? 'k' : '') + 'm\u00B2';
};
/*@
Ox.formatColor <f> (strange one)
@*/
// FIXME: implement invert
Ox.formatColor = function(val, type, invert) {
var background, color, element;
if (type == 'hue') {
background = Ox.rgb(val, 1, 0.25).map(function(val) {
return Math.round(val);
});
color = Ox.rgb(val, 1, 0.75).map(function(val) {
return Math.round(val);
});
} else if (type == 'saturation') {
background = Ox.range(7).map(function(i) {
return Ox.rgb(i * 60, val, 0.25).map(function(val) {
return Math.round(val);
});
});
color = Ox.range(3).map(function() {
return Math.round(128 + val * 127);
});
} else if (type == 'lightness') {
background = Ox.range(3).map(function() {
return Math.round(val * 255);
});
color = Ox.range(3).map(function() {
var v = Math.round(val * 255);
return val < 0.5 ? 128 + v : v - 128;
});
}
element = Ox.element('<div>')
.css({
borderRadius: '8px',
padding: '0 4px 1px 4px',
color: 'rgb(' + color.join(', ') + ')',
overflow: 'hidden',
textAlign: 'right',
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
};
/*@
Ox.formatCurrency <f> Formats a number with a currency symbol
> Ox.formatCurrency(1000, '$', 2)