jaames / iro.js

🎨 Modular color picker widget for JavaScript, with support for a bunch of color formats
https://iro.js.org
Mozilla Public License 2.0
1.32k stars 82 forks source link

Possible to determine element from color:change etc. #245

Open moracca opened 1 year ago

moracca commented 1 year ago

When referencing a ColorPicker instance, we can call the el method on the object to get the HTML element that the color picker was mounted to. When we add callbacks to the color picker, for example color:change or input:end, we are passed a Color instance, that has properties describing the current color state of the picker.

My question however, is whether it is possible to determine within the callback function which ColorPicker this Color object corresponds to? The end goal being to grab some data-* attributes from the HTML element the color picker was mounted to in order to perform some action that is specific to this color picker (as opposed to other color pickers which may be rendered on the same page). Can this be done? I can't find a way to reference the element or ColorPicker instance from the Color instance, and don't see it listed in the Colors API, but it seems that this would be a common use case, so perhaps I am missing something.

Thanks!