bootstrap-colorpicker2-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +51 -0
  6. data/Rakefile +1 -0
  7. data/bootstrap-colorpicker2-rails.gemspec +25 -0
  8. data/lib/bootstrap-colorpicker2-rails.rb +1 -0
  9. data/lib/bootstrap/colorpicker2/rails/engine.rb +10 -0
  10. data/lib/bootstrap/colorpicker2/rails/version.rb +7 -0
  11. data/test/colorpicker2_rails_test/.gitignore +16 -0
  12. data/test/colorpicker2_rails_test/Gemfile +49 -0
  13. data/test/colorpicker2_rails_test/README.rdoc +28 -0
  14. data/test/colorpicker2_rails_test/Rakefile +6 -0
  15. data/test/colorpicker2_rails_test/app/assets/images/.keep +0 -0
  16. data/test/colorpicker2_rails_test/app/assets/javascripts/application.js +17 -0
  17. data/test/colorpicker2_rails_test/app/assets/javascripts/page.js.coffee +3 -0
  18. data/test/colorpicker2_rails_test/app/assets/stylesheets/application.css +13 -0
  19. data/test/colorpicker2_rails_test/app/assets/stylesheets/custom.css.scss +2 -0
  20. data/test/colorpicker2_rails_test/app/assets/stylesheets/page.css.scss +3 -0
  21. data/test/colorpicker2_rails_test/app/controllers/application_controller.rb +5 -0
  22. data/test/colorpicker2_rails_test/app/controllers/concerns/.keep +0 -0
  23. data/test/colorpicker2_rails_test/app/controllers/pages_controller.rb +26 -0
  24. data/test/colorpicker2_rails_test/app/helpers/application_helper.rb +2 -0
  25. data/test/colorpicker2_rails_test/app/helpers/page_helper.rb +2 -0
  26. data/test/colorpicker2_rails_test/app/mailers/.keep +0 -0
  27. data/test/colorpicker2_rails_test/app/models/.keep +0 -0
  28. data/test/colorpicker2_rails_test/app/models/concerns/.keep +0 -0
  29. data/test/colorpicker2_rails_test/app/models/page.rb +2 -0
  30. data/test/colorpicker2_rails_test/app/views/layouts/application.html.erb +14 -0
  31. data/test/colorpicker2_rails_test/app/views/pages/new.html.erb +19 -0
  32. data/test/colorpicker2_rails_test/app/views/pages/show.html.erb +3 -0
  33. data/test/colorpicker2_rails_test/bin/bundle +3 -0
  34. data/test/colorpicker2_rails_test/bin/rails +4 -0
  35. data/test/colorpicker2_rails_test/bin/rake +4 -0
  36. data/test/colorpicker2_rails_test/config.ru +4 -0
  37. data/test/colorpicker2_rails_test/config/application.rb +25 -0
  38. data/test/colorpicker2_rails_test/config/boot.rb +4 -0
  39. data/test/colorpicker2_rails_test/config/database.yml +25 -0
  40. data/test/colorpicker2_rails_test/config/environment.rb +5 -0
  41. data/test/colorpicker2_rails_test/config/environments/development.rb +29 -0
  42. data/test/colorpicker2_rails_test/config/environments/production.rb +80 -0
  43. data/test/colorpicker2_rails_test/config/environments/test.rb +36 -0
  44. data/test/colorpicker2_rails_test/config/initializers/backtrace_silencers.rb +7 -0
  45. data/test/colorpicker2_rails_test/config/initializers/filter_parameter_logging.rb +4 -0
  46. data/test/colorpicker2_rails_test/config/initializers/inflections.rb +16 -0
  47. data/test/colorpicker2_rails_test/config/initializers/mime_types.rb +5 -0
  48. data/test/colorpicker2_rails_test/config/initializers/secret_token.rb +12 -0
  49. data/test/colorpicker2_rails_test/config/initializers/session_store.rb +3 -0
  50. data/test/colorpicker2_rails_test/config/initializers/wrap_parameters.rb +14 -0
  51. data/test/colorpicker2_rails_test/config/locales/en.yml +23 -0
  52. data/test/colorpicker2_rails_test/config/routes.rb +60 -0
  53. data/test/colorpicker2_rails_test/db/migrate/20141004181002_create_pages.rb +11 -0
  54. data/test/colorpicker2_rails_test/db/schema.rb +24 -0
  55. data/test/colorpicker2_rails_test/db/seeds.rb +7 -0
  56. data/test/colorpicker2_rails_test/lib/assets/.keep +0 -0
  57. data/test/colorpicker2_rails_test/lib/tasks/.keep +0 -0
  58. data/test/colorpicker2_rails_test/log/.keep +0 -0
  59. data/test/colorpicker2_rails_test/public/404.html +58 -0
  60. data/test/colorpicker2_rails_test/public/422.html +58 -0
  61. data/test/colorpicker2_rails_test/public/500.html +57 -0
  62. data/test/colorpicker2_rails_test/public/favicon.ico +0 -0
  63. data/test/colorpicker2_rails_test/public/robots.txt +5 -0
  64. data/test/colorpicker2_rails_test/test/controllers/.keep +0 -0
  65. data/test/colorpicker2_rails_test/test/controllers/page_controller_test.rb +7 -0
  66. data/test/colorpicker2_rails_test/test/fixtures/.keep +0 -0
  67. data/test/colorpicker2_rails_test/test/fixtures/pages.yml +11 -0
  68. data/test/colorpicker2_rails_test/test/helpers/.keep +0 -0
  69. data/test/colorpicker2_rails_test/test/helpers/page_helper_test.rb +4 -0
  70. data/test/colorpicker2_rails_test/test/integration/.keep +0 -0
  71. data/test/colorpicker2_rails_test/test/mailers/.keep +0 -0
  72. data/test/colorpicker2_rails_test/test/models/.keep +0 -0
  73. data/test/colorpicker2_rails_test/test/models/page_test.rb +7 -0
  74. data/test/colorpicker2_rails_test/test/test_helper.rb +15 -0
  75. data/test/colorpicker2_rails_test/vendor/assets/javascripts/.keep +0 -0
  76. data/test/colorpicker2_rails_test/vendor/assets/stylesheets/.keep +0 -0
  77. data/vendor/assets/images/alpha-horizontal.png +0 -0
  78. data/vendor/assets/images/alpha.png +0 -0
  79. data/vendor/assets/images/hue-horizontal.png +0 -0
  80. data/vendor/assets/images/hue.png +0 -0
  81. data/vendor/assets/images/saturation.png +0 -0
  82. data/vendor/assets/javascripts/bootstrap-colorpicker.js +953 -0
  83. data/vendor/assets/stylesheets/bootstrap-colorpicker.css +217 -0
  84. metadata +235 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PageControllerTest < ActionController::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ color_1: MyString
