/**! * @preserve color animation jquery-plugin * http://www.bitstorm.org/jquery/color-animation/ * copyright 2011 edwin martin * released under the mit and gpl licenses. */ (function($) { /** * check whether the browser supports rgba color mode. * * author mehdi kabab * @return {boolean} true if the browser support rgba. false otherwise. */ function isrgbacapable() { var $script = $('script:first'), color = $script.css('color'), result = false; if (/^rgba/.test(color)) { result = true; } else { try { result = ( color != $script.css('color', 'rgba(0, 0, 0, 0.5)').css('color') ); $script.css('color', color); } catch (e) { } } return result; } $.extend(true, $, { support: { 'rgba': isrgbacapable() } }); var properties = ['color', 'backgroundcolor', 'borderbottomcolor', 'borderleftcolor', 'borderrightcolor', 'bordertopcolor', 'outlinecolor']; $.each(properties, function(i, property) { $.fx.step[property] = function(fx) { if (!fx.init) { fx.begin = parsecolor($(fx.elem).css(property)); fx.end = parsecolor(fx.end); fx.init = true; } fx.elem.style[property] = calculatecolor(fx.begin, fx.end, fx.pos); } }); // bordercolor doesn't fit in standard fx.step above. $.fx.step.bordercolor = function(fx) { if (!fx.init) { fx.end = parsecolor(fx.end); } var borders = properties.slice(2, 6); // all four border properties $.each(borders, function(i, property) { if (!fx.init) { fx[property] = {begin: parsecolor($(fx.elem).css(property))}; } fx.elem.style[property] = calculatecolor(fx[property].begin, fx.end, fx.pos); }); fx.init = true; } // calculate an in-between color. returns "#aabbcc"-like string. function calculatecolor(begin, end, pos) { var color = 'rgb' + ($.support['rgba'] ? 'a' : '') + '(' + parseint((begin[0] + pos * (end[0] - begin[0])), 10) + ',' + parseint((begin[1] + pos * (end[1] - begin[1])), 10) + ',' + parseint((begin[2] + pos * (end[2] - begin[2])), 10); if ($.support['rgba']) { color += ',' + (begin && end ? parsefloat(begin[3] + pos * (end[3] - begin[3])) : 1); } color += ')'; return color; } // parse an css-syntax color. outputs an array [r, g, b] function parsecolor(color) { var match, triplet; // match #aabbcc if (match = /#([0-9a-fa-f]{2})([0-9a-fa-f]{2})([0-9a-fa-f]{2})/.exec(color)) { triplet = [parseint(match[1], 16), parseint(match[2], 16), parseint(match[3], 16), 1]; // match #abc } else if (match = /#([0-9a-fa-f])([0-9a-fa-f])([0-9a-fa-f])/.exec(color)) { triplet = [parseint(match[1], 16) * 17, parseint(match[2], 16) * 17, parseint(match[3], 16) * 17, 1]; // match rgb(n, n, n) } else if (match = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) { triplet = [parseint(match[1]), parseint(match[2]), parseint(match[3]), 1]; } else if (match = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]*)\s*\)/.exec(color)) { triplet = [parseint(match[1], 10), parseint(match[2], 10), parseint(match[3], 10),parsefloat(match[4])]; // no browser returns rgb(n%, n%, n%), so little reason to support this format. } return triplet; } })(jquery);