Coder Social home page Coder Social logo

pitpik / tinycolorpicker Goto Github PK

View Code? Open in Web Editor NEW
276.0 18.0 78.0 513 KB

Tiny jQuery color picker for mobile and desktop with alpha channel

Home Page: http://www.dematte.at/tinyColorPicker/

License: MIT License

JavaScript 69.27% CSS 18.73% HTML 12.00%

tinycolorpicker's Introduction

tinyColorPicker and colors

Looking for mobile first, tiny foot print, fast, scaleable, flexible, pluggable and a rich color model...
This small (5.07KB gZip, 11.39KB minified, no extra HTML, images or css needed) HSB colorpicker is based on a subset of colors.js from it's big brother colorPicker for a precise and rich color model, supports all modern features like touch and MS pointer, GPU accelerated rendering, battery friendly requestAnimationFrame and provides a lot of hooks for developers to write plugins or extend the UI.

##Demo See demo at dematte.at/tinyColorPicker

Supports WCAG 2.0 calculations for readability based on opacity levels of multiple layers.
Supported color spaces are: rgb, hsv(b), hsl, HEX.
CMYK, CMY, Lab and XYZ and more standards are supported if using colors.js from github.com/PitPik/colorPicker

Usage

<script type="text/javascript" src="jqColorPicker.min.js"></script>
<script type="text/javascript">
    $('.color').colorPicker(/* optinal options */); // that's it
</script>

jqColorPicker.min.js holds all necessary data such as HTML, CSS and images in one file to run tinyColorPicker. So, it is not needed to include anything else than this single file.
If you need to debug things for development, you can also use colors.js, the color calculation module, and jqColorPicker.js, the UI and interaction module seperately.

<script type="text/javascript" src="colors.js"></script>
<script type="text/javascript" src="jqColorPicker.js"></script>
<script type="text/javascript">
    $('.color').colorPicker();
</script>

AMD / CommonJS wrapper

tinyColorPicker now supports AMD and CommonJS import (thanks to Munawwar) in both, the minified version and the single fies (colors.js and jqColorPicker.js).

// example for requirejs configuration
requirejs.config({
    baseUrl: 'scripts',
    paths: {
        jquery: 'lib/jquery-2.2.1.min'
    },
    shim: {
        'colorPicker': {
            deps: [ 'jquery' ],
            exports: 'jQuery.fn.colorPicker'
        }
    }
});

// then use tinyColorPicker in your module...
(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define(['jquery', 'jqColorPicker'], function (jQuery) {
            return factory(root, jQuery);
        });
    } else {
        factory(root, root.jQuery);
    }
}(this, function(window, $){
    $('.color').colorPicker(options);
}));

Bower support

tinyColorPicker can be received via bower:

bower install tinyColorPicker

jqColorPicker.js

jqColorPicker.js is a jQuery plugin including the UI, CSS and images and uses an instance of Colors (from colors.js) for all the color calculations. It passes the options to that instance, so some values might be the same when inspecting...

$('.color').colorPicker({
    color: ..., // see Colors below...
    customBG: '#FFF' // see Colors below...
    animationSpeed: 150, // toggle animation speed
    GPU: true, // use transform: translate3d or regular rendereing (top, left)
    doRender: true | 'selector', // render color and bgColor of input field (on certain elements if selector)
    opacity: true, // enable / disable alpha slider
    buildCallback: function($elm) {
         // 'this': colorPicker instance; // will be the same as in positionCallback() and renderCallback();
         // $elm: the UI (<div class="cp-color-picker"></div>)
    },
    renderCallback: function($elm, toggled) {
        // 'this': current colorPicker instance; // instance has all kinds of information about colorPicker such as $UI including dimensions etc...
        // $elm: the input field or other element that just toggled the colorPicker;
        // toggle -> 'true': just appeared; 'false': just closed; 'undefined': is rendering
    },
    positionCallback: function($elm) {
        // 'this': current colorPicker instance;
        // $elm: the input field or other element that just toggled the colorPicker;
        // optionally...
        return {top: y, left: x}; // positions colorPicker before appearing
    },
    css: '', // String: replaces existing css
    cssAddon: '', // String: adds css to existing
    margin: '', // positioning margin (can also be set in cssAddon)
    scrollResize: true // toggle for repositioning colorPicker on window.resize/scroll
    gap: 4 // gap to right and bottom edge of view port if repositioned to fit
    dark: '#222' // default font color if background is light
    light: '#DDD' // default font color if background is dark
    preventFocus: false // prevents default on focus of input fields (e.g. no keyboard on mobile)
    body: document.body // the element where the events are attached to (touchstart, mousedown, pointerdown, focus, click, change),
    forceAlpha: // force printing alpha channel (undefined = auto; false = never print alpha),
    cssPrepend: // makes add CSS being added to the beginning of the <head> instead of to the end
});