5
+ color_2: MyString
6
+ color_3: MyString
7
+
8
+ two:
9
+ color_1: MyString
10
+ color_2: MyString
11
+ color_3: MyString
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class PageHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PageTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,15 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ ActiveRecord::Migration.check_pending!
7
+
8
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
9
+ #
10
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
11
+ # -- they do not yet inherit this setting
12
+ fixtures :all
13
+
14
+ # Add more helper methods to be used by all tests here...
15
+ end
@@ -0,0 +1,953 @@
1
+ /*!
2
+ * Bootstrap Colorpicker
3
+ * http://mjolnic.github.io/bootstrap-colorpicker/
4
+ *
5
+ * Originally written by (c) 2012 Stefan Petre
6
+ * Licensed under the Apache License v2.0
7
+ * http://www.apache.org/licenses/LICENSE-2.0.txt
8
+ *
9
+ * @todo Update DOCS
10
+ */
11
+
12
+ (function(factory) {
13
+ "use strict";
14
+ if (typeof define === 'function' && define.amd) {
15
+ define(['jquery'], factory);
16
+ } else if (window.jQuery && !window.jQuery.fn.colorpicker) {
17
+ factory(window.jQuery);
18
+ }
19
+ }
20
+ (function($) {
21
+ 'use strict';
22
+
23
+ // Color object
24
+ var Color = function(val) {
25
+ this.value = {
26
+ h: 0,
27
+ s: 0,
28
+ b: 0,
29
+ a: 1
30
+ };
31
+ this.origFormat = null; // original string format
32
+ if (val) {
33
+ if (val.toLowerCase !== undefined) {
34
+ this.setColor(val);
35
+ } else if (val.h !== undefined) {
36
+ this.value = val;
37
+ }
38
+ }
39
+ };
40
+
41
+ Color.prototype = {
42
+ constructor: Color,
43
+ // 140 predefined colors from the HTML Colors spec
44
+ colors: {
45
+ "aliceblue": "#f0f8ff",
46
+ "antiquewhite": "#faebd7",
47
+ "aqua": "#00ffff",
48
+ "aquamarine": "#7fffd4",
49
+ "azure": "#f0ffff",
50
+ "beige": "#f5f5dc",
51
+ "bisque": "#ffe4c4",
52
+ "black": "#000000",
53
+ "blanchedalmond": "#ffebcd",
54
+ "blue": "#0000ff",
55
+ "blueviolet": "#8a2be2",
56
+ "brown": "#a52a2a",
57
+ "burlywood": "#deb887",
58
+ "cadetblue": "#5f9ea0",
59
+ "chartreuse": "#7fff00",
60
+ "chocolate": "#d2691e",
61
+ "coral": "#ff7f50",
62
+ "cornflowerblue": "#6495ed",
63
+ "cornsilk": "#fff8dc",
64
+ "crimson": "#dc143c",
65
+ "cyan": "#00ffff",
66
+ "darkblue": "#00008b",
67
+ "darkcyan": "#008b8b",
68
+ "darkgoldenrod": "#b8860b",
69
+ "darkgray": "#a9a9a9",
70
+ "darkgreen": "#006400",
71
+ "darkkhaki": "#bdb76b",
72
+ "darkmagenta": "#8b008b",
73
+ "darkolivegreen": "#556b2f",
74
+ "darkorange": "#ff8c00",
75
+ "darkorchid": "#9932cc",
76
+ "darkred": "#8b0000",
77
+ "darksalmon": "#e9967a",
78
+ "darkseagreen": "#8fbc8f",
79
+ "darkslateblue": "#483d8b",
80
+ "darkslategray": "#2f4f4f",
81
+ "darkturquoise": "#00ced1",
82
+ "darkviolet": "#9400d3",
83
+ "deeppink": "#ff1493",
84
+ "deepskyblue": "#00bfff",
85
+ "dimgray": "#696969",
86
+ "dodgerblue": "#1e90ff",
87
+ "firebrick": "#b22222",
88
+ "floralwhite": "#fffaf0",
89
+ "forestgreen": "#228b22",
90
+ "fuchsia": "#ff00ff",
91
+ "gainsboro": "#dcdcdc",
92
+ "ghostwhite": "#f8f8ff",
93
+ "gold": "#ffd700",
94
+ "goldenrod": "#daa520",
95
+ "gray": "#808080",
96
+ "green": "#008000",
97
+ "greenyellow": "#adff2f",
98
+ "honeydew": "#f0fff0",
99
+ "hotpink": "#ff69b4",
100
+ "indianred ": "#cd5c5c",
101
+ "indigo ": "#4b0082",
102
+ "ivory": "#fffff0",
103
+ "khaki": "#f0e68c",
104
+ "lavender": "#e6e6fa",
105
+ "lavenderblush": "#fff0f5",
106
+ "lawngreen": "#7cfc00",
107
+ "lemonchiffon": "#fffacd",
108
+ "lightblue": "#add8e6",
109
+ "lightcoral": "#f08080",
110
+ "lightcyan": "#e0ffff",
111
+ "lightgoldenrodyellow": "#fafad2",
112
+ "lightgrey": "#d3d3d3",
113
+ "lightgreen": "#90ee90",
114
+ "lightpink": "#ffb6c1",
115
+ "lightsalmon": "#ffa07a",
116
+ "lightseagreen": "#20b2aa",
117
+ "lightskyblue": "#87cefa",
118
+ "lightslategray": "#778899",
119
+ "lightsteelblue": "#b0c4de",
120
+ "lightyellow": "#ffffe0",
121
+ "lime": "#00ff00",
122
+ "limegreen": "#32cd32",
123
+ "linen": "#faf0e6",
124
+ "magenta": "#ff00ff",
125
+ "maroon": "#800000",
126
+ "mediumaquamarine": "#66cdaa",
127
+ "mediumblue": "#0000cd",
128
+ "mediumorchid": "#ba55d3",
129
+ "mediumpurple": "#9370d8",
130
+ "mediumseagreen": "#3cb371",
131
+ "mediumslateblue": "#7b68ee",
132
+ "mediumspringgreen": "#00fa9a",
133
+ "mediumturquoise": "#48d1cc",
134
+ "mediumvioletred": "#c71585",
135
+ "midnightblue": "#191970",
136
+ "mintcream": "#f5fffa",
137
+ "mistyrose": "#ffe4e1",
138
+ "moccasin": "#ffe4b5",
139
+ "navajowhite": "#ffdead",
140
+ "navy": "#000080",
141
+ "oldlace": "#fdf5e6",
142
+ "olive": "#808000",
143
+ "olivedrab": "#6b8e23",
144
+ "orange": "#ffa500",
145
+ "orangered": "#ff4500",
146
+ "orchid": "#da70d6",
147
+ "palegoldenrod": "#eee8aa",
148
+ "palegreen": "#98fb98",
149
+ "paleturquoise": "#afeeee",
150
+ "palevioletred": "#d87093",
151
+ "papayawhip": "#ffefd5",
152
+ "peachpuff": "#ffdab9",
153
+ "peru": "#cd853f",
154
+ "pink": "#ffc0cb",
155
+ "plum": "#dda0dd",
156
+ "powderblue": "#b0e0e6",
157
+ "purple": "#800080",
158
+ "red": "#ff0000",
159
+ "rosybrown": "#bc8f8f",
160
+ "royalblue": "#4169e1",
161
+ "saddlebrown": "#8b4513",
162
+ "salmon": "#fa8072",
163
+ "sandybrown": "#f4a460",
164
+ "seagreen": "#2e8b57",
165
+ "seashell": "#fff5ee",
166
+ "sienna": "#a0522d",
167
+ "silver": "#c0c0c0",
168
+ "skyblue": "#87ceeb",
169
+ "slateblue": "#6a5acd",
170
+ "slategray": "#708090",
171
+ "snow": "#fffafa",
172
+ "springgreen": "#00ff7f",
173
+ "steelblue": "#4682b4",
174
+ "tan": "#d2b48c",
175
+ "teal": "#008080",
176
+ "thistle": "#d8bfd8",
177
+ "tomato": "#ff6347",
178
+ "turquoise": "#40e0d0",
179
+ "violet": "#ee82ee",
180
+ "wheat": "#f5deb3",
181
+ "white": "#ffffff",
182
+ "whitesmoke": "#f5f5f5",
183
+ "yellow": "#ffff00",
184
+ "yellowgreen": "#9acd32"
185
+ },
186
+ _sanitizeNumber: function(val) {
187
+ if (typeof val === 'number') {
188
+ return val;
189
+ }
190
+ if (isNaN(val) || (val === null) || (val === '') || (val === undefined)) {
191
+ return 1;
192
+ }
193
+ if (val.toLowerCase !== undefined) {
194
+ return parseFloat(val);
195
+ }
196
+ return 1;
197
+ },
198
+ //parse a string to HSB
199
+ setColor: function(strVal) {
200
+ strVal = strVal.toLowerCase();
201
+ this.value = this.stringToHSB(strVal) || {
202
+ h: 0,
203
+ s: 0,
204
+ b: 0,
205
+ a: 1
206
+ };
207
+ },
208
+ stringToHSB: function(strVal) {
209
+ strVal = strVal.toLowerCase();
210
+ var that = this,
211
+ result = false;
212
+ $.each(this.stringParsers, function(i, parser) {
213
+ var match = parser.re.exec(strVal),
214
+ values = match && parser.parse.apply(that, [match]),
215
+ format = parser.format || 'rgba';
216
+ if (values) {
217
+ if (format.match(/hsla?/)) {
218
+ result = that.RGBtoHSB.apply(that, that.HSLtoRGB.apply(that, values));
219
+ } else {
220
+ result = that.RGBtoHSB.apply(that, values);
221
+ }
222
+ that.origFormat = format;
223
+ return false;
224
+ }
225
+ return true;
226
+ });
227
+ return result;
228
+ },
229
+ setHue: function(h) {
230
+ this.value.h = 1 - h;
231
+ },
232
+ setSaturation: function(s) {
233
+ this.value.s = s;
234
+ },
235
+ setBrightness: function(b) {
236
+ this.value.b = 1 - b;
237
+ },
238
+ setAlpha: function(a) {
239
+ this.value.a = parseInt((1 - a) * 100, 10) / 100;
240
+ },
241
+ toRGB: function(h, s, b, a) {
242
+ if (!h) {
243
+ h = this.value.h;
244
+ s = this.value.s;
245
+ b = this.value.b;
246
+ }
247
+ h *= 360;
248
+ var R, G, B, X, C;
249
+ h = (h % 360) / 60;
250
+ C = b * s;
251
+ X = C * (1 - Math.abs(h % 2 - 1));
252
+ R = G = B = b - C;
253
+
254
+ h = ~~h;
255
+ R += [C, X, 0, 0, X, C][h];
256
+ G += [X, C, C, X, 0, 0][h];
257
+ B += [0, 0, X, C, C, X][h];
258
+ return {
259
+ r: Math.round(R * 255),
260
+ g: Math.round(G * 255),
261
+ b: Math.round(B * 255),
262
+ a: a || this.value.a
263
+ };
264
+ },
265
+ toHex: function(h, s, b, a) {
266
+ var rgb = this.toRGB(h, s, b, a);
267
+ return '#' + ((1 << 24) | (parseInt(rgb.r) << 16) | (parseInt(rgb.g) << 8) | parseInt(rgb.b)).toString(16).substr(1);
268
+ },
269
+ toHSL: function(h, s, b, a) {
270
+ h = h || this.value.h;
271
+ s = s || this.value.s;
272
+ b = b || this.value.b;
273
+ a = a || this.value.a;
274
+
275
+ var H = h,
276
+ L = (2 - s) * b,
277
+ S = s * b;
278
+ if (L > 0 && L <= 1) {
279
+ S /= L;
280
+ } else {
281
+ S /= 2 - L;
282
+ }
283
+ L /= 2;
284
+ if (S > 1) {
285
+ S = 1;
286
+ }
287
+ return {
288
+ h: isNaN(H) ? 0 : H,
289
+ s: isNaN(S) ? 0 : S,
290
+ l: isNaN(L) ? 0 : L,
291
+ a: isNaN(a) ? 0 : a,
292
+ };
293
+ },
294
+ toAlias: function(r, g, b, a) {
295
+ var rgb = this.toHex(r, g, b, a);
296
+ for (var alias in this.colors) {
297
+ if (this.colors[alias] == rgb) {
298
+ return alias;
299
+ }
300
+ }
301
+ return false;
302
+ },
303
+ RGBtoHSB: function(r, g, b, a) {
304
+ r /= 255;
305
+ g /= 255;
306
+ b /= 255;
307
+
308
+ var H, S, V, C;
309
+ V = Math.max(r, g, b);
310
+ C = V - Math.min(r, g, b);
311
+ H = (C === 0 ? null :
312
+ V === r ? (g - b) / C :
313
+ V === g ? (b - r) / C + 2 :
314
+ (r - g) / C + 4
315
+ );
316
+ H = ((H + 360) % 6) * 60 / 360;
317
+ S = C === 0 ? 0 : C / V;
318
+ return {
319
+ h: this._sanitizeNumber(H),
320
+ s: S,
321
+ b: V,
322
+ a: this._sanitizeNumber(a)
323
+ };
324
+ },
325
+ HueToRGB: function(p, q, h) {
326
+ if (h < 0) {
327
+ h += 1;
328
+ } else if (h > 1) {
329
+ h -= 1;
330
+ }
331
+ if ((h * 6) < 1) {
332
+ return p + (q - p) * h * 6;
333
+ } else if ((h * 2) < 1) {
334
+ return q;
335
+ } else if ((h * 3) < 2) {
336
+ return p + (q - p) * ((2 / 3) - h) * 6;
337
+ } else {
338
+ return p;
339
+ }
340
+ },
341
+ HSLtoRGB: function(h, s, l, a) {
342
+ if (s < 0) {
343
+ s = 0;
344
+ }
345
+ var q;
346
+ if (l <= 0.5) {
347
+ q = l * (1 + s);
348
+ } else {
349
+ q = l + s - (l * s);
350
+ }
351
+
352
+ var p = 2 * l - q;
353
+
354
+ var tr = h + (1 / 3);
355
+ var tg = h;
356
+ var tb = h - (1 / 3);
357
+
358
+ var r = Math.round(this.HueToRGB(p, q, tr) * 255);
359
+ var g = Math.round(this.HueToRGB(p, q, tg) * 255);
360
+ var b = Math.round(this.HueToRGB(p, q, tb) * 255);
361
+ return [r, g, b, this._sanitizeNumber(a)];
362
+ },
363
+ toString: function(format) {
364
+ format = format || 'rgba';
365
+ switch (format) {
366
+ case 'rgb':
367
+ {
368
+ var rgb = this.toRGB();
369
+ return 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')';
370
+ }
371
+ break;
372
+ case 'rgba':
373
+ {
374
+ var rgb = this.toRGB();
375
+ return 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + rgb.a + ')';
376
+ }
377
+ break;
378
+ case 'hsl':
379
+ {
380
+ var hsl = this.toHSL();
381
+ return 'hsl(' + Math.round(hsl.h * 360) + ',' + Math.round(hsl.s * 100) + '%,' + Math.round(hsl.l * 100) + '%)';
382
+ }
383
+ break;
384
+ case 'hsla':
385
+ {
386
+ var hsl = this.toHSL();
387
+ return 'hsla(' + Math.round(hsl.h * 360) + ',' + Math.round(hsl.s * 100) + '%,' + Math.round(hsl.l * 100) + '%,' + hsl.a + ')';
388
+ }
389
+ break;
390
+ case 'hex':
391
+ {
392
+ return this.toHex();
393
+ }
394
+ break;
395
+ case 'alias':
396
+ return this.toAlias() || this.toHex();
397
+ default:
398
+ {
399
+ return false;
400
+ }
401
+ break;
402
+ }
403
+ },
404
+ // a set of RE's that can match strings and generate color tuples.
405
+ // from John Resig color plugin
406
+ // https://github.com/jquery/jquery-color/
407
+ stringParsers: [{
408
+ re: /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
409
+ format: 'hex',
410
+ parse: function(execResult) {
411
+ return [
412
+ parseInt(execResult[1], 16),
413
+ parseInt(execResult[2], 16),
414
+ parseInt(execResult[3], 16),
415
+ 1
416
+ ];
417
+ }
418
+ }, {
419
+ re: /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
420
+ format: 'hex',
421
+ parse: function(execResult) {
422
+ return [
423
+ parseInt(execResult[1] + execResult[1], 16),
424
+ parseInt(execResult[2] + execResult[2], 16),
425
+ parseInt(execResult[3] + execResult[3], 16),
426
+ 1
427
+ ];
428
+ }
429
+ }, {
430
+ re: /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*?\)/,
431
+ format: 'rgb',
432
+ parse: function(execResult) {
433
+ return [
434
+ execResult[1],
435
+ execResult[2],
436
+ execResult[3],
437
+ 1
438
+ ];
439
+ }
440
+ }, {
441
+ re: /rgb\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*?\)/,
442
+ format: 'rgb',
443
+ parse: function(execResult) {
444
+ return [
445
+ 2.55 * execResult[1],
446
+ 2.55 * execResult[2],
447
+ 2.55 * execResult[3],
448
+ 1
449
+ ];
450
+ }
451
+ }, {
452
+ re: /rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
453
+ format: 'rgba',
454
+ parse: function(execResult) {
455
+ return [
456
+ execResult[1],
457
+ execResult[2],
458
+ execResult[3],
459
+ execResult[4]
460
+ ];
461
+ }
462
+ }, {
463
+ re: /rgba\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
464
+ format: 'rgba',
465
+ parse: function(execResult) {
466
+ return [
467
+ 2.55 * execResult[1],
468
+ 2.55 * execResult[2],
469
+ 2.55 * execResult[3],
470
+ execResult[4]
471
+ ];
472
+ }
473
+ }, {
474
+ re: /hsl\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*?\)/,
475
+ format: 'hsl',
476
+ parse: function(execResult) {
477
+ return [
478
+ execResult[1] / 360,
479
+ execResult[2] / 100,
480
+ execResult[3] / 100,
481
+ execResult[4]
482
+ ];
483
+ }
484
+ }, {
485
+ re: /hsla\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
486
+ format: 'hsla',
487
+ parse: function(execResult) {
488
+ return [
489
+ execResult[1] / 360,
490
+ execResult[2] / 100,
491
+ execResult[3] / 100,
492
+ execResult[4]
493
+ ];
494
+ }
495
+ }, {
496
+ //predefined color name
497
+ re: /^([a-z]{3,})$/,
498
+ format: 'alias',
499
+ parse: function(execResult) {
500
+ var hexval = this.colorNameToHex(execResult[0]) || '#000000';
501
+ var match = this.stringParsers[0].re.exec(hexval),
502
+ values = match && this.stringParsers[0].parse.apply(this, [match]);
503
+ return values;
504
+ }
505
+ }],
506
+ colorNameToHex: function(name) {
507
+ if (typeof this.colors[name.toLowerCase()] !== 'undefined') {
508
+ return this.colors[name.toLowerCase()];
509
+ }
510
+ return false;
511
+ }
512
+ };
513
+
514
+
515
+ var defaults = {
516
+ horizontal: false, // horizontal mode layout ?
517
+ inline: false, //forces to show the colorpicker as an inline element
518
+ color: false, //forces a color
519
+ format: false, //forces a format
520
+ input: 'input', // children input selector
521
+ container: false, // container selector
522
+ component: '.add-on, .input-group-addon', // children component selector
523
+ sliders: {
524
+ saturation: {
525
+ maxLeft: 100,
526
+ maxTop: 100,
527
+ callLeft: 'setSaturation',
528
+ callTop: 'setBrightness'
529
+ },
530
+ hue: {
531
+ maxLeft: 0,
532
+ maxTop: 100,
533
+ callLeft: false,
534
+ callTop: 'setHue'
535
+ },
536
+ alpha: {
537
+ maxLeft: 0,
538
+ maxTop: 100,
539
+ callLeft: false,
540
+ callTop: 'setAlpha'
541
+ }
542
+ },
543
+ slidersHorz: {
544
+ saturation: {
545
+ maxLeft: 100,
546
+ maxTop: 100,
547
+ callLeft: 'setSaturation',
548
+ callTop: 'setBrightness'
549
+ },
550
+ hue: {
551
+ maxLeft: 100,
552
+ maxTop: 0,
553
+ callLeft: 'setHue',
554
+ callTop: false
555
+ },
556
+ alpha: {
557
+ maxLeft: 100,
558
+ maxTop: 0,
559
+ callLeft: 'setAlpha',
560
+ callTop: false
561
+ }
562
+ },
563
+ template: '<div class="colorpicker dropdown-menu">' +
564
+ '<div class="colorpicker-saturation"><i><b></b></i></div>' +
565
+ '<div class="colorpicker-hue"><i></i></div>' +
566
+ '<div class="colorpicker-alpha"><i></i></div>' +
567
+ '<div class="colorpicker-color"><div /></div>' +
568
+ '</div>'
569
+ };
570
+
571
+ var Colorpicker = function(element, options) {
572
+ this.element = $(element).addClass('colorpicker-element');
573
+ this.options = $.extend({}, defaults, this.element.data(), options);
574
+ this.component = this.options.component;
575
+ this.component = (this.component !== false) ? this.element.find(this.component) : false;
576
+ if (this.component && (this.component.length === 0)) {
577
+ this.component = false;
578
+ }
579
+ this.container = (this.options.container === true) ? this.element : this.options.container;
580
+ this.container = (this.container !== false) ? $(this.container) : false;
581
+
582
+ // Is the element an input? Should we search inside for any input?
583
+ this.input = this.element.is('input') ? this.element : (this.options.input ?
584
+ this.element.find(this.options.input) : false);
585
+ if (this.input && (this.input.length === 0)) {
586
+ this.input = false;
587
+ }
588
+ // Set HSB color
589
+ this.color = new Color(this.options.color !== false ? this.options.color : this.getValue());
590
+ this.format = this.options.format !== false ? this.options.format : this.color.origFormat;
591
+
592
+ // Setup picker
593
+ this.picker = $(this.options.template);
594
+ if (this.options.inline) {
595
+ this.picker.addClass('colorpicker-inline colorpicker-visible');
596
+ } else {
597
+ this.picker.addClass('colorpicker-hidden');
598
+ }
599
+ if (this.options.horizontal) {
600
+ this.picker.addClass('colorpicker-horizontal');
601
+ }
602
+ if (this.format === 'rgba' || this.format === 'hsla') {
603
+ this.picker.addClass('colorpicker-with-alpha');
604
+ }
605
+ this.picker.on('mousedown.colorpicker', $.proxy(this.mousedown, this));
606
+ this.picker.appendTo(this.container ? this.container : $('body'));
607
+
608
+ // Bind events
609
+ if (this.input !== false) {
610
+ this.input.on({
611
+ 'keyup.colorpicker': $.proxy(this.keyup, this)
612
+ });
613
+ if (this.component === false) {
614
+ this.element.on({
615
+ 'focus.colorpicker': $.proxy(this.show, this)
616
+ });
617
+ }
618
+ if (this.options.inline === false) {
619
+ this.element.on({
620
+ 'focusout.colorpicker': $.proxy(this.hide, this)
621
+ });
622
+ }
623
+ }
624
+
625
+ if (this.component !== false) {
626
+ this.component.on({
627
+ 'click.colorpicker': $.proxy(this.show, this)
628
+ });
629
+ }
630
+
631
+ if ((this.input === false) && (this.component === false)) {
632
+ this.element.on({
633
+ 'click.colorpicker': $.proxy(this.show, this)
634
+ });
635
+ }
636
+ this.update();
637
+
638
+ $($.proxy(function() {
639
+ this.element.trigger('create');
640
+ }, this));
641
+ };
642
+
643
+ Colorpicker.version = '2.0.0-beta';
644
+
645
+ Colorpicker.Color = Color;
646
+
647
+ Colorpicker.prototype = {
648
+ constructor: Colorpicker,
649
+ destroy: function() {
650
+ this.picker.remove();
651
+ this.element.removeData('colorpicker').off('.colorpicker');
652
+ if (this.input !== false) {
653
+ this.input.off('.colorpicker');
654
+ }
655
+ if (this.component !== false) {
656
+ this.component.off('.colorpicker');
657
+ }
658
+ this.element.removeClass('colorpicker-element');
659
+ this.element.trigger({
660
+ type: 'destroy'
661
+ });
662
+ },
663
+ reposition: function() {
664
+ if (this.options.inline !== false) {
665
+ return false;
666
+ }
667
+ var type = this.container && this.container[0] !== document.body ? 'position' : 'offset';
668
+ var offset = this.component ? this.component[type]() : this.element[type]();
669
+ this.picker.css({
670
+ top: offset.top + (this.component ? this.component.outerHeight() : this.element.outerHeight()),
671
+ left: offset.left
672
+ });
673
+ },
674
+ show: function(e) {
675
+ if (this.isDisabled()) {
676
+ return false;
677
+ }
678
+ this.picker.addClass('colorpicker-visible').removeClass('colorpicker-hidden');
679
+ this.reposition();
680
+ $(window).on('resize.colorpicker', $.proxy(this.reposition, this));
681
+ if (!this.hasInput() && e) {
682
+ if (e.stopPropagation && e.preventDefault) {
683
+ e.stopPropagation();
684
+ e.preventDefault();
685
+ }
686
+ }
687
+ if (this.options.inline === false) {
688
+ $(window.document).on({
689
+ 'mousedown.colorpicker': $.proxy(this.hide, this)
690
+ });
691
+ }
692
+ this.element.trigger({
693
+ type: 'showPicker',
694
+ color: this.color
695
+ });
696
+ },
697
+ hide: function() {
698
+ this.picker.addClass('colorpicker-hidden').removeClass('colorpicker-visible');
699
+ $(window).off('resize.colorpicker', this.reposition);
700
+ $(document).off({
701
+ 'mousedown.colorpicker': this.hide
702
+ });
703
+ this.update();
704
+ this.element.trigger({
705
+ type: 'hidePicker',
706
+ color: this.color
707
+ });
708
+ },
709
+ updateData: function(val) {
710
+ val = val || this.color.toString(this.format);
711
+ this.element.data('color', val);
712
+ return val;
713
+ },
714
+ updateInput: function(val) {
715
+ val = val || this.color.toString(this.format);
716
+ if (this.input !== false) {
717
+ this.input.prop('value', val);
718
+ }
719
+ return val;
720
+ },
721
+ updatePicker: function(val) {
722
+ if (val !== undefined) {
723
+ this.color = new Color(val);
724
+ }
725
+ var sl = (this.options.horizontal === false) ? this.options.sliders : this.options.slidersHorz;
726
+ var icns = this.picker.find('i');
727
+ if (icns.length === 0) {
728
+ return;
729
+ }
730
+ if (this.options.horizontal === false) {
731
+ sl = this.options.sliders;
732
+ icns.eq(1).css('top', sl.hue.maxTop * (1 - this.color.value.h)).end()
733
+ .eq(2).css('top', sl.alpha.maxTop * (1 - this.color.value.a));
734
+ } else {
735
+ sl = this.options.slidersHorz;
736
+ icns.eq(1).css('left', sl.hue.maxLeft * (1 - this.color.value.h)).end()
737
+ .eq(2).css('left', sl.alpha.maxLeft * (1 - this.color.value.a));
738
+ }
739
+ icns.eq(0).css({
740
+ 'top': sl.saturation.maxTop - this.color.value.b * sl.saturation.maxTop,
741
+ 'left': this.color.value.s * sl.saturation.maxLeft
742
+ });
743
+ this.picker.find('.colorpicker-saturation').css('backgroundColor', this.color.toHex(this.color.value.h, 1, 1, 1));
744
+ this.picker.find('.colorpicker-alpha').css('backgroundColor', this.color.toHex());
745
+ this.picker.find('.colorpicker-color, .colorpicker-color div').css('backgroundColor', this.color.toString(this.format));
746
+ return val;
747
+ },
748
+ updateComponent: function(val) {
749
+ val = val || this.color.toString(this.format);
750
+ if (this.component !== false) {
751
+ var icn = this.component.find('i').eq(0);
752
+ if (icn.length > 0) {
753
+ icn.css({
754
+ 'backgroundColor': val
755
+ });
756
+ } else {
757
+ this.component.css({
758
+ 'backgroundColor': val
759
+ });
760
+ }
761
+ }
762
+ return val;
763
+ },
764
+ update: function(force) {
765
+ var val = this.updateComponent();
766
+ if ((this.getValue(false) !== false) || (force === true)) {
767
+ // Update input/data only if the current value is not blank
768
+ this.updateInput(val);
769
+ this.updateData(val);
770
+ }
771
+ this.updatePicker();
772
+ return val;
773
+
774
+ },
775
+ setValue: function(val) { // set color manually
776
+ this.color = new Color(val);
777
+ this.update();
778
+ this.element.trigger({
779
+ type: 'changeColor',
780
+ color: this.color,
781
+ value: val
782
+ });
783
+ },
784
+ getValue: function(defaultValue) {
785
+ defaultValue = (defaultValue === undefined) ? '#000000' : defaultValue;
786
+ var val;
787
+ if (this.hasInput()) {
788
+ val = this.input.val();
789
+ } else {
790
+ val = this.element.data('color');
791
+ }
792
+ if ((val === undefined) || (val === '') || (val === null)) {
793
+ // if not defined or empty, return default
794
+ val = defaultValue;
795
+ }
796
+ return val;
797
+ },
798
+ hasInput: function() {
799
+ return (this.input !== false);
800
+ },
801
+ isDisabled: function() {
802
+ if (this.hasInput()) {
803
+ return (this.input.prop('disabled') === true);
804
+ }
805
+ return false;
806
+ },
807
+ disable: function() {
808
+ if (this.hasInput()) {
809
+ this.input.prop('disabled', true);
810
+ return true;
811
+ }
812
+ return false;
813
+ },
814
+ enable: function() {
815
+ if (this.hasInput()) {
816
+ this.input.prop('disabled', false);
817
+ return true;
818
+ }
819
+ return false;
820
+ },
821
+ currentSlider: null,
822
+ mousePointer: {
823
+ left: 0,
824
+ top: 0
825
+ },
826
+ mousedown: function(e) {
827
+ e.stopPropagation();
828
+ e.preventDefault();
829
+
830
+ var target = $(e.target);
831
+
832
+ //detect the slider and set the limits and callbacks
833
+ var zone = target.closest('div');
834
+ var sl = this.options.horizontal ? this.options.slidersHorz : this.options.sliders;
835
+ if (!zone.is('.colorpicker')) {
836
+ if (zone.is('.colorpicker-saturation')) {
837
+ this.currentSlider = $.extend({}, sl.saturation);
838
+ } else if (zone.is('.colorpicker-hue')) {
839
+ this.currentSlider = $.extend({}, sl.hue);
840
+ } else if (zone.is('.colorpicker-alpha')) {
841
+ this.currentSlider = $.extend({}, sl.alpha);
842
+ } else {
843
+ return false;
844
+ }
845
+ var offset = zone.offset();
846
+ //reference to guide's style
847
+ this.currentSlider.guide = zone.find('i')[0].style;
848
+ this.currentSlider.left = e.pageX - offset.left;
849
+ this.currentSlider.top = e.pageY - offset.top;
850
+ this.mousePointer = {
851
+ left: e.pageX,
852
+ top: e.pageY
853
+ };
854
+ //trigger mousemove to move the guide to the current position
855
+ $(document).on({
856
+ 'mousemove.colorpicker': $.proxy(this.mousemove, this),
857
+ 'mouseup.colorpicker': $.proxy(this.mouseup, this)
858
+ }).trigger('mousemove');
859
+ }
860
+ return false;
861
+ },
862
+ mousemove: function(e) {
863
+ e.stopPropagation();
864
+ e.preventDefault();
865
+ var left = Math.max(
866
+ 0,
867
+ Math.min(
868
+ this.currentSlider.maxLeft,
869
+ this.currentSlider.left + ((e.pageX || this.mousePointer.left) - this.mousePointer.left)
870
+ )
871
+ );
872
+ var top = Math.max(
873
+ 0,
874
+ Math.min(
875
+ this.currentSlider.maxTop,
876
+ this.currentSlider.top + ((e.pageY || this.mousePointer.top) - this.mousePointer.top)
877
+ )
878
+ );
879
+ this.currentSlider.guide.left = left + 'px';
880
+ this.currentSlider.guide.top = top + 'px';
881
+ if (this.currentSlider.callLeft) {
882
+ this.color[this.currentSlider.callLeft].call(this.color, left / 100);
883
+ }
884
+ if (this.currentSlider.callTop) {
885
+ this.color[this.currentSlider.callTop].call(this.color, top / 100);
886
+ }
887
+ this.update(true);
888
+
889
+ this.element.trigger({
890
+ type: 'changeColor',
891
+ color: this.color
892
+ });
893
+ return false;
894
+ },
895
+ mouseup: function(e) {
896
+ e.stopPropagation();
897
+ e.preventDefault();
898
+ $(document).off({
899
+ 'mousemove.colorpicker': this.mousemove,
900
+ 'mouseup.colorpicker': this.mouseup
901
+ });
902
+ return false;
903
+ },
904
+ keyup: function(e) {
905
+ if ((e.keyCode === 38)) {
906
+ if (this.color.value.a < 1) {
907
+ this.color.value.a = Math.round((this.color.value.a + 0.01) * 100) / 100;
908
+ }
909
+ this.update(true);
910
+ } else if ((e.keyCode === 40)) {
911
+ if (this.color.value.a > 0) {
912
+ this.color.value.a = Math.round((this.color.value.a - 0.01) * 100) / 100;
913
+ }
914
+ this.update(true);
915
+ } else {
916
+ var val = this.input.val();
917
+ this.color = new Color(val);
918
+ if (this.getValue(false) !== false) {
919
+ this.updateData();
920
+ this.updateComponent();
921
+ this.updatePicker();
922
+ }
923
+ }
924
+ this.element.trigger({
925
+ type: 'changeColor',
926
+ color: this.color,
927
+ value: val
928
+ });
929
+ }
930
+ };
931
+
932
+ $.colorpicker = Colorpicker;
933
+
934
+ $.fn.colorpicker = function(option) {
935
+ var pickerArgs = arguments;
936
+
937
+ return this.each(function() {
938
+ var $this = $(this),
939
+ inst = $this.data('colorpicker'),
940
+ options = ((typeof option === 'object') ? option : {});
941
+ if ((!inst) && (typeof option !== 'string')) {
942
+ $this.data('colorpicker', new Colorpicker(this, options));
943
+ } else {
944
+ if (typeof option === 'string') {
945
+ inst[option].apply(inst, Array.prototype.slice.call(pickerArgs, 1));
946
+ }
947
+ }
948
+ });
949
+ };
950
+
951
+ $.fn.colorpicker.constructor = Colorpicker;
952
+
953
+ }));