-
Notifications
You must be signed in to change notification settings - Fork 2
A CSS3 color picker
gruppler/CSS3-Colorpicker
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
CSS3 ColorPicker (https://github.com/gruppler/CSS3-Colorpicker) v1.3.2 Copyright (c) 2011 Craig Laparo (https://plus.google.com/114746898337682206892) Based on "PhotoShop-like JavaScript Color Picker" Copyright (c) 2007 John Dyer (http://johndyer.name) MIT style license Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ Usage: Include these in your header: <link rel="stylesheet" type="text/css" href="colorpicker.css"/> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="colorpicker.js"></script> Apply to your selection: // Default options $(".selector").colorpicker(); // Custom options $(".selector").colorpicker({ realtime: false, invertControls: false, controlStyle: 'raised' }); -------------------------------------------------------------------------------- Options: showAnim: true // [true|false] to enable/disable animations duration: 200 // Fade duration color: 'FFF' // Default color allowNull: false // [true|false] to allow an empty color value; // otherwise default to the default color realtime: true // [true|false] to enable/disable instant updates invertControls: true // [true|false] to enable/disable inverting color // of mouse controls based on luminance controlStyle: 'simple' // Mouse control theme [simple|raised|inset]; // separate multiple themes with a space swatches: true // [true|false] to enable/disable, // or an array of hex codes to pre-fill alpha: false // [true|false] to enable/disable alpha alphaHex: false // [true|false] to enable/disable 4-byte hex // in the format '#AARRGGBB' Options can be retrieved or changed at any time: // Get option's current value $(".selector").colorpicker("option", "color"); // Set option $(".selector").colorpicker("option", "color", "fff"); -------------------------------------------------------------------------------- Events: beforeShow(input, inst) // Fired before the color picker is shown onClose(color, inst) // Fired when the color picker is hidden onSelect(color, inst) // Fired when the color is set onAddSwatch(color, swatches) // Fired when a new color swatch is added Event handlers can be set just like options: // At initialization $(".selector").colorpicker({ onSelect: function(color, inst){...} }); // After initialization $(".selector").colorpicker('option', 'onSelect', function(color, inst){...}); -------------------------------------------------------------------------------- Public Methods: setDefaults(settings) // Set the defaults for all color pickers addSwatch(color, newOnly) // Add a color or array of colors to the swatches; // preserve sorting if 'newOnly' is true clearSwatches() // Remove all swatches refresh() // Update the color picker color(args) // A useful color class hexToRgb(hex, alphaOn) // Returns {r:[0-255], g:[0-255], b:[0-255], a:[0-100]} validateHex(hex, norm, alphaOn) // Returns a valid hex code, // optionally normalized rgbToHex(rgb, alphaOn) // rgb = {r:[0-255], g:[0-255], b:[0-255], [a:[0-100]]} intToHex(dec) // Base conversion from 10 to 16 hextToInt(hex) // Base conversion from 16 to 10 rgbToLum(rgb) // rgb = {r:[0-255], g:[0-255], b:[0-255]} // Returns integer [0-100] rgbToHsv(rgb) // rgb = {r:[0-255], g:[0-255], b:[0-255]} // Returns {h:[0-359], s:[0-100], v:[0-100]} hsvToRgb(rgb) // hsv = {h:[0-359], s:[0-100], v:[0-100]} // Returns {r:[0-255], g:[0-255], b:[0-255]} To use a public method, call it like this: // Validate 'hex' $.colorpicker.validateHex('hex'); // Create a color object var myColor = new $.colorpicker.color({hex: 'ccc'});