See the following section or the demos on how the callbacks work and what you can do with them...

Some tips

The positionCallback can be used to optionally position the colorPicker different from its default; in case you want it to also show above or to the left of the input field etc. The callback will also be called on scroll. If you return an object ({left: x, top: y} to position the colorPicker) then those coordinates will be taken, otherwhise the function just executes (what you need to do: re-append for example) and it takes the internal algorithm to position the color picker. See ./demo/index.js for an example:

positionCallback: function($elm) {
    var $UI = this.$UI, // this is the instance; this.$UI is the colorPicker DOMElement
        position = $elm.offset(), // $elm is the current trigger that opened the UI
        gap = this.color.options.gap, // this.color.options stores all options
        top = 0,
        left = 0;

    // $UI.appendTo('#somwhereElse');
    // do here your calculations with top and left and then...
    return { // the object will be used as in $('.something').css({...});
        left: left,
        top: top
    }
}

This callback is also good if you need to append your colorPicker to a different container than document.body. This way you can then calculate the coordinates relative to the appended container...

The renderCallback can be used as openCallback and closeCallback:

renderCallback: function($elm, toggled) {
    if (toggled === true) { // simple, lightweight check
        // ... like an open callback
    } else if (toggled === false) {
        // ... like a close callback
    } else {
        // rendering...
    }
}

Here you can fire events if necessary or check for a className or data attribute on $elm to see if there is a hint for hiding the opacity slider:

this.$UI.find('.cp-alpha').toggle(!$elm.hasClass('no-alpha'));

colors.js

This section only shows the options for color.js. They are picked up automatically if set in $('.color').colorPicker({/* options */});

Colors({ // all options have a default value...
    color: 'rgba(204, 82, 37, 0.8)', // initial color (#RGB, RGB, #RRGGBB, RRGGBB, rgb(r, g, b), ...)
    grey: {r: 0.298954, g: 0.586434, b: 0.114612}, // CIE-XYZ 1931
    luminance: {r: 0.2126, g: 0.7152, b: 0.0722}, // W3C 2.0
    valueRanges: {rgb: {r: [0, 255], g: [0, 255], b: [0, 255]}, hsv:...}, // skip ranges if no conversion required
    customBG: '#808080' // the solid bgColor behind the chosen bgColor (saved color)
    convertCallback: function(colors, type){}, // callback function after color convertion for further calculations...
});

The color model, the methods and more

After initializing Color or ColorPicker you'll get a clean but rhich model of the instance:

myColors: {
    colors: { all kinds of color values...  see later},
    options: { all the options you set or that are set as default... },
    __proto__: { // all methods Color uses (See https://github.com/PitPik/colorPicker for details)
        setColor: function(newCol, type, alpha) {},
        setCustomBackground: function(col) {},
        saveAsBackground: function() {},
        // new method: converts current color to HTML-String like: rgba(123, 234, 0, 0.89)
        // forceAlpha === true / false -> alway / never print alpha, === undefined -> auto
        toString: function('rgb' || 'hsl' || 'hex' || '' -> 'rgb', forceAlpha) {},
    }
}

colors.js is a quite handy tool for color calculations/conversion (gray value, contrast and luminance, etc...). It can also calculate layer mixes between background and foreground colors and therefore make calculations about readability (WCAG 2.0 standard). If you need more complex calculations or more color spaces, use the version from https://github.com/PitPik/colorPicker. It supports also cmy, cmyk, XYZ and Lab.

myColorPicker: {
    $trigger: ... // jQuery object of active trigger or null if none active
    $UI: ... // jQuery object of the colorPicker HTML element
    color: { // instance of Color inside colorPicker
        colors: { all kinds of color values... see later},
        options: { all the options you set or that are set as default... },
        __proto__: { all methods Color uses ... see above}
    },
    __proto__: { // all methods ColorPicker uses
        render: function() {},
        toggle: function(openClose) {} // openClose: true = open; false = close
    }
}

The color model

HEX: // current color as HEX (upper case, 6 digits)
rgb: // current RGB color as normalized values (0 - 1)
    r: // red
    g: // green
    b: // blue
hsv: // current color values in normalized HSV (HSB) model
    h: // hue
    s: // saturation
    v: // value (brightness)
hsl: // current color values in normalized HSL model
    h: // hue
    s: // saturation
    l: // lightness
RND: // all above colors in their defined ranges
    rgb: // current RGB color, rounded between 0 and 255
        r: // red (0 - 255)
        g: // green (0 - 255)
        b: // blue (0 - 255)
    hsv: // see above
        h: // hue (0 - 360 degrees)
        s: // saturation (0 - 100 %)
        v: // value (brightness) (0 - 100 %)
    hsl: // see above
        h: // hue (0 - 360 degrees)
        s: // saturation (0 - 100 %)
        l: // lightness (0 - 100 %)
background: // saved (background) color (saveAsBackground(){})
    rgb: // color in RGB model
        r: // red
        g: // green
        b: // blue
    RGB: // RGB color, rounded between 0 and 255
        r: // red (0 - 255)
        g: // green (0 - 255)
        b: // blue (0 - 255)
    alpha: // alpha or opacity value (0 - 1)
    equivalentGrey: // r = g = b = (0 - 255)
    rgbaMixBlack: // saved (background) color mixed with solid black color
        r: // red
        g: // green
        b: // blue
        a: // resulting alpha or opacity value (0 - 1)
        luminance: // luminance of resulting mix (0 - 1)
    rgbaMixCustom: // saved (background) color mixed with custom (solid) color
        r: // red
        g: // green
        b: // blue
        a: // resulting alpha or opacity value (0 - 1)
        luminance: // luminance of resulting mix (0 - 1)
    rgbaMixWhite: // saved (background) color mixed with solid white color
        r: // red
        g: // green
        b: // blue
        a: // resulting alpha or opacity value (0 - 1)
        luminance: // luminance of resulting mix (0 - 1)
alpha: // alpha or opacity value (0 - 1) of current color
equivalentGrey: // r = g = b = (0 - 1)
HUELuminance: // luminance of hue (in full brightnes and saturation) (0 - 1)
RGBLuminance: // luminance of the current color
hueRGB: // rounded integer value of current color in rgb model with full saturation and brightness
    r: // red (0 - 255)
    g: // green (0 - 255)
    b: // blue (0 - 255)
saveColor: // '' or 'web smart' or 'web save', if so.
webSave: // closest web-save color
    r: // red (0 - 255)
    g: // green (0 - 255)
    b: // blue (0 - 255)
webSmart: // closest web-smart color
    r: // red (0 - 255)
    g: // green (0 - 255)
    b: // blue (0 - 255)
rgbaMixBG: // color mix result: current color above saved (background) color
    r: // red (0 - 1)
    g: // green (0 - 1)
    b: // blue (0 - 1)
    a: // resulting alpha or opacity value (0 - 1)
    luminance: // luminance of resulting mix (0 - 1)
rgbaMixBGMixCustom: // color mix result: current color above saved (background) color above solid custom color
    r: // red (0 - 1)
    g: // green (0 - 1)
    b: // blue (0 - 1)
    a: // resulting alpha or opacity value (0 - 1)
    luminance: // luminance of resulting mix (0 - 1)
    luminanceDelta: // luminance difference between current color and resulting saved-custom mix (0 - 1)
    hueDelta: // hue difference between current color and resulting saved-custom mix (0 - 1)
    WCAG2Ratio: // readability vale (1 - 21, 1:1 to 21:1)
rgbaMixBlack: // color mix result: current color above solid black
    r: // red (0 - 1)
    g: // green (0 - 1)
    b: // blue (0 - 1)
    a: // resulting alpha or opacity value (0 - 1)
    luminance: // luminance of resulting mix (0 - 1)
    WCAG2Ratio: // readability vale (1 - 21, 1:1 to 21:1)
