-
Notifications
You must be signed in to change notification settings - Fork 222
Description
Firstly this is a brilliant little tool, and were implementing it where i work (I added a few little events a while ago to help with throttling an associated chart).
Anyhow were in a situation where its possible the picker could be passed a non RGB
or HEX
value such as red
or blue
. We would need this to be detected and converted into the selected colour format so the picker will continue to function.
Ive had another look through the code base and found a potential solution. The colour could be checked in the ngModel
watch. A regex could be used to check if its not RGB or HEX and if so run it through a converter, then continue.
The psuedo code below should do the trick.
function convertRGB(val){
var d = document.createElement("div");
d.style.color = val;
document.body.appendChild(d)
val = window.getComputedStyle(d).color ;
document.body.removeChild(d);
return val;
}
I am a little concerned with window.getComputedStyle
, its support is IE9+. My other concern with that implementation is the adding and removing of DOM elements. It could be possible to have a hidden element that persists for this use so we don't have to create and remove it speeding the process up.
Lastly this will convert it to a RGB string so finally if HEX or RGBA is selected we will have to convert it again to that format.
Would this be an extra feature that could be included? I don't mind it being an opt-in feature with the use of a data-attribute etc. If it is something then i can have a pull request ready by tomorrow.
Again thanks!