PickyColor is a Ruby on Rails plugin for the JS color picker based on Prototype/Scriptaculous named... picky_color! (here is his GitHub page)
./script/plugin install git://github.com/sunito/picky-color.git
First of all you have to include the picky_color.css
and picky_color.js
to your layout :
<%= javascript_include_tag 'picky_color' %>
<%= stylesheet_link_tag 'picky_color' %>
Warning: This color-picker uses the prototype and scriptaculous librairies, therefore the corresponding js files have to be included to, if it's not the case, you just have to add the following line before the picky_color
javascript ::
<%= javascript_include_tag :defaults %>
For the case 2 and 3 of this example I will act as if I have to put a color picker for the field color of my model post
This plugin offer 3 way to use the helper :
-
Using it like a tag from FormTagHelper.
<%= picky_color_tag "my_color", "000000" %>
-
Using it as a FormHelper
<%= picky_color :post, :color %>
-
Using it in the Formbuilder
<% form_for(@post) do |f| %> <%= f.picky_color :color %> <% end %>
It is of course possible to add any html option in addition to these parameters as a Hash as last parameter of the methods. They will be applied on the input text field :
<%= picky_color :post, :color, :class => "my_sexy_class" %>
In addition to the html options, you have at your disposal 3 custom parameters : draggable, close_text and default
-
:close_text
takes a string and is the text of the confirm button of the color picker, default is "OK" -
:draggable
takes a boolean and set if the color picker is draggable or not, default is false -
:default
takes a string and is the default color shown by the color picker, default is "000000"
example :
<%= picky_color :post, :color, :draggable => true, :close_text => "ColorMe!", :default => "0fe" %>
Author of the plugin : Morgan Hotonnier Original author of the picker : Brandon Arbini/Sevenwire
Thanks to wildgoose, the author of the rails calendar_date_select plugin, whose code helped me a lot to figure out how to integrate my helper in the built-in formbuilder
A special thanks to Gabriel Laskar, who helped me a lot for this plugin, which is my first one. "Merci papi Gabi!"
It's my first plugin therefore I'm sure my code is a mess and deserve a lot of improvements, all suggestions are really welcome!
Copyright (c) 2008 Morgan Hotonnier [email protected], released under the MIT license