Belonit / AEColorPicker

AEColorPicker
The Unlicense
30 stars 1 forks source link

documentation on how to provide a proper long as a starting point? #3

Open vaporstack opened 4 years ago

vaporstack commented 4 years ago

Thank you for this lovely library. I've been using it with much pleasure. I had a hard time finding how to provide a properly configured long though, in the documentation you pass it a literal:

var oldColor = 0x20F186;

I wasn't able to figure out how to define my color as such, I ended up doing something like:

oldColor = eval('0x' + hex);

where hex was my string value. Is there a "good" way to do this? Might help a future user.

Thanks again! lovely piece of kit.

Belonit commented 4 years ago

I'm not really sure I should explain how to use standard JS functions like parseInt([radix]) or Number.prototype.toString([radix]). Moreover, I use the same interface as the standard ColorPicker. Anyway, here is a small example:

var stringColor = "20F186";
var numberColor = parseInt(stringColor, 16);

alert(
    '"stringColor" = ' + stringColor + "\r\n" + 
    '"numberColor" = ' + numberColor + "\r\n" + 
    '"numberColor to string" = ' + numberColor.toString(16).toUpperCase() + "\r\n" + 
    '"numberColor to string === stringColor" = ' + (numberColor.toString(16).toUpperCase() === stringColor).toString()
);

Thanks for the feedback, I'll think about how I can improve the description.