jquery-simplecolorpicker-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery-simplecolorpicker-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tanguy Krotoff
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # jQuery simplecolorpicker for Rails
2
+
3
+ Simplecolorpicker packaged for the Rails 3.1+ asset pipeline.
4
+ Check [simplecolorpicker project home page](https://github.com/tkrotoff/jquery-simplecolorpicker).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'jquery-simplecolorpicker-rails'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install jquery-simplecolorpicker-rails
19
+
20
+ ## Usage
21
+
22
+ Add the following JavaScript file to `app/assets/javascripts/application.js`:
23
+
24
+ //= require jquery.simplecolorpicker.js
25
+
26
+ Add the following stylesheet file to `app/assets/stylesheets/application.css`:
27
+
28
+ *= require jquery.simplecolorpicker.css
29
+
30
+ If you use [simple_form](https://github.com/plataformatec/simple_form) then write this inside your form:
31
+
32
+ <%= f.input :color, collection: MY_COLORS, selected: my_default_color %>
33
+
34
+ With `MY_COLORS` being:
35
+
36
+ # Colors from Google Calendar
37
+ MY_COLORS = {
38
+ 'Green' => '#7bd148',
39
+ 'Bold blue' => '#5484ed',
40
+ 'Blue' => '#a4bdfc',
41
+ 'Turquoise' => '#46d6db',
42
+ 'Light green' => '#7ae7bf',
43
+ 'Bold green' => '#51b749',
44
+ 'Yellow' => '#fbd75b',
45
+ 'Orange' => '#ffb878',
46
+ 'Red' => '#ff887c',
47
+ 'Bold red' => '#dc2127',
48
+ 'Purple' => '#dbadff',
49
+ 'Gray' => '#e1e1e1',
50
+ }
51
+
52
+ And `my_default_color` being:
53
+
54
+ my_default_color = MY_COLORS['Yellow']
55
+
56
+ ## License
57
+
58
+ Simplecolorpicker is licensed under the MIT license, this gem too.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jquery-simplecolorpicker-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Tanguy Krotoff"]
6
+ gem.email = ["tkrotoff@gmail.com"]
7
+ gem.description = %q{simplecolorpicker jQuery plugin}
8
+ gem.summary = %q{simplecolorpicker packaged for the Rails 3.1+ asset pipeline}
9
+ gem.homepage = "http://github.com/tkrotoff/jquery-simplecolorpicker-rails"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "jquery-simplecolorpicker-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Jquery::Simplecolorpicker::Rails::VERSION
17
+
18
+ gem.add_dependency 'railties', '>= 3.1.0'
19
+ end
@@ -0,0 +1,10 @@
1
+ require "jquery-simplecolorpicker-rails/version"
2
+
3
+ module Jquery
4
+ module Simplecolorpicker
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Simplecolorpicker
3
+ module Rails
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Very simple jQuery Color Picker.
3
+ *
4
+ * Copyright (C) 2012 Tanguy Krotoff
5
+ *
6
+ * Licensed under the MIT license.
7
+ */
8
+
9
+ !function($) {
10
+
11
+ /**
12
+ * Constructor.
13
+ */
14
+ var SimpleColorPicker = function(element, options) {
15
+ this.select = $(element);
16
+ this.options = $.extend({}, $.fn.simplecolorpicker.defaults, options);
17
+
18
+ this.select.hide();
19
+
20
+ // Trick: fix span alignment
21
+ // When a span does not contain any text, its alignment is not correct
22
+ var fakeText = '&nbsp;&nbsp;&nbsp;&nbsp;';
23
+
24
+ // Build the list of colors
25
+ // <div class="selected" title="Green" style="background-color: #7bd148;" role="button"></div>
26
+ var colorList = '';
27
+ $('option', this.select).each(function() {
28
+ var option = $(this);
29
+ var color = option.val();
30
+ var title = option.text();
31
+ var selected = '';
32
+ if (option.attr('selected')) {
33
+ selected = 'class="selected"';
34
+ }
35
+ colorList += '<div ' + selected + ' title="' + title + '" style="background-color: ' + color + ';" role="button" tabindex="0">'
36
+ + fakeText +
37
+ '</div>';
38
+ });
39
+
40
+ if (this.options.picker) {
41
+ var selectText = this.select.find('option:selected').text();
42
+ var selectValue = this.select.val();
43
+ this.icon = $('<span class="simplecolorpicker icon" title="' + selectText + '" style="background-color: ' + selectValue + ';" role="button" tabindex="0">'
44
+ + fakeText +
45
+ '</span>').insertAfter(this.select);
46
+ this.icon.on('click', $.proxy(this.show, this));
47
+
48
+ this.picker = $('<span class="simplecolorpicker picker"></span>').appendTo(document.body);
49
+ this.picker.html(colorList);
50
+ this.picker.on('click', $.proxy(this.click, this));
51
+
52
+ // Hide picker when clicking outside
53
+ $(document).on('mousedown', $.proxy(this.hide, this));
54
+ this.picker.on('mousedown', $.proxy(this.mousedown, this));
55
+ } else {
56
+ this.inline = $('<span class="simplecolorpicker inline"></span>').insertAfter(this.select);
57
+ this.inline.html(colorList);
58
+ this.inline.on('click', $.proxy(this.click, this));
59
+ }
60
+ }
61
+
62
+ /**
63
+ * SimpleColorPicker class.
64
+ */
65
+ SimpleColorPicker.prototype = {
66
+ constructor: SimpleColorPicker,
67
+
68
+ show: function() {
69
+ var bootstrapArrowWidth = 16; // Empirical value
70
+ var pos = this.icon.offset();
71
+ this.picker.css({
72
+ left: pos.left + this.icon.width() / 2 - bootstrapArrowWidth, // Middle of the icon
73
+ top: pos.top + this.icon.outerHeight()
74
+ });
75
+
76
+ this.picker.show(this.options.delay);
77
+ },
78
+
79
+ hide: function() {
80
+ this.picker.hide(this.options.delay);
81
+ },
82
+
83
+ click: function(e) {
84
+ var target = $(e.target);
85
+ if (target.length == 1) {
86
+ switch (target[0].nodeName.toLowerCase()) {
87
+
88
+ // When you click on a color
89
+ case 'div':
90
+ var color = target.css('background-color');
91
+ var title = target.attr('title');
92
+
93
+ // Mark this div as the selected one
94
+ target.siblings().removeClass('selected');
95
+ target.addClass('selected');
96
+
97
+ if (this.options.picker) {
98
+ this.icon.css('background-color', color);
99
+ this.icon.attr('title', title);
100
+
101
+ // Hide the picker
102
+ this.hide();
103
+ }
104
+
105
+ // Change select value
106
+ this.select.val(this.rgb2hex(color)).change();
107
+
108
+ break;
109
+
110
+ }
111
+ }
112
+ },
113
+
114
+ /**
115
+ * Prevents the mousedown event from "eating" the click event.
116
+ */
117
+ mousedown: function(e) {
118
+ e.stopPropagation();
119
+ e.preventDefault();
120
+ },
121
+
122
+ /**
123
+ * Converts a RGB color to its hexadecimal value.
124
+ *
125
+ * See http://stackoverflow.com/questions/1740700/get-hex-value-rather-than-rgb-value-using-jquery
126
+ */
127
+ rgb2hex: function(rgb) {
128
+ rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
129
+ function hex(x) {
130
+ return ("0" + parseInt(x).toString(16)).slice(-2);
131
+ }
132
+ return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Plugin definition.
138
+ */
139
+ $.fn.simplecolorpicker = function(option) {
140
+ // For HTML element passed to the plugin
141
+ return this.each(function () {
142
+ var $this = $(this),
143
+ data = $this.data('simplecolorpicker'),
144
+ options = typeof option == 'object' && option;
145
+ if (!data) {
146
+ $this.data('simplecolorpicker', (data = new SimpleColorPicker(this, options)));
147
+ }
148
+ if (typeof option == 'string') data[option]();
149
+ });
150
+ }
151
+
152
+ $.fn.simplecolorpicker.Constructor = SimpleColorPicker;
153
+
154
+ /**
155
+ * Default options.
156
+ */
157
+ $.fn.simplecolorpicker.defaults = {
158
+ // Animation delay
159
+ delay: 0,
160
+
161
+ // Show the picker or make it inline
162
+ picker: false
163
+ };
164
+
165
+ }(window.jQuery);
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Very simple jQuery Color Picker CSS.
3
+ *
4
+ * Copyright (C) 2012 Tanguy Krotoff
5
+ *
6
+ * Licensed under the MIT license.
7
+ *
8
+ * Inspired by Bootstrap Twitter.
9
+ * See https://github.com/twitter/bootstrap/blob/master/less/dropdowns.less
10
+ * See http://twitter.github.com/bootstrap/assets/css/bootstrap.css
11
+ */
12
+
13
+ .simplecolorpicker:before {
14
+ position: absolute;
15
+ top: -7px;
16
+ left: 9px;
17
+ display: inline-block;
18
+ border-right: 7px solid transparent;
19
+ border-bottom: 7px solid #ccc;
20
+ border-left: 7px solid transparent;
21
+ border-bottom-color: rgba(0, 0, 0, 0.2);
22
+ content: '';
23
+ }
24
+
25
+ .simplecolorpicker:after {
26
+ position: absolute;
27
+ top: -6px;
28
+ left: 10px;
29
+ display: inline-block;
30
+ border-right: 6px solid transparent;
31
+ border-bottom: 6px solid #ffffff;
32
+ border-left: 6px solid transparent;
33
+ content: '';
34
+ }
35
+
36
+ .simplecolorpicker.picker {
37
+ position: absolute;
38
+ top: 100%;
39
+ left: 0;
40
+ z-index: 1000;
41
+ display: none;
42
+ float: left;
43
+
44
+ min-width: 160px;
45
+ max-width: 264px;
46
+
47
+ padding: 4px 0 0 4px;
48
+ margin: 1px 0 0;
49
+ list-style: none;
50
+ background-color: #ffffff;
51
+
52
+ border: 1px solid #ccc;
53
+ border: 1px solid rgba(0, 0, 0, 0.2);
54
+
55
+ *border-right-width: 2px;
56
+ *border-bottom-width: 2px;
57
+
58
+ -webkit-border-radius: 5px;
59
+ -moz-border-radius: 5px;
60
+ border-radius: 5px;
61
+
62
+ -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
63
+ -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
64
+ box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
65
+
66
+ -webkit-background-clip: padding-box;
67
+ -moz-background-clip: padding;
68
+ background-clip: padding-box;
69
+ }
70
+
71
+ .simplecolorpicker.inline {
72
+ display: inline-block;
73
+ height: 18px;
74
+ padding: 4px 0;
75
+ }
76
+
77
+ .simplecolorpicker.icon,
78
+ .simplecolorpicker div {
79
+ cursor: pointer;
80
+ display: inline-block;
81
+ margin: 0 4px 4px 0;
82
+
83
+ -webkit-border-radius: 3px;
84
+ -moz-border-radius: 3px;
85
+ border-radius: 3px;
86
+
87
+ border: 1px solid transparent;
88
+ }
89
+
90
+ .simplecolorpicker div:hover,
91
+ .simplecolorpicker div.selected {
92
+ border: 1px solid black;
93
+ }
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-simplecolorpicker-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tanguy Krotoff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &70305360074020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70305360074020
25
+ description: simplecolorpicker jQuery plugin
26
+ email:
27
+ - tkrotoff@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - jquery-simplecolorpicker-rails.gemspec
38
+ - lib/jquery-simplecolorpicker-rails.rb
39
+ - lib/jquery-simplecolorpicker-rails/version.rb
40
+ - vendor/assets/javascripts/jquery.simplecolorpicker.js
41
+ - vendor/assets/stylesheets/jquery.simplecolorpicker.css
42
+ homepage: http://github.com/tkrotoff/jquery-simplecolorpicker-rails
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.15
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: simplecolorpicker packaged for the Rails 3.1+ asset pipeline
66
+ test_files: []