Zak
unread,Apr 19, 2009, 10:04:05 AM4/19/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to MochiKit
I can't get a null result from the fromString method. No matter what
I put in, it's never null. Generally, what I'm expecting it to do is
if I pass in a value that's not hex, not hsl, not rgb, that it should
drop through to the namedColor check and when it doesn't find the
named color, it should return null. But this just never seems to
happen.
Also, it looks like there's not much validation once it's determined
that a color starts with #, rgb or hsl, not too worried about this as
I'll be checking my inputs before creating the color object, but is
this by design?
Here's a short example:
createLoggingPane(true);
var myColor = new Color.fromString("xyz");
log(myColor == null);
^^^
This always returns false for me, no matter what I put in the
constructor. Perhaps there's something wrong with my code? Here's
what I'm actually doing with it so far:
function findColorsClick(text) {
createLoggingPane(true);
var myColor = new Color.fromString("123lksdjf098234lkj");
if (myColor){
var colorNameHash = Color.namedColors();
var myColorName = "[No color name found]";
for (var i in colorNameHash)
{
if (myColor.toHexString() == colorNameHash[i]){
myColorName = i;
break;
}
}
alert("Color Name: " + myColorName + "\nRGB: " + myColor.toRGBString
() + "\nHSL: " + myColor.toHSLString() + "\nHEX: " +
myColor.toHexString() + "\nIs light: " + myColor.isLight() + "\nIs
dark: " + myColor.isDark());
}