This fixes an exception when trying to parse gradient like: 'rgb(254, 254, 254) 0%, rgb(236, 236, 236) 100%'

Note: This does not parse the % which would be good to delineate steps correctly, just a fix for an Exception.
This commit is contained in:
MoyuScript 2011-12-07 09:53:40 +11:00
parent e4837f83eb
commit fa0f614ccd

View File

@ -31,7 +31,7 @@ html2canvas.Generate.Gradient = function(src, bounds) {
canvas.height = bounds.height; canvas.height = bounds.height;
function getColors(input) { function getColors(input) {
var j = -1, var j = -1,
color = '', color = '',
chr; chr;
@ -39,16 +39,20 @@ html2canvas.Generate.Gradient = function(src, bounds) {
while( j++ < input.length ) { while( j++ < input.length ) {
chr = input.charAt( j ); chr = input.charAt( j );
if (chr === ')') { if (chr === ')') {
color += chr; color += chr;
steps.push( color ); steps.push( color );
color = ''; color = '';
j+=2; j+=2;
} else { } else if (color || isValidColorStartChar(chr)) {
color += chr; color += chr;
} }
} }
} }
function isValidColorStartChar(c) {
return c && /[^0-9%,]/.test(c);
}
if ( tmp = src.match(/-webkit-linear-gradient\((.*)\)/) ) { if ( tmp = src.match(/-webkit-linear-gradient\((.*)\)/) ) {
position = tmp[1].split( ",", 1 )[0]; position = tmp[1].split( ",", 1 )[0];