simple color invert function
use: Ext.util.Color.invertHex('ffffff') - > 000000
PHP Code:
Ext.util.Color = function() {
return {
decToHex: function( n ) {
var HCHARS = '0123456789ABCDEF';
n = parseInt(n, 10);
n = ( !isNaN( n )) ? n : 0;
n = (n > 255 || n < 0) ? 0 : n;
return HCHARS.charAt( ( n - n % 16 ) / 16 ) + HCHARS.charAt( n % 16 );
},
getHCharPos: function( c ) {
var HCHARS = '0123456789ABCDEF';
return HCHARS.indexOf( c.toUpperCase() );
},
hexToDec: function( hex ) {
var s = hex.split('');
return ( ( Ext.util.Color.getHCharPos( s[0] ) * 16 ) + Ext.util.Color.getHCharPos( s[1] ) );
},
rgbToHex: function( r, g, b ) {
if( r instanceof Array ) { return Ext.util.Color.rgbToHex.call( this, r[0], r[1], r[2] ); }
return Ext.util.Color.decToHex( r ) + Ext.util.Color.decToHex( g ) + Ext.util.Color.decToHex( b );
},
hexToRgb: function( hex ) {
return [ Ext.util.Color.hexToDec( hex.substr(0, 2) ), Ext.util.Color.hexToDec( hex.substr(2, 2) ), Ext.util.Color.hexToDec( hex.substr(4, 2) ) ];
},
invertRgb: function( r, g, b ) {
if( r instanceof Array ) { return Ext.util.Color.invertRgb.call( this, r[0], r[1], r[2] ); }
return [255-r,255-g,255-b];
},
invertHex: function( hex ) {
var rgb = Ext.util.Color.hexToRgb(hex),
invert = Ext.util.Color.invertRgb(rgb[0], rgb[1], rgb[2]);
return Ext.util.Color.rgbToHex(invert[0], invert[1], invert[2]);
}
}
}();