Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse non RGB or HEX values #116

Open
ste2425 opened this issue Nov 19, 2015 · 0 comments
Open

Parse non RGB or HEX values #116

ste2425 opened this issue Nov 19, 2015 · 0 comments

Comments

@ste2425
Copy link
Contributor

ste2425 commented Nov 19, 2015

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant