GithubHelp home page GithubHelp logo

jrparish / farbtastic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mattfarina/farbtastic

0.0 2.0 0.0 60 KB

jQuery Color Wheel

License: GNU General Public License v2.0

HTML 9.22% JavaScript 90.78%

farbtastic's Introduction

Farbtastic: jQuery color picker plug-in

Farbtastic is a jQuery plug-in that can add one or more color picker widgets into a page. Each widget is then linked to an existing element (e.g. a text field) and will update the element's value when a color is selected.

Farbtastic 2 uses the html5 canvas element to render a saturation/luminance gradient inside of a hue circle. In order to work with Internet Explorer, which does not currently support the canvas element, Explorer Canvas is needed to translate the canvas usage into features native to Internet Explorer.

Notice: The 2.x branch is under development and considered not production ready. If you are interested in a production tested version see the 1.x branch.

Farbtastic was originally written by Steven Wittens and is licensed under the GPL.

Basic Usage

  1. Include farbtastic.js in your HTML:

    <script type="text/javascript" src="farbtastic.js"></script>
  2. Add a placeholder div and a text field to your HTML, and give each an ID:

  3. Add a ready() handler to the document which initializes the color picker and link it to the text field with the following syntax:

    <script type="text/javascript"> $(document).ready(function() { $('#colorpicker').farbtastic('#color'); }); </script>

See demo/test.html for an example.

Advanced Usage

jQuery Method

$(...).farbtastic()
$(...).farbtastic(callback)

This creates color pickers in the selected objects. callback is optional and can be a:

  • DOM Node, jQuery object or jQuery selector: the color picker will be linked to the selected element(s) by syncing the value (for form elements) and color (all elements).
  • Function: this function will be called whenever the user chooses a different color.

Object

$.farbtastic(placeholder)
$.farbtastic(placeholder, callback)

Invoking $.farbtastic(placeholder) is the same as using $(placeholder).farbtastic() except that the Farbtastic object is returned instead of the jQuery object. This allows you to use the Farbtastic methods and properties below. Note that there is only one Farbtastic object per placeholder. If you call $.farbtastic(placeholder) twice with the same placeholder, you will get the same object back each time.

The optional callback argument behaves exactly as for the jQuery method.

Options

$(...).farbtastic(options)
$.farbtastic(placeholder, options)

Farbtastic 2 provides the ability to pass in other options beyond a callback. The possible options are:

  • callback: The callback as described previously.
  • height: The height of the widget.
  • width: The width of the widget.

An example usage would be $(...).farbtastic({ callback: '#color2', width: 150 }).

Methods

.linkTo(callback) - Allows you to set a new callback. Any existing callbacks are removed. See above for the meaning of callback.

.setColor(string) - Sets the picker color to the given color in hex representation.

.setColor([h, s, l]) - Sets the picker color to the given color in normalized HSL (0..1 scale).

Properties

.linked - The elements (jQuery object) or callback function this picker is linked to.

.color - Current color in hex representation.

.hsl - Current color in normalized HSL.

farbtastic's People

Contributors

calvincorreli avatar codingisacopingstrategy avatar darkv avatar johnalbin avatar mattfarina avatar robloach avatar unconed 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.