Created
January 19, 2010 16:56
-
-
Save mikewest/281085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cssColor() { | |
var i, limit, number; | |
if (nexttoken.identifier) { | |
switch (nexttoken.value) { | |
case 'rgb': | |
limit = 3; | |
break; | |
case 'rgba': | |
limit = 4; | |
break; | |
} | |
if (limit) { | |
advance(); | |
advance('('); | |
for (i = 0; i < limit; i += 1) { | |
if (i) { | |
advance(','); | |
} | |
number = nexttoken.value; | |
if (nexttoken.type !== '(number)' || number < 0) { | |
warning("Expected a positive number and instead saw '{a}'", | |
nexttoken, number); | |
advance(); | |
} else { | |
advance(); | |
if ( i === 3 ) { | |
// The last parameter of an RGBA value must be an | |
// "alphavalue" ( http://www.w3.org/TR/css3-color/#alphavaluedt ) | |
// It boils down to a decimal between 0 and 1. | |
if ( nexttoken.id === '%' ) { | |
warning( "The last parameter of an RGBA value must be a decimal between 0 and 1, not a percentage.", | |
token, number ); | |
advance( '%' ); | |
} | |
if ( number > 1 ) { | |
warning( "The last parameter of an RGBA value must be a decimal between 0 and 1", | |
token, number ); | |
} | |
console.log( nexttoken, number ); | |
} else { | |
if (nexttoken.id === '%') { | |
advance('%'); | |
if (number > 100) { | |
warning("Expected a percentage and instead saw '{a}'", | |
token, number); | |
} | |
} else { | |
if (number > 255) { | |
warning("Expected a small number and instead saw '{a}'", | |
token, number); | |
} | |
} | |
} | |
} | |
} | |
advance(')'); | |
return true; | |
} else if (cssColorData[nexttoken.value] === true) { | |
advance(); | |
return true; | |
} | |
} else if (nexttoken.type === '(color)') { | |
advance(); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment