From ad2ce4f9b42fc8b3f379d9ad768f1d365f735bb2 Mon Sep 17 00:00:00 2001 From: "steven@acko.net" Date: Wed, 25 Mar 2009 22:15:27 +0000 Subject: [PATCH] Adding fb2 and fb1 --- branches/farbtastic-1/CHANGELOG.html | 32 ++ branches/farbtastic-1/LICENSE.txt | 341 ++++++++++++++++++ branches/farbtastic-1/README.html | 71 ++++ branches/farbtastic-1/demo1.html | 28 ++ branches/farbtastic-1/demo2.html | 57 +++ branches/farbtastic-1/farbtastic.css | 33 ++ branches/farbtastic-1/farbtastic.js | 276 +++++++++++++++ branches/farbtastic-1/marker.png | Bin 0 -> 652 bytes branches/farbtastic-1/mask.png | Bin 0 -> 2020 bytes branches/farbtastic-1/wheel.png | Bin 0 -> 11733 bytes trunk/demo/test.html | 53 +++ trunk/src/farbtastic-2.0.js | 509 +++++++++++++++++++++++++++ 12 files changed, 1400 insertions(+) create mode 100644 branches/farbtastic-1/CHANGELOG.html create mode 100644 branches/farbtastic-1/LICENSE.txt create mode 100644 branches/farbtastic-1/README.html create mode 100644 branches/farbtastic-1/demo1.html create mode 100644 branches/farbtastic-1/demo2.html create mode 100644 branches/farbtastic-1/farbtastic.css create mode 100644 branches/farbtastic-1/farbtastic.js create mode 100755 branches/farbtastic-1/marker.png create mode 100644 branches/farbtastic-1/mask.png create mode 100644 branches/farbtastic-1/wheel.png create mode 100644 trunk/demo/test.html create mode 100644 trunk/src/farbtastic-2.0.js diff --git a/branches/farbtastic-1/CHANGELOG.html b/branches/farbtastic-1/CHANGELOG.html new file mode 100644 index 0000000..4060f05 --- /dev/null +++ b/branches/farbtastic-1/CHANGELOG.html @@ -0,0 +1,32 @@ + + +Farbtastic: Changelog + +

Farbtastic: Changelog

+ +

1.3 - 2009/xx/xx

+ +

1.2 - 2007/01/08

+ +

1.1 - 2006/10/27

+ +

1.0 - 2006/07/14

+ + +

More info on Acko.net.

+

Created by Steven Wittens.

+ + + \ No newline at end of file diff --git a/branches/farbtastic-1/LICENSE.txt b/branches/farbtastic-1/LICENSE.txt new file mode 100644 index 0000000..5a3cc20 --- /dev/null +++ b/branches/farbtastic-1/LICENSE.txt @@ -0,0 +1,341 @@ + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/branches/farbtastic-1/README.html b/branches/farbtastic-1/README.html new file mode 100644 index 0000000..e527472 --- /dev/null +++ b/branches/farbtastic-1/README.html @@ -0,0 +1,71 @@ + + +Farbtastic: jQuery color picker plug-in + +

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 uses layered transparent PNGs to render a saturation/luminance gradient inside of a hue circle. No Flash or pixel-sized divs are used.

+ +

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

+ +

Basic Usage

+
    +
  1. Include farbtastic.js and farbtastic.css in your HTML:
    +
    <script type="text/javascript" src="farbtastic.js"></script>
    <link rel="stylesheet" href="farbtastic.css" type="text/css" />
    +
  2. +
  3. Add a placeholder div and a text field to your HTML, and give each an ID:
    +
    <form><input type="text" id="color" name="color" value="#123456" /></form>
    <div id="colorpicker"></div>
    +
  4. +
  5. 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>
    +
  6. +
+

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

+

Styling

+

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

+

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.

+

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.
+

+
+ + +

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.
+
+
+ + \ No newline at end of file diff --git a/branches/farbtastic-1/demo1.html b/branches/farbtastic-1/demo1.html new file mode 100644 index 0000000..876d9cf --- /dev/null +++ b/branches/farbtastic-1/demo1.html @@ -0,0 +1,28 @@ + + + + Farbtastic + + + + + + +

jQuery Color Picker: Farbtastic