rgbaMixWhite: // color mix result: current color above solid white
    r: // red (0 - 1)
    g: // green (0 - 1)
    b: // blue (0 - 1)
    a: // resulting alpha or opacity value (0 - 1)
    luminance: // luminance of resulting mix (0 - 1)
    WCAG2Ratio: // readability vale (1 - 21, 1:1 to 21:1)

tinycolorpicker's People

Contributors

katacarbix avatar padawin avatar pitpik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinycolorpicker's Issues

Impossibile to set a color from another script

I've tried in many ways, but it seems to be impossibile to set a color from another script.
HERE is an example at the bottom of the page.

Also, it's not possibile to call the "renderCallback" twice.

I'm completly stucked......

Multiple calling is the problem

Hello,
plugin has a problem when performing multiple calls. E.g.

ย ย ย ย  jQuery (".en-color").colorPicker ({
ย ย ย ย ย ย ย ย  customBG: '# 222'
ย ย ย ย ย ย ย ย  margin: '0px 5px 0'
ย ย ย ย ย ย ย ย  doRender: 'div div'
ย ย ย ย ย ย ย ย  opacity: true
ย ย ย ย  });
ย ย ย ย 
ย ย ย ย  jQuery (".en-color-2").colorPicker ({
ย ย ย ย ย ย ย ย  customBG: '# 222'
ย ย ย ย ย ย ย ย  margin: '0px 5px 0'
ย ย ย ย ย ย ย ย  doRender: 'div div'
ย ย ย ย ย ย ย ย  opacity: false
ย ย ย ย  });

When selector en-color-2 opacity is TRUE, because he was called plugin. The problem is probably here
$ .fn.colorPicker = function (options) {...}

because variables are created as _colorPicker or _instance that are out of this feature. Can you look at it?

Thanks

Issue using jQuery Button

i have a button like below but i cant seem to get the color picker to work with it. What Happens is the color picker shows up in the bottom left corner of the screen instead of below the button.

<script type="text/javascript"> $(document).ready(function () { $('#TestButton').button({ text:false, icons:{primary:'ui-icon-plus'} }).click(function (e) { e.preventDefault(); }).colorPicker(); }) </script>

Minified version doens't work with RequireJS

When I use the current jqColorPicker.min.js with RequireJS, something goes wrong:

TypeError: $(...).colorPicker is not a function
$('.input--color').colorPicker({

When I use the seperate colors.js and jqColorPicker.js files, everything is fine.
Probably the AMD wrapper is wrong in the minified version, can you fix this?

set color dynamically

Hi PitPik!

Your colorpicker is pretty nice and I really like it. But I have a question: how to set a color dynamically? I use 'div' variation.

Thanks!

Typo in documentation

There is a typo in the documentation "buidCallback", should be "buildCallback" ;)

Color selection disappears

$('#color').colorPicker({renderCallback: function($elm,toggled) {
        var color=$elm.text
        console.log(color)
        $('.result').css('border-color', $elm.text)
    }});

When the color picker open๏ผŒit all ok๏ผŒbut when it close๏ผŒmy border color will disappear๏ผŒand Console final output an empty color.....

No destroy() method

Plugin can not be used in single-page applications. Please add destroy() method.

TinyColorPicker box is not visible

Without set z-index:9999 hard in code the "cp-color-picker" is not visible for me. What is the best way to fix this? ;)

I add:
....H=".cp-color-picker{....;z-index:9999}.....

EDIT: Refresh colorpicker

Hello! nice component!
Question: Is there a way to update the component (input background, etc) after modifiying the input content by code?

Initialize:

$('#colorpick').colorPicker();

Modify input:

$('#colorpick').val('#FF0000');

The value changes but the background stays.
some ideas?

Uncaught ReferenceError: Colors is not defined

Instead of

<script type="text/javascript" src="jqColorPicker.min.js">

(minimized version), I tried jqColorPicker.js (full version) and get a error in console

jqColorPicker.js:317 Uncaught ReferenceError: Colors is not defined

Hide the text from input field

Me again...
How can i hide the text from the field, once it has been rendered.

