eyecon-colorpicker-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +4 -0
  5. data/Rakefile +2 -0
  6. data/eyecon-colorpicker-rails.gemspec +19 -0
  7. data/lib/eyecon-colorpicker-rails.rb +13 -0
  8. data/lib/eyecon-colorpicker-rails/engine.rb +11 -0
  9. data/lib/eyecon-colorpicker-rails/railtie.rb +11 -0
  10. data/lib/eyecon-colorpicker-rails/version.rb +7 -0
  11. data/vendor/assets/images/eyecon/colorpicker/blank.gif +0 -0
  12. data/vendor/assets/images/eyecon/colorpicker/colorpicker_background.png +0 -0
  13. data/vendor/assets/images/eyecon/colorpicker/colorpicker_hex.png +0 -0
  14. data/vendor/assets/images/eyecon/colorpicker/colorpicker_hsb_b.png +0 -0
  15. data/vendor/assets/images/eyecon/colorpicker/colorpicker_hsb_h.png +0 -0
  16. data/vendor/assets/images/eyecon/colorpicker/colorpicker_hsb_s.png +0 -0
  17. data/vendor/assets/images/eyecon/colorpicker/colorpicker_indic.gif +0 -0
  18. data/vendor/assets/images/eyecon/colorpicker/colorpicker_overlay.png +0 -0
  19. data/vendor/assets/images/eyecon/colorpicker/colorpicker_rgb_b.png +0 -0
  20. data/vendor/assets/images/eyecon/colorpicker/colorpicker_rgb_g.png +0 -0
  21. data/vendor/assets/images/eyecon/colorpicker/colorpicker_rgb_r.png +0 -0
  22. data/vendor/assets/images/eyecon/colorpicker/colorpicker_select.gif +0 -0
  23. data/vendor/assets/images/eyecon/colorpicker/colorpicker_submit.png +0 -0
  24. data/vendor/assets/images/eyecon/colorpicker/custom_background.png +0 -0
  25. data/vendor/assets/images/eyecon/colorpicker/custom_hex.png +0 -0
  26. data/vendor/assets/images/eyecon/colorpicker/custom_hsb_b.png +0 -0
  27. data/vendor/assets/images/eyecon/colorpicker/custom_hsb_h.png +0 -0
  28. data/vendor/assets/images/eyecon/colorpicker/custom_hsb_s.png +0 -0
  29. data/vendor/assets/images/eyecon/colorpicker/custom_indic.gif +0 -0
  30. data/vendor/assets/images/eyecon/colorpicker/custom_rgb_b.png +0 -0
  31. data/vendor/assets/images/eyecon/colorpicker/custom_rgb_g.png +0 -0
  32. data/vendor/assets/images/eyecon/colorpicker/custom_rgb_r.png +0 -0
  33. data/vendor/assets/images/eyecon/colorpicker/custom_submit.png +0 -0
  34. data/vendor/assets/images/eyecon/colorpicker/select.png +0 -0
  35. data/vendor/assets/images/eyecon/colorpicker/select2.png +0 -0
  36. data/vendor/assets/images/eyecon/colorpicker/slider.png +0 -0
  37. data/vendor/assets/javascripts/eyecon/colorpicker.js +504 -0
  38. data/vendor/assets/stylesheets/eyecon/colorpicker.scss +163 -0
  39. metadata +130 -0
@@ -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 vendor/gems/colorpicker.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Andrew Vit
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.
@@ -0,0 +1,4 @@
1
+ # Eyecon ColorPicker for Rails
2
+
3
+ Integrate ColorPicker jQuery widget from eyecon.ro into the Rails Asset
4
+ Pipeline.
@@ -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/eyecon-colorpicker-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrew Vit"]
6
+ gem.email = ["andrew@avit.ca"]
7
+ gem.description = %q{jQuery colorpicker for Rails}
8
+ gem.summary = %q{Integrate colorpicker widget from eyecon.ro into the Rails Asset Pipeline.}
9
+ gem.homepage = "https://github.com/avit/eyecon-colorpicker-rails"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "eyecon-colorpicker-rails"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Eyecon::ColorPicker::Rails::VERSION
16
+
17
+ gem.add_dependency "jquery-rails"
18
+ gem.add_dependency "sass-rails"
19
+ end
@@ -0,0 +1,13 @@
1
+ require "eyecon-colorpicker-rails/version"
2
+
3
+ module Eyecon
4
+ module Colorpicker
5
+ module Rails
6
+ if ::Rails.version < "3.1"
7
+ require "eyecon-colorpicker-rails/railtie"
8
+ else
9
+ require "eyecon-colorpicker-rails/engine"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Eyecon
2
+ module ColorPicker
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ initializer "configure colorpicker assets", :group => :all do |app|
6
+ app.config.assets.precompile += %w(eyecon/colorpicker.js eyecon/colorpicker.css)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Eyecon
2
+ module ColorPicker
3
+ module Rails
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "configure colorpicker assets", :group => :all do |app|
6
+ app.config.assets.precompile += %w(eyecon/colorpicker.js eyecon/colorpicker.css)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Eyecon
2
+ module ColorPicker
3
+ module Rails
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,504 @@
1
+ /**
2
+ *
3
+ * Color picker
4
+ * Author: Stefan Petre www.eyecon.ro
5
+ * Modified by Nicholas Kircher (https://github.com/MiracleBlue/jQuery-colorpicker)
6
+ *
7
+ * Dual licensed under the MIT and GPL licenses
8
+ *
9
+ */
10
+ (function ($) {
11
+ var ColorPicker = function () {
12
+ var
13
+ debugging = false,
14
+ ids = {},
15
+ inAction,
16
+ charMin = 65,
17
+ visible,
18
+ tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
19
+ defaults = {
20
+ eventName: 'click',
21
+ onShow: function () {},
22
+ onBeforeShow: function(){},
23
+ onHide: function () {},
24
+ onChange: function () {},
25
+ onSubmit: function () {},
26
+ color: 'ff0000',
27
+ livePreview: true,
28
+ flat: false
29
+ },
30
+ debug = function (msg) {
31
+ if (debugging) {
32
+ console.log(msg);
33
+ }
34
+ },
35
+ fillRGBFields = function (hsb, cal) {
36
+ var rgb = HSBToRGB(hsb);
37
+ $(cal).data('colorpicker').fields
38
+ .eq(1).val(rgb.r).end()
39
+ .eq(2).val(rgb.g).end()
40
+ .eq(3).val(rgb.b).end();
41
+ },
42
+ fillHSBFields = function (hsb, cal) {
43
+ $(cal).data('colorpicker').fields
44
+ .eq(4).val(hsb.h).end()
45
+ .eq(5).val(hsb.s).end()
46
+ .eq(6).val(hsb.b).end();
47
+ },
48
+ fillHexFields = function (hsb, cal) {
49
+ $(cal).data('colorpicker').fields
50
+ .eq(0).val(HSBToHex(hsb)).end();
51
+ },
52
+ setSelector = function (hsb, cal) {
53
+ $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
54
+ $(cal).data('colorpicker').selectorIndic.css({
55
+ left: parseInt(150 * hsb.s/100, 10),
56
+ top: parseInt(150 * (100-hsb.b)/100, 10)
57
+ });
58
+ },
59
+ setHue = function (hsb, cal) {
60
+ $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
61
+ },
62
+ setCurrentColor = function (hsb, cal) {
63
+ $(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
64
+ },
65
+ setNewColor = function (hsb, cal) {
66
+ $(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
67
+ },
68
+ keyDown = function (ev) {
69
+ var pressedKey = ev.charCode || ev.keyCode || -1;
70
+ if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
71
+ return false;
72
+ }
73
+ var cal = $(this).parent().parent();
74
+ if (cal.data('colorpicker').livePreview === true) {
75
+ change.apply(this);
76
+ }
77
+ },
78
+ change = function (ev) {
79
+ var cal = $(this).parent().parent(), col;
80
+ debug("change");
81
+ if (this.parentNode.className.indexOf('_hex') > 0) {
82
+ cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
83
+ } else if (this.parentNode.className.indexOf('_hsb') > 0) {
84
+ cal.data('colorpicker').color = col = fixHSB({
85
+ h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
86
+ s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
87
+ b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
88
+ });
89
+ } else {
90
+ cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
91
+ r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
92
+ g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
93
+ b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
94
+ }));
95
+ }
96
+ if (ev) {
97
+ fillRGBFields(col, cal.get(0));
98
+ fillHexFields(col, cal.get(0));
99
+ fillHSBFields(col, cal.get(0));
100
+ }
101
+ setSelector(col, cal.get(0));
102
+ setHue(col, cal.get(0));
103
+ setNewColor(col, cal.get(0));
104
+ cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el]);
105
+ },
106
+ blur = function (ev) {
107
+ var cal = $(this).parent().parent();
108
+ cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
109
+ },
110
+ focus = function () {
111
+ charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
112
+ $(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
113
+ $(this).parent().addClass('colorpicker_focus');
114
+ },
115
+ downIncrement = function (ev) {
116
+ var field = $(this).parent().find('input').focus();
117
+ var current = {
118
+ el: $(this).parent().addClass('colorpicker_slider'),
119
+ max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
120
+ y: ev.pageY,
121
+ field: field,
122
+ val: parseInt(field.val(), 10),
123
+ preview: $(this).parent().parent().data('colorpicker').livePreview
124
+ };
125
+ $(document).bind('mouseup', current, upIncrement);
126
+ $(document).bind('mousemove', current, moveIncrement);
127
+ },
128
+ moveIncrement = function (ev) {
129
+ ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
130
+ if (ev.data.preview) {
131
+ change.apply(ev.data.field.get(0), [true]);
132
+ }
133
+ debug("move");
134
+ return false;
135
+ },
136
+ upIncrement = function (ev) {
137
+ change.apply(ev.data.field.get(0), [true]);
138
+ ev.data.el.removeClass('colorpicker_slider').find('input').focus();
139
+ $(document).unbind('mouseup', upIncrement);
140
+ $(document).unbind('mousemove', moveIncrement);
141
+ return false;
142
+ },
143
+ downHue = function (ev) {
144
+ var current = {
145
+ cal: $(this).parent(),
146
+ y: $(this).offset().top
147
+ };
148
+ current.preview = current.cal.data('colorpicker').livePreview;
149
+ var current2 = ev;
150
+ current2.data = current;
151
+ $(document).bind('mouseup', current, upHue);
152
+ $(document).bind('mousemove', current, moveHue);
153
+ moveHue(current2);
154
+ debug("down");
155
+ },
156
+ moveHue = function (ev) {
157
+ change.apply(
158
+ ev.data.cal.data('colorpicker')
159
+ .fields
160
+ .eq(4)
161
+ .val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
162
+ .get(0),
163
+ [ev.data.preview]
164
+ );
165
+ debug("move");
166
+ return false;
167
+ },
168
+ upHue = function (ev) {
169
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
170
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
171
+ $(document).unbind('mouseup', upHue);
172
+ $(document).unbind('mousemove', moveHue);
173
+ return false;
174
+ },
175
+ downSelector = function (ev) {
176
+ var current = {
177
+ cal: $(this).parent(),
178
+ pos: $(this).offset()
179
+ };
180
+ current.preview = current.cal.data('colorpicker').livePreview;
181
+ var current2 = ev;
182
+ current2.data = current;
183
+ $(document).bind('mouseup', current, upSelector);
184
+ $(document).bind('mousemove', current, moveSelector);
185
+ moveSelector(current2);
186
+ },
187
+ moveSelector = function (ev) {
188
+ change.apply(
189
+ ev.data.cal.data('colorpicker')
190
+ .fields
191
+ .eq(6)
192
+ .val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
193
+ .end()
194
+ .eq(5)
195
+ .val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
196
+ .get(0),
197
+ [ev.data.preview]
198
+ );
199
+ return false;
200
+ },
201
+ upSelector = function (ev) {
202
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
203
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
204
+ $(document).unbind('mouseup', upSelector);
205
+ $(document).unbind('mousemove', moveSelector);
206
+ return false;
207
+ },
208
+ enterSubmit = function (ev) {
209
+ $(this).addClass('colorpicker_focus');
210
+ },
211
+ leaveSubmit = function (ev) {
212
+ $(this).removeClass('colorpicker_focus');
213
+ },
214
+ clickSubmit = function (ev) {
215
+ var cal = $(this).parent();
216
+ var col = cal.data('colorpicker').color;
217
+ cal.data('colorpicker').origColor = col;
218
+ setCurrentColor(col, cal.get(0));
219
+ cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
220
+ },
221
+ show = function (ev) {
222
+ var cal = $('#' + $(this).data('colorpickerId'));
223
+ cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
224
+ var pos = $(this).offset();
225
+ var viewPort = getViewport();
226
+ var top = pos.top + this.offsetHeight;
227
+ var left = pos.left;
228
+ if (top + 176 > viewPort.t + viewPort.h) {
229
+ top -= this.offsetHeight + 176;
230
+ }
231
+ if (left + 356 > viewPort.l + viewPort.w) {
232
+ left -= 356;
233
+ }
234
+ cal.css({left: left + 'px', top: top + 'px'});
235
+ if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
236
+ cal.show();
237
+ }
238
+ $(document).bind('mousedown', {cal: cal}, hide);
239
+ return false;
240
+ },
241
+ hide = function (ev) {
242
+ if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
243
+ if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
244
+ ev.data.cal.hide();
245
+ }
246
+ $(document).unbind('mousedown', hide);
247
+ }
248
+ },
249
+ isChildOf = function(parentEl, el, container) {
250
+ if (parentEl == el) {
251
+ return true;
252
+ }
253
+ if (parentEl.contains) {
254
+ return parentEl.contains(el);
255
+ }
256
+ if ( parentEl.compareDocumentPosition ) {
257
+ return !!(parentEl.compareDocumentPosition(el) & 16);
258
+ }
259
+ var prEl = el.parentNode;
260
+ while(prEl && prEl != container) {
261
+ if (prEl == parentEl)
262
+ return true;
263
+ prEl = prEl.parentNode;
264
+ }
265
+ return false;
266
+ },
267
+ getViewport = function () {
268
+ var m = document.compatMode == 'CSS1Compat';
269
+ return {
270
+ l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
271
+ t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
272
+ w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
273
+ h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
274
+ };
275
+ },
276
+ fixHSB = function (hsb) {
277
+ return {
278
+ h: Math.min(360, Math.max(0, hsb.h)),
279
+ s: Math.min(100, Math.max(0, hsb.s)),
280
+ b: Math.min(100, Math.max(0, hsb.b))
281
+ };
282
+ },
283
+ fixRGB = function (rgb) {
284
+ return {
285
+ r: Math.min(255, Math.max(0, rgb.r)),
286
+ g: Math.min(255, Math.max(0, rgb.g)),
287
+ b: Math.min(255, Math.max(0, rgb.b))
288
+ };
289
+ },
290
+ fixHex = function (hex) {
291
+ var len = 6 - hex.length;
292
+ if (len > 0) {
293
+ var o = [];
294
+ for (var i=0; i<len; i++) {
295
+ o.push('0');
296
+ }
297
+ o.push(hex);
298
+ hex = o.join('');
299
+ }
300
+ return hex;
301
+ },
302
+ HexToRGB = function (hex) {
303
+ var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
304
+ return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
305
+ },
306
+ HexToHSB = function (hex) {
307
+ return RGBToHSB(HexToRGB(hex));
308
+ },
309
+ RGBToHSB = function (rgb) {
310
+ var hsb = {
311
+ h: 0,
312
+ s: 0,
313
+ b: 0
314
+ };
315
+ var min = Math.min(rgb.r, rgb.g, rgb.b);
316
+ var max = Math.max(rgb.r, rgb.g, rgb.b);
317
+ var delta = max - min;
318
+ hsb.b = max;
319
+ if (max != 0) {
320
+
321
+ }
322
+ hsb.s = max != 0 ? 255 * delta / max : 0;
323
+ if (hsb.s != 0) {
324
+ if (rgb.r == max) {
325
+ hsb.h = (rgb.g - rgb.b) / delta;
326
+ } else if (rgb.g == max) {
327
+ hsb.h = 2 + (rgb.b - rgb.r) / delta;
328
+ } else {
329
+ hsb.h = 4 + (rgb.r - rgb.g) / delta;
330
+ }
331
+ } else {
332
+ hsb.h = -1;
333
+ }
334
+ hsb.h *= 60;
335
+ if (hsb.h < 0) {
336
+ hsb.h += 360;
337
+ }
338
+ hsb.s *= 100/255;
339
+ hsb.b *= 100/255;
340
+ return hsb;
341
+ },
342
+ HSBToRGB = function (hsb) {
343
+ var rgb = {};
344
+ var h = Math.round(hsb.h);
345
+ var s = Math.round(hsb.s*255/100);
346
+ var v = Math.round(hsb.b*255/100);
347
+ if(s == 0) {
348
+ rgb.r = rgb.g = rgb.b = v;
349
+ } else {
350
+ var t1 = v;
351
+ var t2 = (255-s)*v/255;
352
+ var t3 = (t1-t2)*(h%60)/60;
353
+ if(h==360) h = 0;
354
+ if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
355
+ else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
356
+ else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
357
+ else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
358
+ else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
359
+ else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
360
+ else {rgb.r=0; rgb.g=0; rgb.b=0}
361
+ }
362
+ return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
363
+ },
364
+ RGBToHex = function (rgb) {
365
+ var hex = [
366
+ rgb.r.toString(16),
367
+ rgb.g.toString(16),
368
+ rgb.b.toString(16)
369
+ ];
370
+ $.each(hex, function (nr, val) {
371
+ if (val.length == 1) {
372
+ hex[nr] = '0' + val;
373
+ }
374
+ });
375
+ return hex.join('');
376
+ },
377
+ HSBToHex = function (hsb) {
378
+ return RGBToHex(HSBToRGB(hsb));
379
+ },
380
+ restoreOriginal = function (ev) {
381
+ var cal = $(this).parent();
382
+ var col = cal.data('colorpicker').origColor;
383
+ col = fixHSB(col);
384
+ cal.data('colorpicker').color = col;
385
+ fillRGBFields(col, cal.get(0));
386
+ fillHexFields(col, cal.get(0));
387
+ fillHSBFields(col, cal.get(0));
388
+ setSelector(col, cal.get(0));
389
+ setHue(col, cal.get(0));
390
+ setCurrentColor(col, cal.get(0));
391
+ setNewColor(col, cal.get(0));
392
+ change.apply($(this).parent().find('.colorpicker_hsb_s input').get(0), [true]); // WOO IT WORKS! Needed to set get(0) to retrieve raw DOM elem
393
+ };
394
+ return {
395
+ init: function (opt) {
396
+ opt = $.extend({}, defaults, opt||{});
397
+ if (typeof opt.color == 'string') {
398
+ opt.color = HexToHSB(opt.color);
399
+ } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
400
+ opt.color = RGBToHSB(opt.color);
401
+ } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
402
+ opt.color = fixHSB(opt.color);
403
+ } else {
404
+ return this;
405
+ }
406
+ return this.each(function () {
407
+ if (!$(this).data('colorpickerId')) {
408
+ var options = $.extend({}, opt);
409
+ options.origColor = opt.color;
410
+ var id = 'collorpicker_' + parseInt(Math.random() * 1000);
411
+ $(this).data('colorpickerId', id);
412
+ var cal = $(tpl).attr('id', id);
413
+ if (options.flat) {
414
+ cal.appendTo(this).show();
415
+ } else {
416
+ cal.appendTo(document.body);
417
+ }
418
+ options.fields = cal
419
+ .find('input')
420
+ .bind('keyup', keyDown)
421
+ .bind('change', change)
422
+ .bind('blur', blur)
423
+ .bind('focus', focus);
424
+ cal
425
+ .find('span').bind('mousedown', downIncrement).end()
426
+ .find('>div.colorpicker_current_color').bind('click', restoreOriginal);
427
+ options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
428
+ options.selectorIndic = options.selector.find('div div');
429
+ options.el = this;
430
+ options.hue = cal.find('div.colorpicker_hue div');
431
+ cal.find('div.colorpicker_hue').bind('mousedown', downHue);
432
+ options.newColor = cal.find('div.colorpicker_new_color');
433
+ options.currentColor = cal.find('div.colorpicker_current_color');
434
+ cal.data('colorpicker', options);
435
+ cal.find('div.colorpicker_submit')
436
+ .bind('mouseenter', enterSubmit)
437
+ .bind('mouseleave', leaveSubmit)
438
+ .bind('click', clickSubmit);
439
+ fillRGBFields(options.color, cal.get(0));
440
+ fillHSBFields(options.color, cal.get(0));
441
+ fillHexFields(options.color, cal.get(0));
442
+ setHue(options.color, cal.get(0));
443
+ setSelector(options.color, cal.get(0));
444
+ setCurrentColor(options.color, cal.get(0));
445
+ setNewColor(options.color, cal.get(0));
446
+ if (options.flat) {
447
+ cal.css({
448
+ position: 'relative',
449
+ display: 'block'
450
+ });
451
+ } else {
452
+ $(this).bind(options.eventName, show);
453
+ }
454
+ }
455
+ });
456
+ },
457
+ showPicker: function() {
458
+ return this.each( function () {
459
+ if ($(this).data('colorpickerId')) {
460
+ show.apply(this);
461
+ }
462
+ });
463
+ },
464
+ hidePicker: function() {
465
+ return this.each( function () {
466
+ if ($(this).data('colorpickerId')) {
467
+ $('#' + $(this).data('colorpickerId')).hide();
468
+ }
469
+ });
470
+ },
471
+ setColor: function(col) {
472
+ if (typeof col == 'string') {
473
+ col = HexToHSB(col);
474
+ } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
475
+ col = RGBToHSB(col);
476
+ } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
477
+ col = fixHSB(col);
478
+ } else {
479
+ return this;
480
+ }
481
+ return this.each(function(){
482
+ if ($(this).data('colorpickerId')) {
483
+ var cal = $('#' + $(this).data('colorpickerId'));
484
+ cal.data('colorpicker').color = col;
485
+ cal.data('colorpicker').origColor = col;
486
+ fillRGBFields(col, cal.get(0));
487
+ fillHSBFields(col, cal.get(0));
488
+ fillHexFields(col, cal.get(0));
489
+ setHue(col, cal.get(0));
490
+ setSelector(col, cal.get(0));
491
+ setCurrentColor(col, cal.get(0));
492
+ setNewColor(col, cal.get(0));
493
+ }
494
+ });
495
+ }
496
+ };
497
+ }();
498
+ $.fn.extend({
499
+ ColorPicker: ColorPicker.init,
500
+ ColorPickerHide: ColorPicker.hidePicker,
501
+ ColorPickerShow: ColorPicker.showPicker,
502
+ ColorPickerSetColor: ColorPicker.setColor
503
+ });
504
+ })(jQuery)
@@ -0,0 +1,163 @@
1
+ .colorpicker {
2
+ width: 356px;
3
+ height: 176px;
4
+ overflow: hidden;
5
+ position: absolute;
6
+ background: image-url("eyecon/colorpicker/colorpicker_background.png");
7
+ font-family: Arial, Helvetica, sans-serif;
8
+ display: none;
9
+ }
10
+ .colorpicker_color {
11
+ width: 150px;
12
+ height: 150px;
13
+ left: 14px;
14
+ top: 13px;
15
+ position: absolute;
16
+ background: #f00;
17
+ overflow: hidden;
18
+ cursor: crosshair;
19
+ }
20
+ .colorpicker_color div {
21
+ position: absolute;
22
+ top: 0;
23
+ left: 0;
24
+ width: 150px;
25
+ height: 150px;
26
+ background: image-url("eyecon/colorpicker/colorpicker_overlay.png");
27
+ }
28
+ .colorpicker_color div div {
29
+ position: absolute;
30
+ top: 0;
31
+ left: 0;
32
+ width: 11px;
33
+ height: 11px;
34
+ overflow: hidden;
35
+ background: image-url("eyecon/colorpicker/colorpicker_select.gif");
36
+ margin: -5px 0 0 -5px;
37
+ }
38
+ .colorpicker_hue {
39
+ position: absolute;
40
+ top: 13px;
41
+ left: 171px;
42
+ width: 35px;
43
+ height: 150px;
44
+ cursor: n-resize;
45
+ }
46
+ .colorpicker_hue div {
47
+ position: absolute;
48
+ width: 35px;
49
+ height: 9px;
50
+ overflow: hidden;
51
+ background: image-url("eyecon/colorpicker/colorpicker_indic.gif") left top;
52
+ margin: -4px 0 0 0;
53
+ left: 0px;
54
+ }
55
+ .colorpicker_new_color {
56
+ position: absolute;
57
+ width: 60px;
58
+ height: 30px;
59
+ left: 213px;
60
+ top: 13px;
61
+ background: #f00;
62
+ }
63
+ .colorpicker_current_color {
64
+ position: absolute;
65
+ width: 60px;
66
+ height: 30px;
67
+ left: 283px;
68
+ top: 13px;
69
+ background: #f00;
70
+ cursor: pointer;
71
+ }
72
+ .colorpicker input {
73
+ background-color: transparent;
74
+ border: 1px solid transparent;
75
+ position: absolute;
76
+ font-size: 10px;
77
+ font-family: Arial, Helvetica, sans-serif;
78
+ color: #898989;
79
+ top: 4px;
80
+ right: 11px;
81
+ text-align: right;
82
+ margin: 0;
83
+ padding: 0;
84
+ height: 11px;
85
+ }
86
+ .colorpicker_hex {
87
+ position: absolute;
88
+ width: 72px;
89
+ height: 22px;
90
+ background: image-url("eyecon/colorpicker/colorpicker_hex.png") top;
91
+ left: 212px;
92
+ top: 142px;
93
+ }
94
+ .colorpicker_hex input {
95
+ right: 6px;
96
+ }
97
+ .colorpicker_field {
98
+ height: 22px;
99
+ width: 62px;
100
+ background-position: top;
101
+ position: absolute;
102
+ }
103
+ .colorpicker_field span {
104
+ position: absolute;
105
+ width: 12px;
106
+ height: 22px;
107
+ overflow: hidden;
108
+ top: 0;
109
+ right: 0;
110
+ cursor: n-resize;
111
+ }
112
+ .colorpicker_rgb_r {
113
+ background-image: image-url("eyecon/colorpicker/colorpicker_rgb_r.png");
114
+ top: 52px;
115
+ left: 212px;
116
+ }
117
+ .colorpicker_rgb_g {
118
+ background-image: image-url("eyecon/colorpicker/colorpicker_rgb_g.png");
119
+ top: 82px;
120
+ left: 212px;
121
+ }
122
+ .colorpicker_rgb_b {
123
+ background-image: image-url("eyecon/colorpicker/colorpicker_rgb_b.png");
124
+ top: 112px;
125
+ left: 212px;
126
+ }
127
+ .colorpicker_hsb_h {
128
+ background-image: image-url("eyecon/colorpicker/colorpicker_hsb_h.png");
129
+ top: 52px;
130
+ left: 282px;
131
+ }
132
+ .colorpicker_hsb_s {
133
+ background-image: image-url("eyecon/colorpicker/colorpicker_hsb_s.png");
134
+ top: 82px;
135
+ left: 282px;
136
+ }
137
+ .colorpicker_hsb_b {
138
+ background-image: image-url("eyecon/colorpicker/colorpicker_hsb_b.png");
139
+ top: 112px;
140
+ left: 282px;
141
+ }
142
+ .colorpicker_submit {
143
+ position: absolute;
144
+ width: 22px;
145
+ height: 22px;
146
+ background: image-url("eyecon/colorpicker/colorpicker_submit.png") top;
147
+ left: 322px;
148
+ top: 142px;
149
+ overflow: hidden;
150
+ cursor: pointer;
151
+ }
152
+ .colorpicker_focus {
153
+ background-position: center;
154
+ }
155
+ .colorpicker_hex.colorpicker_focus {
156
+ background-position: bottom;
157
+ }
158
+ .colorpicker_submit.colorpicker_focus {
159
+ background-position: bottom;
160
+ }
161
+ .colorpicker_slider {
162
+ background-position: bottom;
163
+ }
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eyecon-colorpicker-rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Vit
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-06 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: jquery-rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: sass-rails
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: jQuery colorpicker for Rails
49
+ email:
50
+ - andrew@avit.ca
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - eyecon-colorpicker-rails.gemspec
64
+ - lib/eyecon-colorpicker-rails.rb
65
+ - lib/eyecon-colorpicker-rails/engine.rb
66
+ - lib/eyecon-colorpicker-rails/railtie.rb
67
+ - lib/eyecon-colorpicker-rails/version.rb
68
+ - vendor/assets/images/eyecon/colorpicker/blank.gif
69
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_background.png
70
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_hex.png
71
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_hsb_b.png
72
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_hsb_h.png
73
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_hsb_s.png
74
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_indic.gif
75
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_overlay.png
76
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_rgb_b.png
77
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_rgb_g.png
78
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_rgb_r.png
79
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_select.gif
80
+ - vendor/assets/images/eyecon/colorpicker/colorpicker_submit.png
81
+ - vendor/assets/images/eyecon/colorpicker/custom_background.png
82
+ - vendor/assets/images/eyecon/colorpicker/custom_hex.png
83
+ - vendor/assets/images/eyecon/colorpicker/custom_hsb_b.png
84
+ - vendor/assets/images/eyecon/colorpicker/custom_hsb_h.png
85
+ - vendor/assets/images/eyecon/colorpicker/custom_hsb_s.png
86
+ - vendor/assets/images/eyecon/colorpicker/custom_indic.gif
87
+ - vendor/assets/images/eyecon/colorpicker/custom_rgb_b.png
88
+ - vendor/assets/images/eyecon/colorpicker/custom_rgb_g.png
89
+ - vendor/assets/images/eyecon/colorpicker/custom_rgb_r.png
90
+ - vendor/assets/images/eyecon/colorpicker/custom_submit.png
91
+ - vendor/assets/images/eyecon/colorpicker/select.png
92
+ - vendor/assets/images/eyecon/colorpicker/select2.png
93
+ - vendor/assets/images/eyecon/colorpicker/slider.png
94
+ - vendor/assets/javascripts/eyecon/colorpicker.js
95
+ - vendor/assets/stylesheets/eyecon/colorpicker.scss
96
+ homepage: https://github.com/avit/eyecon-colorpicker-rails
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options: []
101
+
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.24
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Integrate colorpicker widget from eyecon.ro into the Rails Asset Pipeline.
129
+ test_files: []
130
+