+ +
jQuery.js is not present. You must install jQuery in this folder for the demo to work.
+ +
+
+
+ +

More info on Acko.net.

+

Created by Steven Wittens.

+ + diff --git a/branches/farbtastic-1/demo2.html b/branches/farbtastic-1/demo2.html new file mode 100644 index 0000000..59a9325 --- /dev/null +++ b/branches/farbtastic-1/demo2.html @@ -0,0 +1,57 @@ + + + + Farbtastic + + + + + + + + +

jQuery Color Picker: Farbtastic

+ +
jQuery.js is not present. You must install jQuery in this folder for the demo to work.
+ +
+
+
+
+
+ +
+ +

More info on Acko.net.

+

Created by Steven Wittens.

+ + diff --git a/branches/farbtastic-1/farbtastic.css b/branches/farbtastic-1/farbtastic.css new file mode 100644 index 0000000..07d953f --- /dev/null +++ b/branches/farbtastic-1/farbtastic.css @@ -0,0 +1,33 @@ +.farbtastic { + position: relative; +} +.farbtastic * { + position: absolute; + cursor: crosshair; +} +.farbtastic, .farbtastic .wheel { + width: 195px; + height: 195px; +} +.farbtastic .color, .farbtastic .overlay { + top: 47px; + left: 47px; + width: 101px; + height: 101px; +} +.farbtastic .wheel { + background: url(wheel.png) no-repeat; + width: 195px; + height: 195px; +} +.farbtastic .overlay { + background: url(mask.png) no-repeat; +} +.farbtastic .marker { + width: 17px; + height: 17px; + margin: -8px 0 0 -8px; + overflow: hidden; + background: url(marker.png) no-repeat; +} + diff --git a/branches/farbtastic-1/farbtastic.js b/branches/farbtastic-1/farbtastic.js new file mode 100644 index 0000000..9111d5b --- /dev/null +++ b/branches/farbtastic-1/farbtastic.js @@ -0,0 +1,276 @@ +// Farbtastic 1.3 +(function($) { + +$.fn.farbtastic = function (options) { + $.farbtastic(this, options); + return this; +}; + +$.farbtastic = function (callback) { + $.farbtastic(this, callback); + return this; +}; + +$.farbtastic = function (container, callback) { + var container = $(container).get(0); + return container.farbtastic || (container.farbtastic = new $._farbtastic(container, callback)); +}; + +$._farbtastic = function (container, callback) { + // Store farbtastic object + var fb = this; + + // Insert markup + $(container).html('
'); + var e = $('.farbtastic', container); + fb.wheel = $('.wheel', container).get(0); + // Dimensions + fb.radius = 84; + fb.square = 100; + fb.width = 194; + + // Fix background PNGs in IE6 + if (navigator.appVersion.match(/MSIE [0-6]\./)) { + $('*', e).each(function () { + if (this.currentStyle.backgroundImage != 'none') { + var image = this.currentStyle.backgroundImage; + image = this.currentStyle.backgroundImage.substring(5, image.length - 2); + $(this).css({ + 'backgroundImage': 'none', + 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" + }); + } + }); + } + + /** + * Link to the given element(s) or callback. + */ + fb.linkTo = function (callback) { + // Unbind previous nodes + if (typeof fb.callback == 'object') { + $(fb.callback).unbind('keyup', fb.updateValue); + } + + // Reset color + fb.color = null; + + // Bind callback or elements + if (typeof callback == 'function') { + fb.callback = callback; + } + else if (typeof callback == 'object' || typeof callback == 'string') { + fb.callback = $(callback); + fb.callback.bind('keyup', fb.updateValue); + if (fb.callback.get(0).value) { + fb.setColor(fb.callback.get(0).value); + } + } + return this; + }; + fb.updateValue = function (event) { + if (this.value && this.value != fb.color) { + fb.setColor(this.value); + } + }; + + /** + * Change color with HTML syntax #123456 + */ + fb.setColor = function (color) { + var unpack = fb.unpack(color); + if (fb.color != color && unpack) { + fb.color = color; + fb.rgb = unpack; + fb.hsl = fb.RGBToHSL(fb.rgb); + fb.updateDisplay(); + } + return this; + }; + + /** + * Change color with HSL triplet [0..1, 0..1, 0..1] + */ + fb.setHSL = function (hsl) { + fb.hsl = hsl; + fb.rgb = fb.HSLToRGB(hsl); + fb.color = fb.pack(fb.rgb); + fb.updateDisplay(); + return this; + }; + + ///////////////////////////////////////////////////// + + /** + * Retrieve the coordinates of the given event relative to the center + * of the widget. + */ + fb.widgetCoords = function (event) { + var offset = $(fb.wheel).offset(); + return { x: (event.pageX - offset.left) - fb.width / 2, y: (event.pageY - offset.top) - fb.width / 2 }; + }; + + /** + * Mousedown handler + */ + fb.mousedown = function (event) { + // Capture mouse + if (!document.dragging) { + $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup); + document.dragging = true; + } + + // Check which area is being dragged + var pos = fb.widgetCoords(event); + fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square; + + // Process + fb.mousemove(event); + return false; + }; + + /** + * Mousemove handler + */ + fb.mousemove = function (event) { + // Get coordinates relative to color picker center + var pos = fb.widgetCoords(event); + + // Set new HSL parameters + if (fb.circleDrag) { + var hue = Math.atan2(pos.x, -pos.y) / 6.28; + if (hue < 0) hue += 1; + fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]); + } + else { + var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5)); + var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5)); + fb.setHSL([fb.hsl[0], sat, lum]); + } + return false; + }; + + /** + * Mouseup handler + */ + fb.mouseup = function () { + // Uncapture mouse + $(document).unbind('mousemove', fb.mousemove); + $(document).unbind('mouseup', fb.mouseup); + document.dragging = false; + }; + + /** + * Update the markers and styles + */ + fb.updateDisplay = function () { + // Markers + var angle = fb.hsl[0] * 6.28; + $('.h-marker', e).css({ + left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px', + top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px' + }); + + $('.sl-marker', e).css({ + left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px', + top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px' + }); + + // Saturation/Luminance gradient + $('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5]))); + + // Linked elements or callback + if (typeof fb.callback == 'object') { + // Set background/foreground color + $(fb.callback).css({ + backgroundColor: fb.color, + color: fb.hsl[2] > 0.5 ? '#000' : '#fff' + }); + + // Change linked value + $(fb.callback).each(function() { + if (this.value && this.value != fb.color) { + this.value = fb.color; + } + }); + } + else if (typeof fb.callback == 'function') { + fb.callback.call(fb, fb.color); + } + }; + + /* Various color utility functions */ + fb.pack = function (rgb) { + var r = Math.round(rgb[0] * 255); + var g = Math.round(rgb[1] * 255); + var b = Math.round(rgb[2] * 255); + return '#' + (r < 16 ? '0' : '') + r.toString(16) + + (g < 16 ? '0' : '') + g.toString(16) + + (b < 16 ? '0' : '') + b.toString(16); + }; + + fb.unpack = function (color) { + if (color.length == 7) { + return [parseInt('0x' + color.substring(1, 3)) / 255, + parseInt('0x' + color.substring(3, 5)) / 255, + parseInt('0x' + color.substring(5, 7)) / 255]; + } + else if (color.length == 4) { + return [parseInt('0x' + color.substring(1, 2)) / 15, + parseInt('0x' + color.substring(2, 3)) / 15, + parseInt('0x' + color.substring(3, 4)) / 15]; + } + }; + + fb.HSLToRGB = function (hsl) { + var m1, m2, r, g, b; + var h = hsl[0], s = hsl[1], l = hsl[2]; + m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s; + m1 = l * 2 - m2; + return [this.hueToRGB(m1, m2, h+0.33333), + this.hueToRGB(m1, m2, h), + this.hueToRGB(m1, m2, h-0.33333)]; + }; + + fb.hueToRGB = function (m1, m2, h) { + h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h); + if (h * 6 < 1) return m1 + (m2 - m1) * h * 6; + if (h * 2 < 1) return m2; + if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6; + return m1; + }; + + fb.RGBToHSL = function (rgb) { + var min, max, delta, h, s, l; + var r = rgb[0], g = rgb[1], b = rgb[2]; + min = Math.min(r, Math.min(g, b)); + max = Math.max(r, Math.max(g, b)); + delta = max - min; + l = (min + max) / 2; + s = 0; + if (l > 0 && l < 1) { + s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l)); + } + h = 0; + if (delta > 0) { + if (max == r && max != g) h += (g - b) / delta; + if (max == g && max != b) h += (2 + (b - r) / delta); + if (max == b && max != r) h += (4 + (r - g) / delta); + h /= 6; + } + return [h, s, l]; + }; + + // Install mousedown handler (the others are set on the document on-demand) + $('*', e).mousedown(fb.mousedown); + + // Init color + fb.setColor('#000000'); + + // Set linked elements/callback + if (callback) { + fb.linkTo(callback); + } +}; + +})(jQuery); diff --git a/branches/farbtastic-1/marker.png b/branches/farbtastic-1/marker.png new file mode 100755 index 0000000000000000000000000000000000000000..3929bbb51dd950802bb9bf12a397d1ac1e140610 GIT binary patch literal 652 zcmV;70(1R|P)WdL?^ATcx`YISTNGB7YUATcvKGch_cGaxH4F)%P5@Y>T zK`Rsr}kV+VsK4r03&T_dN z37_`#A}MZSsZ=7H&Gr{5`4jIqW3d>C;2mRQVuQC)s?}<&*X!MgmKw!nwOZ}3XY?Yx z1ZKC}8S0jW4@NQJa5(yFMK4kTYB(HbPN(w+)?NbvF1{X#MEdVndQW6J-p7BJ3*__perLFn{87XL ziu@ni?KWkzS&BxZ!L_t(|+U;H2Qsg=eY^etR|BH|J2?_?=>XzhWIK@;^%f>gUTQ@tI z0Q`Mk?qh%Y{3&r#4*S0lYA-a`9pmlA`d)U0-b2PdfxGLy%k402=K1` zO42&VT(L&GlDj^3aQzI3W72MiWRd2z24Jhgv2#||?&@>Nwa0-(p8?<`XeY@%qSsvl z+F|9N!xN+D%jk0__^$#&)Mif=S7ZRQv64)x1!a}BWPb#6DBzBbOoN=)ipEEcS4g=+ zpsUxYjJLpmRz_h9ud`jES2jg<(eEaBO&0;I94z_H%J4X_Pq3o5F?~BiW5yHg0J)}+ zf{q0WN_MVU0oe{1Uzrpmgk``~fmaF2w9RB3n?5R0mg$q(Jem-?T7*o@o0;DhzoT)@ z6e*RX{FA`F!rUk2{PwRkS$vnGmIyt+`QK^VS5H~(SkblEi;T?}%1N2Gq%cPf3{h8u z81*%x*sw&TI7Zfrl;>lI5hz$COG&y$&hd4_7F~YB2790h>7tw|*&@=AqBBZ?BM7+G}o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RM%!Sd&e6^!P;fZ4T?Y*D5Ltth`?SO|WSjpuuzGK=ZmGH&a5WrCcj`AL_Y^{B|NzV zapopB+1e%wLtVMvD7u-BWFCqmQM?O@%;iI5^(kal7?SGqq+mxYAi4$2bx`>|;_!8w zvM7`=)R((Vz)EIO;op!PTpL_e$vg#3o;s-;Z25hrdyD}6B7}E>xe?ah0rS?5bYGx^ zpZqu3w8`;p8+F%5;tJYc9PFnEto?ttjeU~Y%*+hEmWFu!{!<|Qg&7)j>T z6t<mVD@%R%1{(Y;{qf#_k_v$JgdOBkA|IRr~-Wfikf z>_ouMNOnXrv!+4DWCBEL4-L?JECT&9M9+bK3c4Qy^C*Om!i_6OYCk{;!^Uc2En_M$ zomRF6rl6RNVltA+1dKv528BY$kEM+N6S;|tD!6^S9A?5w!>}mzV00000NkvXXu0mjf+GChC literal 0 HcmV?d00001 diff --git a/trunk/demo/test.html b/trunk/demo/test.html new file mode 100644 index 0000000..7643de8 --- /dev/null +++ b/trunk/demo/test.html @@ -0,0 +1,53 @@ + + + + + + + + Farbtastic v2 + + + + + + + +

