Call the colopicker via javascript:
$('.sample-selector').colorpicker({ /*options...*/ });
You can set colorpicker options either as a plugin parameter or data-* attributes
Name | Type | Default | Description |
---|---|---|---|
format | string | false | If not false, forces the color format to be hex, rgb or rgba, otherwise the format is automatically detected. |
color | string | false | If not false, sets the color to this value. |
container | string or jQuery Element | false | If not false, the picker will be contained inside this element, otherwise it will be appended to the document body. |
component | string or jQuery Element | '.add-on, .input-group-addon' | Children selector for the component or element that trigger the colorpicker and which background color will change (needs an inner <i> element). |
input | string or jQuery Element | 'input' | Children selector for the input that will store the picker selected value. |
horizontal | boolean | false | If true, the hue and alpha channel bars will be rendered horizontally, above the saturation selector. |
template | string | [...] | Customizes the default colorpicker HTML template. |
(behind this line, docs need to be updated)
Initializes an colorpicker.
Show the color picker
Refreshes the widget colors (this is done automatically)
Hide the color picker
Disable the color picker.
Enable the color picker.
Updates the color picker's position relative to the element
Destroys the colorpicker widget and unbind all .colorpicker events from the element and component
Set a new value for the color picker (also for the input or component value). Triggers 'changeColor' event.
Each triggered events have a color object used internally by the picker. This object has several useful methods.
Set a new color. The value is parsed and tries to do a quess on the format.
Set the HUE with a value between 0 and 1.
Set the saturation with a value between 0 and 1.
Set the lightness with a value between 0 and 1.
Set the transparency with a value between 0 and 1.
Returns a hash with red, green, blue and alpha.
Returns a string with HEX format for the current color.
Returns a hash with HSLA values.
The colorpicker plugin exposes some events (with optional .colorpicker namespace)
Event | Description |
---|---|
create | This event fires immediately when the color picker is created. |
showPicker | This event fires immediately when the color picker is displayed. |
hidePicker | This event is fired immediately when the color picker is hidden. |
disable | This event is fired immediately when the color picker is disabled, except if it was initialized as disabled. |
enable | This event is fired immediately when the color picker is enabled, except upon initialization. |
changeColor | This event is fired when the color is changed. |
destroy | This event fires immediately when the color picker is destroyed. |
$('.my-colorpicker-control').colorpicker().on('changeColor', function(ev){ bodyStyle.backgroundColor = ev.color.toHex(); });