Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Color Picker drop-down box helper

// description of your code here
This helper will generate a whole bunch o' colors in a drop down box, which which you can do whatever with. Currently I am allowing users to change certain colors of the page.
     def color_picker(name)
       #build the hexes
      hexes = []
       (0..15).step(3) do |one|
         (0..15).step(3) do |two|
           (0..15).step(3) do |three|
            hexes << "#" + one.to_s(16) + two.to_s(16) + three.to_s(16)
           end
         end
       end
       arr = []
       10.times { arr << "&nbsp;" }
         returning html = '' do
        html << "<select name=#{name}>"
        html << hexes.collect {|c|
          "<option value='#{c}' style='background-color: #{c}'>#{arr.join}</option>" }.join("\n")
        html << "</select>"
      end
     end

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS