Git Product home page Git Product logo

css3-colorpicker's Introduction

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

css3-colorpicker's People

Contributors

gruppler avatar lingo avatar

Watchers

 avatar  avatar

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.