I'd like just a black box. most likely a cssadon, but i can't find an example.
screenshot 2015-12-15 13 18 28

Doesn't operate well with jQuery UI

I have tried to use this plugin in combination with a simple CMS system. I can call the function $('.color').colorPicker(); without any issues, and I am still able to drag and drop elements in the CMS but when I simply click the input field and close the color select again, the sortable, draggable and droppable features are no longer working. The elements simply losses functionality.

Cursor disappears while clicking on devtools-like tCP

Hi @PitPik ;)

If I try http://www.dematte.at/tinyColorPicker/?type=dev_skinned#demo
and click somewhere not at inputs (e.g. while trying to copy rgb code, or just in the gaps), the cursor disappears and is visible only after the mouse button is released.
Other modes work great though :)

Also, a little enhancement proposal: It would be cool if user could specify which palette element to replace. For now the palette is just a queue :( And I believe, as arrow (<) points to the most right square, colors should appear from the right ๐Ÿ˜

Not showing current values on rgb text-box

I tried to use sample from 'plugin.input' which was provided as sample in index,js. After that it showed me that rgb text-boxes but values are nil. It also not shows any values there if I move the sliders inside the picker.
Second thing it also loads jqColorPicker.js.map. Total upload size comes out to 27kb instead of 4kb as mentioned in the site.

Screenshot is attached.
colorpick issue

How to move the color picker box

First of all I want to thank You for develop the nice and useful plugin. But now I want to modify it and want to insert .cp-color-picker div into custom container instead the body.

Is it possible ?

Dependencies in bower.json

The jquery dependency is defined as "jQuery": "^2.2.1" - first of all, the bower package for jQuery is called jquery, not jQuery - I'm now pulling in 2 versions of jquery because of this. Secondly, I'm using jquery 1.12.1.1, which is excluded by your version range, but it works just fine. Maybe >= 1.12.0 < 3.0.0 or something like that would be a better version range, because it would work with older jQuery versions.

Misspelled callback

Hi, I have been playing with your script...it's great...but your have the following spelling oops.

buidCallback instead of buildCallback.

I see that I am not the only one that does this.

Thanks,
Greg

Change()-event not working?

I have 20 inputs with colorPicker and want catch change-events and user inputs with:

$(document).on('change keyup', '#color1', function(){console.log($(this).val());});

but nothing happen in console, after change color with colorPicker. Only user inputs working.

build and preRender bug

add in line 18:
_toggle,
insert in line 200:
if(_toggle == toggled){ return } _toggle = toggled;
replace in line 312:
var value = extractValue(this), mode = value.split('('), $elm = findElement($(this));
to:
var $elm = findElement($(this)), value = extractValue($elm), mode = value.split('(');

Callback drop code

I use this code

$('input.color').colorPicker({
    renderCallback: function($elm, toggled)
    {
        console.log($elm.text);
        $('#field').css('background-color', $elm.text);
    }
});

Now I open the box and move cursor for colors. Result in inspector(console.log) is like:

#1B2938
#112132

#102032

#0F2032
#0E1F32

You can see the empty lines? From time to time the color-code is "empty". Tested with chrome.

Change alpha value make extrem flicking the #field. The input value is always correct. :)

offsetWidth/offsetHeight Deprecated by 4/2016

I don't know about other browsers but definitely Chrome .. google advises using object.getBoundingClientRect() and jQuery is following suit by removing osWidth/Height in version 3.0 which should arrive this summer.

Great plugin, very useful.

Keep changes?

I not sure this is a bug or a mistake from me. I use this code:

$('input.color').colorPicker({
renderCallback: function($elm, toggled)
{
console.log($elm.text);
$('#field').css('background-color', $elm.text);
}
});

After close the colorpicker box the changed color in #field is removed. How I can stop this? Like the input field I want the color in #field too. ;)

Here a example: http://jsfiddle.net/030j27LL/1/
click on a input field, change color and close box. the field above lost background-color.

Empty input?

I have optional input fields to set a color or not to change the color. Its possible to clear the input field without colorPicker replace empty fields with his color-code after close?

Event handler not working anymore

I've had this working for some time now, in a project. (using version from before xmas)

I just updated it, and my event handler is no longer working.

Here is a link to the html file with the full js.. https://github.com/sticilface/Melvanimate/blob/master/examples/Melvanimate-example/data/index.htm

the code for the render is here


                $('.color').colorPicker({
                    preventFocus: true,
                    renderCallback: function($elm, toggled) {
                        if (toggled === true) { // simple, lightweight check
                            // ... like an open callback
                        } else if (toggled === false) {
                              console.log("RENDER TRIGGERED");
                            // ... like a close callback
                            //var nameof = $(this).attr("name"); 
                            //var $form = $(this).closest('input');

                            //console.log($form.attr('name'));
                            var colors = this.color.colors,
                                rgb = colors.RND.rgb;
                            //console.log(rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + colors.alpha);

                            var $form = $elm.closest('form');
                            var inputName = $elm.attr('name');

                            $("#status").empty().append("Waiting ").css("color", "blue");;

                            $.post("data.esp", inputName + "=" + rgb.r + "," + rgb.g + "," + rgb.b 
                                // function(data) {
                                //     console.log(data);
                                // }
                            ).success(function(e) {
                              if (e) {
                                processJSON(e); 
                              }
                            $("#status").empty().append("Success").css("color", "green");;
                        })
                        .error(function() {
                            $("#status").empty().append("Error").css("color", "red");;
                        })
                        .complete(function() {});

                            $elm.css('color', "rgb(" + colors.RND.rgb.r + "," + colors.RND.rgb.g + "," + colors.RND.rgb.b + ")");
                            $elm.css('text-shadow', 'none');
                        }
                    },
                    buildCallback: function($elm) {
                        var colorInstance = this.color,
                            colorPicker = this,
                            random = function(n) {
                                return Math.round(Math.random() * (n || 255));
                            };
                        $elm.append('<div class="cp-memory">' +
                            '<div></div><div></div><div></div><div></div>' +
                            '<div></div><div></div><div></div><div class="cp-store">S</div>').
                        on('click', '.cp-memory div', function(e) {
                          console.log("Colour picker click"); 
                            var $this = $(this);

                            if (this.className) {
                                $this.parent().prepend($this.prev()).children().eq(0).
                                css('background-color', '#' + colorInstance.colors.HEX);
                            } else {
                                colorInstance.setColor($this.css('background-color'));
                                colorPicker.render();
                            }
                        }).find('.cp-memory div').each(function() {
                            !this.className && $(this).css({
                                background: 'rgb(' + random() + ', ' + random() + ', ' + random() + ')'
                            });
                        });
                    },
                    opacity: false,
                    cssAddon: // could also be in a css file instead
                        '.cp-memory {margin-bottom:6px; clear:both;}' +
                        '.cp-xy-slider:active {cursor:none;}' +
                        '.cp-memory div {float:left; width:17px; height:17px; margin-right:2px;' +
                        'background:rgba(0,0,0,1); text-align:center; line-height:17px;}' +
                        '.cp-memory .cp-store {width:21px; margin:0; background:none; font-weight:bold;' +
                        'box-sizing:border-box; border: 1px solid; border-color: #666 #222 #222 #666;}' +
                        '.cp-color-picker{z-index:16777271}'
                });

                // $("#brightness").on('slidestop', function() {
                //     $("#status").empty().append("Waiting...").css("color", "blue");;
                //     $.post("data.esp", $(this).serialize())
                //         .success(function(e) {
                //             processJSON(e); 
                //             $("#status").empty().append("Success").css("color", "green");;
                //         })
                //         .error(function() {
                //             $("#status").empty().append("Error").css("color", "red");;
                //         })
                //         .complete(function() {});
                // });

                // $("#speed").on('slidestop', function() {
                //     $("#status").empty().append("Waiting...").css("color", "blue");;
                //     $.post("data.esp", $(this).serialize())
                //         .success(function(e) {
                //             processJSON(e); 
                //             $("#status").empty().append("Success").css("color", "green");;
                //         })
                //         .error(function() {
                //             $("#status").empty().append("Error").css("color", "red");;
                //         })
                //         .complete(function() {});
                // });
            });

