fixColor.js
fixColors.js is jQuery plugin to fix contrast ratio of foreground and background color automatically.
How to Use?
Its very simple to use, just include jQuery on your page and fixColor.js Call fixColors every time you want to fix the colors of a content.
$('div').fixColors();
How Code Works?
Major part of code goes in function
function getColorInfo(strColor){
var match=strColor.match(/rgba[ \t]*\([ \t]*([0-9.]+)[ \t]*,[ \t]*([0-9.]+)[ \t]*,[ \t]*([0-9.]+)[ \t]*,[ \t]*([0-9.]+)[ \t]*\)/);
var isAlpha=true;
if(match===null){
match=strColor.match(/rgb[ \t]*\([ \t]*([0-9.]+)[ \t]*,[ \t]*([0-9.]+)[ \t]*,[ \t]*([0-9.]+)[ \t]*\)/);
isAlpha=false;
}
var r = match[1]*1, g = match[2]*1,b = match[3]*1, a = match[4]*1;
var brightness = (r * 299 + g * 587 + b * 114) / 1000, cb = 20;
if (brightness < 127) {
cb = 235;
}
isTransparent=(isAlpha)&&(a===0);
var rgbOnly='rgb('+r+','+g+','+b+')';
var maxContrast = "rgb(" + cb+"," +cb+"," +cb+")";
return {'r':r,'g':g,'b':b,'a':a,
'brightness':brightness,
'maxContrast':maxContrast,
'rgb':rgbOnly,
'isAlpha':isAlpha,
'isTransparent':isTransparent
};
}
This function finds some interesting information about a color…