farbtastic-rails 1.3.0

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 farbtastic-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Phil Cohen
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,72 @@
1
+ # farbtastic-rails
2
+
3
+ [Farbtastic](http://acko.net/blog/farbtastic-jquery-color-picker-plug-in/) v[1.3u](https://github.com/mattfarina/farbtastic/tree/farbtastic-1), colorfully bundled for Rails 3+.
4
+
5
+ ## Rails 3.1+
6
+
7
+ For Rails 3.1 and greater, the files will be added to the asset pipeline and available for you to use.
8
+
9
+ To enable:
10
+
11
+ * Add the following line to the file `app/assets/javascripts/application.js` (or other [sprockets](https://github.com/sstephenson/sprockets) manifest):
12
+
13
+ ```javascript
14
+ //= require farbtastic
15
+ ```
16
+
17
+ * Add the following line to the file `app/assets/stylesheets/application.css` (or other [sprockets](https://github.com/sstephenson/sprockets) manifest):
18
+
19
+ ```css
20
+ *= require farbtastic
21
+ ```
22
+
23
+ ### Installation
24
+
25
+ * Add `farbtastic-rails` to your Gemfile
26
+ * Run `bundle`
27
+
28
+ Enjoy!
29
+
30
+
31
+ ## Rails 3.0
32
+
33
+ This gem adds a single generator to Rails 3, `farbtastic:install`. Running the generator will install the JS, CSS and image files necessary to use Farbtastic.
34
+
35
+ ### Installation
36
+
37
+ * Add `farbtastic-rails` to your Gemfile
38
+ * Run `bundle`
39
+ * Invoke the generator: `rails generate farbtastic:install`
40
+ * Add the following to your layout or view files:
41
+
42
+ ```erb
43
+ <%= stylesheet_link_tag "farbtastic" %>
44
+ <%= javascript_include_tag "farbtastic" %>
45
+ ```
46
+
47
+ You're done!
48
+
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
57
+
58
+
59
+ ## License
60
+
61
+ **farbtastic-rails**
62
+
63
+ * Freely distributable and licensed under the [MIT license](http://phlipper.mit-license.org/license.html).
64
+ * Copyright (c) 2012 Phil Cohen (github@phlippers.net) [![endorse](http://api.coderwall.com/phlipper/endorsecount.png)](http://coderwall.com/phlipper)
65
+ * http://phlippers.net/
66
+
67
+
68
+ **Farbtastic**
69
+
70
+ * Freely distributable and licensed under the [GPL v2](https://github.com/mattfarina/farbtastic/blob/farbtastic-1/LICENSE.txt) license.
71
+ * Copyright (c) 2007-2010 [Steven Wittens](http://acko.net/)
72
+ * http://acko.net/blog/farbtastic-jquery-color-picker-plug-in/
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/farbtastic-rails/version", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Phil Cohen"]
6
+ gem.email = ["github@phlippers.net"]
7
+ gem.description = %q{Farbtastic jQuery Color Picker, colorfully bundled for Rails 3+.}
8
+ gem.summary = %q{Farbtastic jQuery Color Picker, colorfully bundled for Rails 3+.}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "farbtastic-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Farbtastic::Rails::VERSION
17
+ end
@@ -0,0 +1,8 @@
1
+ require "farbtastic-rails/engine"
2
+ require "farbtastic-rails/version"
3
+
4
+ module Farbtastic
5
+ module Rails
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Farbtastic
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Farbtastic
2
+ module Rails
3
+ VERSION = "1.3.0"
4
+ FARBTASTIC_VERSION = "1.3u"
5
+ end
6
+ end
@@ -0,0 +1,50 @@
1
+ require "rails"
2
+
3
+ # Supply generator for Rails 3.0.x or if asset pipeline is not enabled
4
+ if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
5
+ module Farbtastic
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+
9
+ desc "This generator installs Farbtastic #{Farbtastic::Rails::FARBTASTIC_VERSION}"
10
+ source_root File.expand_path("../../../../../vendor/assets", __FILE__)
11
+
12
+ def copy_javascript
13
+ say_status("copying", "Farbtastic JS", :green)
14
+ copy_file "javascripts/farbtastic.js", "public/javascripts/farbtastic.js"
15
+ end
16
+
17
+ def copy_stylesheet
18
+ say_status("copying", "Farbtastic CSS", :green)
19
+ copy_file "stylesheets/farbtastic.css.scss", "public/stylesheets/farbtastic.css"
20
+
21
+ say_status("updating", "CSS Image Paths", :green)
22
+ gsub_file "public/stylesheets/farbtastic.css", "image-url(\"farbtastic/", "url(\"/images/farbtastic/"
23
+ end
24
+
25
+ def copy_images
26
+ say_status("copying", "Farbtastic Images", :green)
27
+ directory "images/farbtastic", "public/images/farbtastic"
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ else
34
+ module Farbtastic
35
+ module Generators
36
+ class InstallGenerator < ::Rails::Generators::Base
37
+ desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
38
+
39
+ def do_nothing
40
+ say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
41
+ say_status("", "The necessary files are already in your asset pipeline.")
42
+ say_status("", "Just add `//= require farbtastic` to your app/assets/javascripts/application.js and add `*= require farbtastic` to your app/assets/stylesheets/application.css")
43
+ say_status("", "If you upgraded your app from Rails 3.0 and still have farbtastic.js, farbtastic.css or images/farbtastic in your public assets folders, be sure to remove them.")
44
+ say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
45
+ # ok, nothing
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,276 @@
1
+ /*!
2
+ * Farbtastic: jQuery color picker plug-in v1.3u
3
+ *
4
+ * Licensed under the GPL license:
5
+ * http://www.gnu.org/licenses/gpl.html
6
+ */
7
+ (function($) {
8
+
9
+ $.fn.farbtastic = function (options) {
10
+ $.farbtastic(this, options);
11
+ return this;
12
+ };
13
+
14
+ $.farbtastic = function (container, callback) {
15
+ var container = $(container).get(0);
16
+ return container.farbtastic || (container.farbtastic = new $._farbtastic(container, callback));
17
+ };
18
+
19
+ $._farbtastic = function (container, callback) {
20
+ // Store farbtastic object
21
+ var fb = this;
22
+
23
+ // Insert markup
24
+ $(container).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');
25
+ var e = $('.farbtastic', container);
26
+ fb.wheel = $('.wheel', container).get(0);
27
+ // Dimensions
28
+ fb.radius = 84;
29
+ fb.square = 100;
30
+ fb.width = 194;
31
+
32
+ // Fix background PNGs in IE6
33
+ if (navigator.appVersion.match(/MSIE [0-6]\./)) {
34
+ $('*', e).each(function () {
35
+ if (this.currentStyle.backgroundImage != 'none') {
36
+ var image = this.currentStyle.backgroundImage;
37
+ image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
38
+ $(this).css({
39
+ 'backgroundImage': 'none',
40
+ 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
41
+ });
42
+ }
43
+ });
44
+ }
45
+
46
+ /**
47
+ * Link to the given element(s) or callback.
48
+ */
49
+ fb.linkTo = function (callback) {
50
+ // Unbind previous nodes
51
+ if (typeof fb.callback == 'object') {
52
+ $(fb.callback).unbind('keyup', fb.updateValue);
53
+ }
54
+
55
+ // Reset color
56
+ fb.color = null;
57
+
58
+ // Bind callback or elements
59
+ if (typeof callback == 'function') {
60
+ fb.callback = callback;
61
+ }
62
+ else if (typeof callback == 'object' || typeof callback == 'string') {
63
+ fb.callback = $(callback);
64
+ fb.callback.bind('keyup', fb.updateValue);
65
+ if (fb.callback.get(0).value) {
66
+ fb.setColor(fb.callback.get(0).value);
67
+ }
68
+ }
69
+ return this;
70
+ };
71
+ fb.updateValue = function (event) {
72
+ if (this.value && this.value != fb.color) {
73
+ fb.setColor(this.value);
74
+ }
75
+ };
76
+
77
+ /**
78
+ * Change color with HTML syntax #123456
79
+ */
80
+ fb.setColor = function (color) {
81
+ var unpack = fb.unpack(color);
82
+ if (fb.color != color && unpack) {
83
+ fb.color = color;
84
+ fb.rgb = unpack;
85
+ fb.hsl = fb.RGBToHSL(fb.rgb);
86
+ fb.updateDisplay();
87
+ }
88
+ return this;
89
+ };
90
+
91
+ /**
92
+ * Change color with HSL triplet [0..1, 0..1, 0..1]
93
+ */
94
+ fb.setHSL = function (hsl) {
95
+ fb.hsl = hsl;
96
+ fb.rgb = fb.HSLToRGB(hsl);
97
+ fb.color = fb.pack(fb.rgb);
98
+ fb.updateDisplay();
99
+ return this;
100
+ };
101
+
102
+ /////////////////////////////////////////////////////
103
+
104
+ /**
105
+ * Retrieve the coordinates of the given event relative to the center
106
+ * of the widget.
107
+ */
108
+ fb.widgetCoords = function (event) {
109
+ var offset = $(fb.wheel).offset();
110
+ return { x: (event.pageX - offset.left) - fb.width / 2, y: (event.pageY - offset.top) - fb.width / 2 };
111
+ };
112
+
113
+ /**
114
+ * Mousedown handler
115
+ */
116
+ fb.mousedown = function (event) {
117
+ // Capture mouse
118
+ if (!document.dragging) {
119
+ $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup);
120
+ document.dragging = true;
121
+ }
122
+
123
+ // Check which area is being dragged
124
+ var pos = fb.widgetCoords(event);
125
+ fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square;
126
+
127
+ // Process
128
+ fb.mousemove(event);
129
+ return false;
130
+ };
131
+
132
+ /**
133
+ * Mousemove handler
134
+ */
135
+ fb.mousemove = function (event) {
136
+ // Get coordinates relative to color picker center
137
+ var pos = fb.widgetCoords(event);
138
+
139
+ // Set new HSL parameters
140
+ if (fb.circleDrag) {
141
+ var hue = Math.atan2(pos.x, -pos.y) / 6.28;
142
+ if (hue < 0) hue += 1;
143
+ fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]);
144
+ }
145
+ else {
146
+ var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5));
147
+ var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5));
148
+ fb.setHSL([fb.hsl[0], sat, lum]);
149
+ }
150
+ return false;
151
+ };
152
+
153
+ /**
154
+ * Mouseup handler
155
+ */
156
+ fb.mouseup = function () {
157
+ // Uncapture mouse
158
+ $(document).unbind('mousemove', fb.mousemove);
159
+ $(document).unbind('mouseup', fb.mouseup);
160
+ document.dragging = false;
161
+ };
162
+
163
+ /**
164
+ * Update the markers and styles
165
+ */
166
+ fb.updateDisplay = function () {
167
+ // Markers
168
+ var angle = fb.hsl[0] * 6.28;
169
+ $('.h-marker', e).css({
170
+ left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px',
171
+ top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px'
172
+ });
173
+
174
+ $('.sl-marker', e).css({
175
+ left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px',
176
+ top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px'
177
+ });
178
+
179
+ // Saturation/Luminance gradient
180
+ $('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5])));
181
+
182
+ // Linked elements or callback
183
+ if (typeof fb.callback == 'object') {
184
+ // Set background/foreground color
185
+ $(fb.callback).css({
186
+ backgroundColor: fb.color,
187
+ color: fb.hsl[2] > 0.5 ? '#000' : '#fff'
188
+ });
189
+
190
+ // Change linked value
191
+ $(fb.callback).each(function() {
192
+ if (this.value && this.value != fb.color) {
193
+ this.value = fb.color;
194
+ }
195
+ });
196
+ }
197
+ else if (typeof fb.callback == 'function') {
198
+ fb.callback.call(fb, fb.color);
199
+ }
200
+ };
201
+
202
+ /* Various color utility functions */
203
+ fb.pack = function (rgb) {
204
+ var r = Math.round(rgb[0] * 255);
205
+ var g = Math.round(rgb[1] * 255);
206
+ var b = Math.round(rgb[2] * 255);
207
+ return '#' + (r < 16 ? '0' : '') + r.toString(16) +
208
+ (g < 16 ? '0' : '') + g.toString(16) +
209
+ (b < 16 ? '0' : '') + b.toString(16);
210
+ };
211
+
212
+ fb.unpack = function (color) {
213
+ if (color.length == 7) {
214
+ return [parseInt('0x' + color.substring(1, 3)) / 255,
215
+ parseInt('0x' + color.substring(3, 5)) / 255,
216
+ parseInt('0x' + color.substring(5, 7)) / 255];
217
+ }
218
+ else if (color.length == 4) {
219
+ return [parseInt('0x' + color.substring(1, 2)) / 15,
220
+ parseInt('0x' + color.substring(2, 3)) / 15,
221
+ parseInt('0x' + color.substring(3, 4)) / 15];
222
+ }
223
+ };
224
+
225
+ fb.HSLToRGB = function (hsl) {
226
+ var m1, m2, r, g, b;
227
+ var h = hsl[0], s = hsl[1], l = hsl[2];
228
+ m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s;
229
+ m1 = l * 2 - m2;
230
+ return [this.hueToRGB(m1, m2, h+0.33333),
231
+ this.hueToRGB(m1, m2, h),
232
+ this.hueToRGB(m1, m2, h-0.33333)];
233
+ };
234
+
235
+ fb.hueToRGB = function (m1, m2, h) {
236
+ h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
237
+ if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
238
+ if (h * 2 < 1) return m2;
239
+ if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
240
+ return m1;
241
+ };
242
+
243
+ fb.RGBToHSL = function (rgb) {
244
+ var min, max, delta, h, s, l;
245
+ var r = rgb[0], g = rgb[1], b = rgb[2];
246
+ min = Math.min(r, Math.min(g, b));
247
+ max = Math.max(r, Math.max(g, b));
248
+ delta = max - min;
249
+ l = (min + max) / 2;
250
+ s = 0;
251
+ if (l > 0 && l < 1) {
252
+ s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
253
+ }
254
+ h = 0;
255
+ if (delta > 0) {
256
+ if (max == r && max != g) h += (g - b) / delta;
257
+ if (max == g && max != b) h += (2 + (b - r) / delta);
258
+ if (max == b && max != r) h += (4 + (r - g) / delta);
259
+ h /= 6;
260
+ }
261
+ return [h, s, l];
262
+ };
263
+
264
+ // Install mousedown handler (the others are set on the document on-demand)
265
+ $('*', e).mousedown(fb.mousedown);
266
+
267
+ // Init color
268
+ fb.setColor('#000000');
269
+
270
+ // Set linked elements/callback
271
+ if (callback) {
272
+ fb.linkTo(callback);
273
+ }
274
+ };
275
+
276
+ })(jQuery);
@@ -0,0 +1,32 @@
1
+ .farbtastic {
2
+ position: relative;
3
+ }
4
+ .farbtastic * {
5
+ position: absolute;
6
+ cursor: crosshair;
7
+ }
8
+ .farbtastic, .farbtastic .wheel {
9
+ width: 195px;
10
+ height: 195px;
11
+ }
12
+ .farbtastic .color, .farbtastic .overlay {
13
+ top: 47px;
14
+ left: 47px;
15
+ width: 101px;
16
+ height: 101px;
17
+ }
18
+ .farbtastic .wheel {
19
+ background: image-url("farbtastic/wheel.png") no-repeat;
20
+ width: 195px;
21
+ height: 195px;
22
+ }
23
+ .farbtastic .overlay {
24
+ background: image-url("farbtastic/mask.png") no-repeat;
25
+ }
26
+ .farbtastic .marker {
27
+ width: 17px;
28
+ height: 17px;
29
+ margin: -8px 0 0 -8px;
30
+ overflow: hidden;
31
+ background: image-url("farbtastic/marker.png") no-repeat;
32
+ }
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: farbtastic-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Cohen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Farbtastic jQuery Color Picker, colorfully bundled for Rails 3+.
15
+ email:
16
+ - github@phlippers.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - farbtastic-rails.gemspec
27
+ - lib/farbtastic-rails.rb
28
+ - lib/farbtastic-rails/engine.rb
29
+ - lib/farbtastic-rails/version.rb
30
+ - lib/generators/farbtastic/install/install_generator.rb
31
+ - vendor/assets/images/farbtastic/marker.png
32
+ - vendor/assets/images/farbtastic/mask.png
33
+ - vendor/assets/images/farbtastic/wheel.png
34
+ - vendor/assets/javascripts/farbtastic.js
35
+ - vendor/assets/stylesheets/farbtastic.css.scss
36
+ homepage: ''
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ segments:
49
+ - 0
50
+ hash: 1518086036302291006
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ segments:
58
+ - 0
59
+ hash: 1518086036302291006
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.15
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Farbtastic jQuery Color Picker, colorfully bundled for Rails 3+.
66
+ test_files: []