the colour picker seems to work fine. appears... selects colours... but it doesn't fire to send it off... and I've no idea why

First colorPicker popup doesnt hide.

I added two <a> elements on a jQuery Mobile page and called colorPicker() on each of them separately. While the color picker popup shows up fine for both the elements, when I click outside the popup, it doesn't hide for the first <a>. If I just try the second <a>, everything works fine.

Am I missing something ?

Colors is not defined

Getting the error "Colors is not defined" in the last line of jqColorPicker.js
})(window.jQuery, Colors);

issue on IE11?

is there a pick color issue on ie11? it's ok on ie10 and chrome, but on ie11, when i picked color, the value of the input field which binded to this colorpicker plugin, its value is "#NANNANNAN". im not sure if i use it in a wrong way, thanks for help.

the code is like below:

    var $colors = $('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';
        }
    }).each(function (idx, elm) {
        $(elm).css({ 'background-color': this.value })
    });

note: im using bootstrap at the same page, is that a problem?

Get the parent input "name"

I'm using jquerymobile and I'm struggling to retrieve the parent input name to use in the rendercallback.

I'd like the input field name

    <div class="form-group">
        <label for="hue-demo">Color One</label>
        <input type="text" name="color1" id="color1" class="color" data-control="hue" value="">
    </div>
          renderCallback: function($elm, toggled) {
    if (toggled === true) { // simple, lightweight check
        // ... like an open callback
    } else if (toggled === false) {
        // ... like a close callback
            //var nameof = $(this).attr("name"); 
            var $form = $(this).closest('input'); //  THIS DOESN'T WORK
            console.log($form.attr('name')); 
            var colors = this.color.colors,
            rgb = colors.RND.rgb;
            console.log(rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + colors.alpha);
            //var data = new Object();
            //myObject = data.color; 
            var myObject = new Object();
              myObject.color = {}; 
              myObject.color.R = rgb.r;
              myObject.color.G = rgb.g;
              myObject.color.B = rgb.b;
              myObject.color.alpha = colors.alpha; 
              console.log(JSON.stringify(myObject));
              $.post("data.esp", JSON.stringify(myObject), 
              function(data) {
                console.log(data); 
              }
              );
    }

forgive me if this is easy. I'm fairly hopeless with web based programming...

Box not disappear

Go to http://www.dematte.at/tinyColorPicker/ click on first input, the box is open. Now click on box with example code under the box. the box not disappear, its moving to grey example box.

See here: http://picload.org/image/cwcidrr/bugcolorpickera.png
EDIT: Go to http://www.dematte.at/tinyColorPicker/ and click only on grey box. the colorpicker will appear. why?

Here more: http://jsfiddle.net/030j27LL/
Click on a input field and try to close the box. its only working with click above the box. Not left, right or bottom the box.

Optimize the position of the ColorPicker

Currently it will cover the input if it's near the bottom as below.
image

so I modified the function "toggle(event)" (line: 86) to make it better.
'top': (_$UI[0].top = position.top + $this.outerHeight()) -
((
$UI[0]._top = _$UI[0]._top + _$UI[0].height -
($window.scrollTop() + $window.height())) + gap > 0 ?
(
$UI[0]._top + gap) < _$UI[0]._height ? _$UI[0]._height + $this.outerHeight() + gap: _$UI[0]._top + gap : 0)
image

but I have one doubt, in the package, the file "jqColorPicker.min.js" is combined by "colors.js" and "jqColorPicker.js" , right?
If yes, why after I combined them manually and used "uglifyjs2" to minify, the result file size(16K) is still bigger than your "jqColorPicker.min.js"(11K)?

ReferenceError: Can't find variable: Colors

Hi,

I am trying out the tinyColorPicker, but I don't seem to get it to work.

Basically, I am only loading jQuery and then jqColorPicker.js.

However, when trying to bind the plugin to a number of input fields with class "colorpicker", it throws the following error:
ReferenceError: Can't find variable: Colors

Note that I did not include colors.js yet, since you wrote on your homepage that only one file is needed.

Thanks!

/b

ColorPicker as a static element

I am very new to jQuery, so I apologize if there is something simple I missed in the documentation. I would like to use the ColorPicker as a static element on a page (i.e. you don't have to click on another element to get the picker to appear: it is always visible on the page). Is there a particular property I can set to make that happen?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.