Copyright 2012 Cory LaViska for A Beautiful Site, LLC. (http://www.abeautifulsite.net/)
Dual licensed under the MIT / GPLv2 licenses
http://labs.abeautifulsite.net/jquery-miniColors/
- Link to jQuery:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
- Link to miniColors:
<script type="text/javascript" src="jquery.miniColors.js"></script>
- Include miniColors stylesheet:
<link type="text/css" rel="stylesheet" href="jquery.miniColors.css" />
- Apply $([selector]).miniColors() to one or more INPUT elements
- disabled [true,false] - Disables the control on init
- readonly [true,false] - Makes the control read-only on init
- opacity [true, false] - Enables/disables the opacity slider
$([selector]).miniColors({
optionName: value,
optionName: value,
...
});
Preset color:
<input type="text" name="color" value="#FFCC00" />
Preset color and opacity:
<input type="text" name="color" value="#FFCC00" data-opacity=".5" />
Methods are called using this syntax:
$([selector]).miniColors('methodName', [value]);
- letterCase [uppercase|lowercase|null] - forces the hex value into upper or lowercase
- disabled [true|false] - sets the disabled status
- readonly [true|false] - sets the readonly status
- opacity (none) - gets the opacity level (0-1)
- opacity (0-1) - sets the opacity level
- value (none) - gets the current value; guaranteed to return a valid hex color
- value [hex value] - sets the control's value
- destroy (none)
-
change(hex, rgb) - called when the color value changes
-
open(hex, rgb) - called when the color picker is opened
-
close(hex, rgb) - called when the color picker is hidden
-
In all callbacks,
this
refers to the original input element. -
hex
is the hex color code of the selected color -
rgb
is an object containing red, green, and blue values; if opacity is enabled, it will also contain an alpha value (rgb.a)
// Get hex color code on change
$([selector]).miniColors({
change: function(hex, rgb) {
console.log(hex);
}
});
// Get RGBA values on change
$([selector]).miniColors({
opacity: true,
change: function(hex, rgba) {
console.log('rgba(' + rgba.r + ', ' + rgba.g + ', ' + rgba.b + ', ' + rgba.a + ')');
}
});
- IE7/8 do not show opacity in the trigger since it uses RGBA
- The color picker icon is based on an icon from the amazing Fugue icon set: http://p.yusukekamiyamane.com/
- The gradient image, the hue image, and the math functions are courtesy of the eyecon.co jQuery color picker: http://www.eyecon.ro/colorpicker/