<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Acko.net]]></title>
  <link href="https://acko.net/atom.xml" rel="self"/>
  <link href="https://acko.net/"/>
  <updated>2026-03-05T12:10:39+01:00</updated>
  <id>https://acko.net</id>
  <author>
    <name><![CDATA[Steven Wittens]]></name>
    
  </author>

  
  <entry>
    <title type="html"><![CDATA[Farbtastic Color Picker]]></title>
    <link href="https://acko.net/blog/farbtastic-jquery-color-picker-plug-in/"/>
    <updated>2006-07-14T00:00:00+02:00</updated>
    <id>https://acko.net/blog/farbtastic-jquery-color-picker-plug-in</id>
    <content type="html"><![CDATA[<div class="g8 i2 first"><div class="pad">
  
<h2 class="sub">jQuery Plug-in</h2>

<p>
Farbtastic is a <a href="http://www.jquery.com/">jQuery</a> plug-in that can add one or more color picker widgets into a page through JavaScript. 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.
</p>

<p>
<a href="/files/farbtastic/farbtastic12.zip">Download Farbtastic 1.2</a> - January 8, 2007 (License: <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a>).
</p>

</div></div>

<div class="g5 i2"><div class="pad">

<h2>Demo</h2>

<p>
Farbtastic uses layered transparent PNGs to render a saturation/luminance gradient inside of a hue circle. No Flash, no pixel sized divs.
</p>

<p>
Click and drag over the selector to try it out.
</p>

<p>
<form action="">
  <div class="form-item"><label for="color">Color:</label><input type="text" id="color" name="color" value="#123456" style="width: 195px" /></div>
</form>
</p>

</div></div>

<div class="g3"><div class="pad m3">

<link rel="stylesheet" type="text/css" media="screen" href="/files/farbtastic/demo/farbtastic.css" />

<script type="text/javascript" charset="utf-8" src="/files/farbtastic/jquery.min.js"></script>

<script type="text/javascript" charset="utf-8" src="/files/farbtastic/demo/farbtastic.js"></script>

<script type="text/javascript" charset="utf-8">
Acko.queue(function() {
  jQuery.farbtastic('#picker').linkTo('#color');
});
</script>

<div id="picker"></div>

</div></div>

<div class="g8 i2"><div class="pad">

<h2>Basic Usage</h2>
<ol>
<li>
  <p>Include farbtastic.js and farbtastic.css in your HTML:</p>
<p class="codeblock">
<code>&lt;script&nbsp;type=&quot;text/javascript&quot;&nbsp;src=&quot;farbtastic.js&quot;&gt;&lt;/script&gt;<br />
&lt;link&nbsp;rel=&quot;stylesheet&quot;&nbsp;href=&quot;farbtastic.css&quot;&nbsp;type=&quot;text/css&quot;&nbsp;/&gt;
</code></p>
</li><li>
  <p>Add a placeholder div and a text field to your HTML, and give each an ID:</p>
<p class="codeblock"><code>&lt;form&gt;&lt;input&nbsp;type=&quot;text&quot;&nbsp;id=&quot;color&quot;&nbsp;name=&quot;color&quot;&nbsp;value=&quot;#123456&quot;&nbsp;/&gt;&lt;/form&gt;<br />
&lt;div&nbsp;id=&quot;colorpicker&quot;&gt;&lt;/div&gt;<br />
</code></p>
</li>
<li>
  <p>Add a ready() handler to the document which initializes the color picker and link it to the text field with the following syntax:</p>
<p class="codeblock"><code>&lt;script&nbsp;type=&quot;text/javascript&quot;&gt;<br />
&nbsp;&nbsp;$(document).ready(function()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;$('#colorpicker').farbtastic('#color');<br />
&nbsp;&nbsp;});<br />
&lt;/script&gt;<br />
</code></p>
</li></ol>

<p>
See demo1.html and demo2.html for an example (jquery.js is not included!).
</p>

<h2>Styling</h2>

<p>
The color picker is a block-level element and is 195x195 pixels large. You can control the position by styling your placeholder (e.g. floating it).
</p>

<p>
Note that the black/white gradients inside wheel.png and mask.png were generated programmatically and cannot be recreated easily in an image editing program.
</p>

<h2>Advanced Usage</h2>

<h3>jQuery Method</h3>
<dl>
<dt>$(...).farbtastic()
$(...).farbtastic(callback)</dt>
<dd>This creates color pickers in the selected objects. <code>callback</code> is optional and can be a:
<ul>
<li><em>DOM Node</em>, <em>jQuery object</em> or <em>jQuery selector</em>: the color picker will be linked to the selected element(s) by syncing the value (for form elements) and color (all elements).</li>
<li><p><em>Function</em>: this function will be called whenever the user chooses a different color. It should have the following signature:
</p>

<p class="codeblock"><code>function&nbsp;callback(color)&nbsp;{&nbsp;...&nbsp;}</code>
</p>

<p>
With <code>color</code> the chosen color in hex representation (e.g. '#123456').
</p>
</li>
</ul>
</dd>
</dl>

<h3>Object</h3>
<dl>
<dt>$.farbtastic(placeholder)
$.farbtastic(placeholder, callback)
</dt>
<dd><p>Invoking <code>$.farbtastic(placeholder)</code> is the same as using <code>$(placeholder).farbtastic()</code> except that the Farbtastic object is returned instead of the jQuery object. This allows you to use the Farbtastic methods and properties below.
</p>

<p>
Note that there is only one Farbtastic object per placeholder. If you call <code>$.farbtastic(placeholder)</code> twice <em>with the same placeholder</em>, you will get the same object back each time.
</p>

<p>
The optional <code>callback</code> argument behaves exactly as for the jQuery method.
</p>
</dd>
</dl>

<h3>Methods</h3>
<dl>
<dt>.linkTo(callback)</dt>
<dd>Allows you to set a new callback. Any existing callbacks are removed. See above for the meaning of <code>callback</code>.</dd>
<dt>.setColor(string)</dt>
<dd>Sets the picker color to the given color in hex representation (e.g. '#123456').</dd>
<dt>.setColor([h, s, l])</dt>
<dd>Sets the picker color to the given color in normalized HSL (0..1 scale).</dd>
</dl>

<h3>Properties</h3>
<dl>
<dt>.linked</dt>
<dd>The elements (jQuery object) or callback function this picker is linked to.</dd>
<dt>.color</dt>
<dd>Current color in hex representation (e.g. '#123456').</dd>
<dt>.hsl</dt>
<dd>Current color in normalized HSL (e.g. [0.3, 0.4, 0.5]).</dd>
</dl>

</div></div>
]]></content>
  </entry>
  
</feed>