Farbtastic 2.0 alpha

+

Canvas/JS. No external CSS, no images.

+ +
+
+
+
+ +
+
+
+
+ +

› Acko.net

+ + + diff --git a/trunk/src/farbtastic-2.0.js b/trunk/src/farbtastic-2.0.js new file mode 100644 index 0000000..335aa74 --- /dev/null +++ b/trunk/src/farbtastic-2.0.js @@ -0,0 +1,509 @@ +// Farbtastic 2.0 alpha +(function ($) { + +var __debug = true; + +$.fn.farbtastic = function (options) { + $.farbtastic(this, options); + return this; +}; + +$.farbtastic = function (container, options) { + var container = $(container)[0]; + return container.farbtastic || (container.farbtastic = new $._farbtastic(container, options)); +} + +$._farbtastic = function (container, options) { + var fb = this; + + ///////////////////////////////////////////////////// + + /** + * Link to the given element(s) or callback. + */ + fb.linkTo = function (callback) { + // Unbind previous nodes + if (typeof fb.callback == 'object') { + $(fb.callback).unbind('keyup', fb.updateValue); + } + + // Reset color + fb.color = null; + + // Bind callback or elements + if (typeof callback == 'function') { + fb.callback = callback; + } + else if (typeof callback == 'object' || typeof callback == 'string') { + fb.callback = $(callback); + fb.callback.bind('keyup', fb.updateValue); + if (fb.callback[0].value) { + fb.setColor(fb.callback[0].value); + } + } + return this; + } + fb.updateValue = function (event) { + if (this.value && this.value != fb.color) { + fb.setColor(this.value); + } + } + + /** + * Change color with HTML syntax #123456 + */ + fb.setColor = function (color) { + var unpack = fb.unpack(color); + if (fb.color != color && unpack) { + fb.color = color; + fb.rgb = unpack; + fb.hsl = fb.RGBToHSL(fb.rgb); + fb.updateDisplay(); + } + return this; + } + + /** + * Change color with HSL triplet [0..1, 0..1, 0..1] + */ + fb.setHSL = function (hsl) { + fb.hsl = hsl; + fb.rgb = fb.HSLToRGB(hsl); + fb.color = fb.pack(fb.rgb); + fb.updateDisplay(); + return this; + } + + ///////////////////////////////////////////////////// + + /** + * Initialize the color picker widget. + */ + fb.initWidget = function () { + + // Insert markup and size accordingly. + var dim = { + width: options.width, + height: options.width + }; + $(container) + .html( + '
' + + '
' + + '' + + '' + + '
' + ) + .find('*').attr(dim).css(dim).end() + .find('div>*').css('position', 'absolute'); + + // IE Fix: Recreate canvas elements with doc.createElement and excanvas. + $.browser.msie && $('canvas', container).each(function () { + // Fetch info. + var attr = { 'class': $(this).attr('class'), style: this.getAttribute('style') }, + e = document.createElement('canvas'); + // Replace element. + $(this).before($(e).attr(attr)).remove(); + // Init with explorerCanvas. + G_vmlCanvasManager && G_vmlCanvasManager.initElement(e); + }); + + // Determine layout + fb.radius = (options.width - options.wheelWidth) / 2 - 1; + fb.square = Math.floor((fb.radius - options.wheelWidth / 2) * 0.7) - 1; + fb.mid = Math.floor(options.width / 2); + fb.markerSize = options.wheelWidth * 0.3; + fb.solidFill = $('.farbtastic-solid', container).css({ + width: fb.square * 2 - 1, + height: fb.square * 2 - 1, + left: fb.mid - fb.square, + top: fb.mid - fb.square + }); + + // Set up drawing context. + fb.cnvMask = $('.farbtastic-mask', container); + fb.ctxMask = fb.cnvMask[0].getContext('2d'); + fb.cnvOverlay = $('.farbtastic-overlay', container); + fb.ctxOverlay = fb.cnvOverlay[0].getContext('2d'); + fb.ctxMask.translate(fb.mid, fb.mid); + fb.ctxOverlay.translate(fb.mid, fb.mid); + + // Draw widget base layers. + fb.drawCircle(); + fb.drawMask(); + } + + /** + * Draw the color wheel. + */ + fb.drawCircle = function () { + var tm = +(new Date()); + // Draw a hue circle with a bunch of gradient-stroked beziers. + // Have to use beziers, as gradient-stroked arcs don't work. + var n = 24, + r = fb.radius, + w = options.wheelWidth, + nudge = 8 / r / n * Math.PI, // Fudge factor for seams. + m = fb.ctxMask, + angle1 = 0, color1, d1; + m.save(); + m.lineWidth = w / r; + m.scale(r, r); + // Each segment goes from angle1 to angle2. + for (var i = 0; i <= n; ++i) { + var d2 = i / n, + angle2 = d2 * Math.PI * 2, + // Endpoints + x1 = Math.sin(angle1), y1 = -Math.cos(angle1); + x2 = Math.sin(angle2), y2 = -Math.cos(angle2), + // Midpoint + am = (angle1 + angle2) / 2, + tan = 1 / Math.cos((angle2 - angle1) / 2), + xm = Math.sin(am) * tan, ym = -Math.cos(am) * tan, + // New color + color2 = fb.pack(fb.HSLToRGB([d2, 1, 0.5])); + if (i > 0) { + if ($.browser.msie) { + // IE's gradient calculations mess up the colors. Correct more along the diagonals. + var corr = (1 + Math.min(Math.abs(Math.tan(angle1)), Math.abs(Math.tan(Math.PI / 2 - angle1)))) / n; + color1 = fb.pack(fb.HSLToRGB([d1 - 0.15 * corr, 1, 0.5])); + color2 = fb.pack(fb.HSLToRGB([d2 + 0.15 * corr, 1, 0.5])); + // Create gradient fill between the endpoints. + var grad = m.createLinearGradient(x1, y1, x2, y2); + grad.addColorStop(0, color1); + grad.addColorStop(1, color2); + m.fillStyle = grad; + // Draw quadratic curve segment as a fill. + var r1 = (r + w / 2) / r, r2 = (r - w / 2) / r; + m.beginPath(); + m.moveTo(x1 * r1, y1 * r1); + m.quadraticCurveTo(xm * r1, ym * r1, x2 * r1, y2 * r1); + m.lineTo(x2 * r2, y2 * r2); + m.quadraticCurveTo(xm * r2, ym * r2, x1 * r2, y1 * r2); + m.fill(); + } + else { + // Create gradient fill between the endpoints. + var grad = m.createLinearGradient(x1, y1, x2, y2); + grad.addColorStop(0, color1); + grad.addColorStop(1, color2); + m.strokeStyle = grad; + // Draw quadratic curve segment. + m.beginPath(); + m.moveTo(x1, y1); + m.quadraticCurveTo(xm, ym, x2, y2); + m.stroke(); + } + } + // Prevent seams where curves join. + angle1 = angle2 - nudge; color1 = color2; d1 = d2; + } + m.restore(); + __debug && $('body').append('
drawCircle '+ (+(new Date()) - tm) +'ms'); + }; + + /** + * Draw the saturation/luminance mask. + */ + fb.drawMask = function () { + var tm = +(new Date()); + + // Iterate over sat/lum space and calculate appropriate mask pixel values. + var size = fb.square * 2, sq = fb.square; + function calculateMask(sizex, sizey, outputPixel) { + var isx = 1 / sizex, isy = 1 / sizey; + for (var y = 0; y <= sizey; ++y) { + var l = 1 - y * isy; + for (var x = 0; x <= sizex; ++x) { + var s = 1 - x * isx; + // From sat/lum to alpha and color (grayscale) + var a = 1 - 2 * Math.min(l * s, (1 - l) * s); + var c = (a > 0) ? ((2 * l - 1 + a) * .5 / a) : 0; + outputPixel(x, y, c, a); + } + } + } + + // Method #1: direct pixel access (new Canvas). + if (fb.ctxMask.getImageData) { + var sz = Math.floor(size / 2); + var buffer = document.createElement('canvas'); + buffer.width = buffer.height = sz + 1; + var ctx = buffer.getContext('2d'); + var frame = ctx.getImageData(0, 0, sz + 1, sz + 1); + + var i = 0; + calculateMask(sz, sz, function (x, y, c, a) { + frame.data[i++] = frame.data[i++] = frame.data[i++] = c * 255; + frame.data[i++] = a * 255; + }); + + ctx.putImageData(frame, 0, 0); + fb.ctxMask.drawImage(buffer, 0, 0, sz + 1, sz + 1, -sq, -sq, sq * 2, sq * 2); + } + // Method #2: drawing commands (old Canvas). + else if (!$.browser.msie) { + var sz = Math.floor(size / 2); + calculateMask(sz, sz, function (x, y, c, a) { + c = Math.round(c * 255); + fb.ctxMask.fillStyle = 'rgba(' + c + ', ' + c + ', ' + c + ', ' + a +')'; + fb.ctxMask.fillRect(x * 2 - sq - 1, y * 2 - sq - 1, 2, 2); + }); + } + // Method #3: vertical DXImageTransform gradient strips (IE). + else { + var cache_last, cache, w = 6; // Each strip is 6 pixels wide. + var sizex = Math.floor(size / w); + // 6 vertical pieces of gradient per strip. + calculateMask(sizex, 6, function (x, y, c, a) { + if (x == 0) { + cache_last = cache; + cache = []; + } + c = Math.round(c * 255); + a = Math.round(a * 255); + // We can only start outputting gradients once we have two rows of pixels. + if (y > 0) { + var c_last = cache_last[x][0], + a_last = cache_last[x][1], + color1 = fb.packDX(c_last, a_last), + color2 = fb.packDX(c, a), + y1 = Math.round(fb.mid + ((y - 1) * .333 - 1) * sq), + y2 = Math.round(fb.mid + (y * .333 - 1) * sq); + $('
').css({ + position: 'absolute', + filter: "progid:DXImageTransform.Microsoft.Gradient(StartColorStr="+ color1 +", EndColorStr="+ color2 +", GradientType=0)", + top: y1, + height: y2 - y1, + // Avoid right-edge sticking out. + left: fb.mid + (x * w - sq - 1), + width: w - (x == sizex ? Math.round(w / 2) : 0) + }).appendTo(fb.cnvMask); + } + cache.push([c, a]); + }); + } + __debug && $('body').append('
drawMask '+ (+(new Date()) - tm) +'ms'); + } + + /** + * Draw the selection markers. + */ + fb.drawMarkers = function () { + var sz = options.width, lw = Math.ceil(fb.markerSize / 4), r = fb.markerSize - lw; + fb.ctxOverlay.clearRect(-fb.mid, -fb.mid, sz, sz); + fb.ctxOverlay.lineWidth = lw; + + var angle = fb.hsl[0] * 6.28, + x1 = Math.sin(angle) * fb.radius, + y1 = -Math.cos(angle) * fb.radius, + x2 = 2 * fb.square * (.5 - fb.hsl[1]), + y2 = 2 * fb.square * (.5 - fb.hsl[2]), + c1 = fb.invert ? '#fff' : '#000', + c2 = fb.invert ? '#000' : '#fff'; + var circles = [ + { x: x1, y: y1, r: fb.markerSize, c: '#fff' }, + { x: x1, y: y1, r: r, c: '#000' }, + { x: x2, y: y2, r: fb.markerSize, c: c1 }, + { x: x2, y: y2, r: r, c: c2 }, + ]; + for (i in circles) { + var c = circles[i]; + fb.ctxOverlay.strokeStyle = c.c; + fb.ctxOverlay.beginPath(); + fb.ctxOverlay.arc(c.x, c.y, c.r, 0, Math.PI * 2, true); + fb.ctxOverlay.stroke(); + } + } + + /** + * Update the markers and styles + */ + fb.updateDisplay = function () { + // Determine whether labels/markers should invert. + fb.invert = (fb.rgb[0] * 0.3 + fb.rgb[1] * .59 + fb.rgb[2] * .11) <= 0.6; + + // Update the solid background fill. + fb.solidFill.css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5]))); + + // Draw markers + fb.drawMarkers(); + + // Linked elements or callback + if (typeof fb.callback == 'object') { + // Set background/foreground color + $(fb.callback).css({ + backgroundColor: fb.color, + color: fb.invert ? '#fff' : '#000' + }); + + // Change linked value + $(fb.callback).each(function() { + if ((typeof this.value == 'string') && this.value != fb.color) { + this.value = fb.color; + } + }); + } + else if (typeof fb.callback == 'function') { + fb.callback.call(fb, fb.color); + } + } + + /** + * Helper for returning coordinates relative to the center. + */ + fb.widgetCoords = function (event) { + return { + x: event.pageX - fb.offset.left - fb.mid, + y: event.pageY - fb.offset.top - fb.mid + }; + } + + /** + * Mousedown handler + */ + fb.mousedown = function (event) { + // Capture mouse + if (!$._farbtastic.dragging) { + $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup); + $._farbtastic.dragging = true; + } + + // Update the stored offset for the widget. + fb.offset = $(container).offset(); + + // Check which area is being dragged + var pos = fb.widgetCoords(event); + fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) > (fb.square + 2); + + // Process + fb.mousemove(event); + return false; + } + + /** + * Mousemove handler + */ + fb.mousemove = function (event) { + // Get coordinates relative to color picker center + var pos = fb.widgetCoords(event); + + // Set new HSL parameters + if (fb.circleDrag) { + var hue = Math.atan2(pos.x, -pos.y) / 6.28; + fb.setHSL([(hue + 1) % 1, fb.hsl[1], fb.hsl[2]]); + } + else { + var sat = Math.max(0, Math.min(1, -(pos.x / fb.square / 2) + .5)); + var lum = Math.max(0, Math.min(1, -(pos.y / fb.square / 2) + .5)); + fb.setHSL([fb.hsl[0], sat, lum]); + } + return false; + } + + /** + * Mouseup handler + */ + fb.mouseup = function () { + // Uncapture mouse + $(document).unbind('mousemove', fb.mousemove); + $(document).unbind('mouseup', fb.mouseup); + $._farbtastic.dragging = false; + } + + /* Various color utility functions */ + fb.dec2hex = function (x) { + return (x < 16 ? '0' : '') + x.toString(16); + } + + fb.packDX = function (c, a) { + return '#' + fb.dec2hex(a) + fb.dec2hex(c) + fb.dec2hex(c) + fb.dec2hex(c); + }; + + fb.pack = function (rgb) { + var r = Math.round(rgb[0] * 255); + var g = Math.round(rgb[1] * 255); + var b = Math.round(rgb[2] * 255); + return '#' + fb.dec2hex(r) + fb.dec2hex(g) + fb.dec2hex(b); + }; + + fb.unpack = function (color) { + if (color.length == 7) { + function x(i) { + return parseInt(color.substring(i, i + 2), 16) / 255; + } + return [ x(1), x(3), x(5) ]; + } + else if (color.length == 4) { + function x(i) { + return parseInt(color.substring(i, i + 1), 16) / 15; + } + return [ x(1), x(2), x(3) ]; + } + }; + + fb.HSLToRGB = function (hsl) { + var m1, m2, r, g, b; + var h = hsl[0], s = hsl[1], l = hsl[2]; + m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s; + m1 = l * 2 - m2; + return [ + this.hueToRGB(m1, m2, h + 0.33333), + this.hueToRGB(m1, m2, h), + this.hueToRGB(m1, m2, h - 0.33333) + ]; + }; + + fb.hueToRGB = function (m1, m2, h) { + h = (h + 1) % 1; + if (h * 6 < 1) return m1 + (m2 - m1) * h * 6; + if (h * 2 < 1) return m2; + if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6; + return m1; + }; + + fb.RGBToHSL = function (rgb) { + var r = rgb[0], g = rgb[1], b = rgb[2], + min = Math.min(r, g, b), + max = Math.max(r, g, b), + delta = max - min, + h = 0, + s = 0, + l = (min + max) / 2; + if (l > 0 && l < 1) { + s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l)); + } + if (delta > 0) { + if (max == r && max != g) h += (g - b) / delta; + if (max == g && max != b) h += (2 + (b - r) / delta); + if (max == b && max != r) h += (4 + (r - g) / delta); + h /= 6; + } + return [h, s, l]; + }; + + // Parse options. + if (!options.callback) { + options = { callback: options }; + } + options = $.extend({ + width: 300, + wheelWidth: (options.width || 300) / 10, + callback: null + }, options); + + // Initialize. + fb.initWidget(); + + // Install mousedown handler (the others are set on the document on-demand) + $('canvas.farbtastic-overlay', container).mousedown(fb.mousedown); + + // Set linked elements/callback + if (options.callback) { + fb.linkTo(options.callback); + } + // Set to gray. + fb.setColor('#808080'); +} + +})(jQuery);