PitPik / colorPicker

Advanced javaScript color picker and color conversion / calculation (rgb, hsv, hsl, hex, cmyk, cmy, XYZ, Lab, alpha, WCAG 2.0, ...)
http://www.dematte.at/colorPicker/
MIT License
570 stars 136 forks source link

How to access colorPicker object? #57

Open johnmastri opened 7 years ago

johnmastri commented 7 years ago

From your jQuery example:

$myColorPicker = $('input.color').colorPicker({
        customBG: '#222',
        readOnly: true,
        init: function(elm, colors) { // colors is a different instance (not connected to colorPicker)
            elm.style.backgroundColor = elm.value;
            elm.style.color = colors.rgbaMixCustom.luminance > 0.22 ? '#222' : '#ddd';
        },
        // appendTo: document.querySelector('.the-paragraph')
        // renderCallback: function(colors, mode) {
        //  console.log(mode);
        // }
        // memoryColors: memoryColors,
        // actionCallback: function(event, type) {
        //  if (type === 'toMemory') {
        //      // $myColorPicker.renderMemory(memoryColors);
        //  }
        // }
    }).each(function(idx, elm) {
        // $(elm).css({'background-color': this.value})
    });

I would think doing console.log($myColorPicker) would return the instance of the colorPicker - but it is returning an array. How do I access the colorPicker object (so I can access it's methods, setColor, etc..)?

Thanks!

PitPik commented 7 years ago

Hi @johnmastri , $myColorPicker = $('input.color') is a jQuery Object that is an Array that holds all the collected elements but also holds other information like prevObject, context etc. I put the instance of colorPicker also there: $myColorPicker.colorPicker