zsinryu / jquery-miniColors

jQuery MiniColors Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jQuery miniColors: A small color selector

Copyright 2012 Cory LaViska for A Beautiful Site, LLC. (http://www.abeautifulsite.net/)

Dual licensed under the MIT / GPLv2 licenses

Demo

http://labs.abeautifulsite.net/jquery-miniColors/

Usage

  1. Link to jQuery: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  2. Link to miniColors: <script type="text/javascript" src="jquery.miniColors.js"></script>
  3. Include miniColors stylesheet: <link type="text/css" rel="stylesheet" href="jquery.miniColors.css" />
  4. Apply $([selector]).miniColors() to one or more INPUT elements

Options

  • 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

Specify options on creation:

$([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

Methods are called using this syntax:

$([selector]).miniColors('methodName', [value]);

Available Methods

  • 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)

Events

  • 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)

Examples

// 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 + ')');
	}
});

Known Issues

  • IE7/8 do not show opacity in the trigger since it uses RGBA

Attribution

About

jQuery MiniColors Plugin