jquery-minicolors-rails 2.1.4.1 → 2.2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -19
- data/lib/jquery-minicolors-rails.rb +0 -24
- data/lib/jquery-minicolors-rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.minicolors.js +1033 -836
- data/vendor/assets/stylesheets/jquery.minicolors.css +278 -0
- metadata +2 -9
- data/vendor/assets/images/jquery.minicolors.grid +0 -1
- data/vendor/assets/images/jquery.minicolors.grid.png +0 -0
- data/vendor/assets/images/jquery.minicolors.png +0 -0
- data/vendor/assets/images/jquery.minicolors.slider +0 -1
- data/vendor/assets/images/jquery.minicolors.slider.png +0 -0
- data/vendor/assets/images/jquery.minicolors.swatch +0 -1
- data/vendor/assets/images/jquery.minicolors.swatch.png +0 -0
- data/vendor/assets/stylesheets/jquery.minicolors.css.erb +0 -292
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870266e817956f141f6ce934a3cca56a3e3d2087
|
4
|
+
data.tar.gz: 85248ae97fce0bb91d8ec6c2d04a09cec278800a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdf04d688331f79754e8daae188225b38a3d5235e3f6bc23b031392b66b0534d17f2ea46b08cda077bdf15f947393b4513e471f9c91b580be42dd5894f5b936e
|
7
|
+
data.tar.gz: c08f3bf231f3ce831ad19bdc15368cb6d3ac58dd87cebb2bd9479b4a6b8d1bc4481e981e308895c4c76a79731ea50756a0b5dbbfc1836765b3559ece4a9e0e11
|
data/README.md
CHANGED
@@ -73,32 +73,28 @@ See https://github.com/plataformatec/simple_form
|
|
73
73
|
<% end %>
|
74
74
|
```
|
75
75
|
|
76
|
-
##
|
77
|
-
|
78
|
-
As of https://github.com/rails/rails/pull/7968 (Rails > 4.*) the asset pipeline precompile command will ignore the images.
|
79
|
-
Since `jquery.minicolors` uses an image for backgrounds, the image is by default splitted into chunks of data URLs and embedded into the CSS directly.
|
80
|
-
This results in a slightly bigger compiled CSS (~50k bigger), but avoids unnecessary image request to the server and headache on deployment.
|
81
|
-
You can still instruct `JqueryMinicolorsRails` to use the original image instead of the data URLs:
|
76
|
+
## Testing
|
82
77
|
|
83
|
-
```
|
84
|
-
|
85
|
-
JqueryMinicolorsRails.use_data_urls = false
|
78
|
+
```bash
|
79
|
+
bundle exec rspec
|
86
80
|
```
|
87
81
|
|
88
|
-
|
82
|
+
Since this gem uses a lot of different frameworks, anything is possible. So despite the specs are
|
83
|
+
"green", please verify manually:
|
89
84
|
|
90
|
-
```
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
85
|
+
```bash
|
86
|
+
cd test_app
|
87
|
+
bundle
|
88
|
+
rails s
|
89
|
+
open http://localhost:3000/ # Assert everything looks & works good.
|
96
90
|
```
|
97
91
|
|
98
|
-
## Testing
|
99
|
-
|
100
92
|
```bash
|
101
|
-
|
93
|
+
rm -rf tmp/cache
|
94
|
+
rm -rf public/assets
|
95
|
+
RAILS_ENV=production bundle exec rake assets:precompile
|
96
|
+
rails s -eproduction
|
97
|
+
open http://localhost:3000/ # Assert everything looks & works good.
|
102
98
|
```
|
103
99
|
|
104
100
|
## Versioning
|
@@ -1,28 +1,4 @@
|
|
1
1
|
require 'jquery-minicolors-rails/engine'
|
2
2
|
|
3
3
|
module JqueryMinicolorsRails
|
4
|
-
class << self
|
5
|
-
attr_writer :use_data_urls
|
6
|
-
|
7
|
-
def use_data_urls?
|
8
|
-
defined?(@use_data_urls) ? !!@use_data_urls : true
|
9
|
-
end
|
10
|
-
|
11
|
-
def image_data_url(name)
|
12
|
-
image_data_url_cache.fetch(name) do
|
13
|
-
image_data_url_cache[:name] = load_image_data_url(name)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def image_data_url_cache
|
20
|
-
@image_data_url_cache ||= {}
|
21
|
-
end
|
22
|
-
|
23
|
-
def load_image_data_url(name)
|
24
|
-
path = File.expand_path("../../vendor/assets/images/jquery.minicolors.#{name}", __FILE__)
|
25
|
-
File.read(path).strip
|
26
|
-
end
|
27
|
-
end
|
28
4
|
end
|
@@ -1,842 +1,1039 @@
|
|
1
1
|
/*
|
2
2
|
* jQuery MiniColors: A tiny color picker built on jQuery
|
3
3
|
*
|
4
|
-
* Copyright Cory LaViska for A Beautiful Site, LLC
|
4
|
+
* Copyright: Cory LaViska for A Beautiful Site, LLC: http://www.abeautifulsite.net/
|
5
5
|
*
|
6
|
-
*
|
6
|
+
* Contribute: https://github.com/claviska/jquery-minicolors
|
7
|
+
*
|
8
|
+
* @license: http://opensource.org/licenses/MIT
|
7
9
|
*
|
8
10
|
*/
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
11
|
+
(function (factory) {
|
12
|
+
/* jshint ignore:start */
|
13
|
+
if (typeof define === 'function' && define.amd) {
|
14
|
+
// AMD. Register as an anonymous module.
|
15
|
+
define(['jquery'], factory);
|
16
|
+
} else if (typeof exports === 'object') {
|
17
|
+
// Node/CommonJS
|
18
|
+
module.exports = factory(require('jquery'));
|
19
|
+
} else {
|
20
|
+
// Browser globals
|
21
|
+
factory(jQuery);
|
22
|
+
}
|
23
|
+
/* jshint ignore:end */
|
24
|
+
}(function ($) {
|
25
|
+
|
26
|
+
'use strict';
|
27
|
+
|
28
|
+
// Defaults
|
29
|
+
$.minicolors = {
|
30
|
+
defaults: {
|
31
|
+
animationSpeed: 50,
|
32
|
+
animationEasing: 'swing',
|
33
|
+
change: null,
|
34
|
+
changeDelay: 0,
|
35
|
+
control: 'hue',
|
36
|
+
dataUris: true,
|
37
|
+
defaultValue: '',
|
38
|
+
format: 'hex',
|
39
|
+
hide: null,
|
40
|
+
hideSpeed: 100,
|
41
|
+
inline: false,
|
42
|
+
keywords: '',
|
43
|
+
letterCase: 'lowercase',
|
44
|
+
opacity: false,
|
45
|
+
position: 'bottom left',
|
46
|
+
show: null,
|
47
|
+
showSpeed: 100,
|
48
|
+
theme: 'default'
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
// Public methods
|
53
|
+
$.extend($.fn, {
|
54
|
+
minicolors: function(method, data) {
|
55
|
+
|
56
|
+
switch(method) {
|
57
|
+
|
58
|
+
// Destroy the control
|
59
|
+
case 'destroy':
|
60
|
+
$(this).each( function() {
|
61
|
+
destroy($(this));
|
62
|
+
});
|
63
|
+
return $(this);
|
64
|
+
|
65
|
+
// Hide the color picker
|
66
|
+
case 'hide':
|
67
|
+
hide();
|
68
|
+
return $(this);
|
69
|
+
|
70
|
+
// Get/set opacity
|
71
|
+
case 'opacity':
|
72
|
+
// Getter
|
73
|
+
if( data === undefined ) {
|
74
|
+
// Getter
|
75
|
+
return $(this).attr('data-opacity');
|
76
|
+
} else {
|
77
|
+
// Setter
|
78
|
+
$(this).each( function() {
|
79
|
+
updateFromInput($(this).attr('data-opacity', data));
|
80
|
+
});
|
81
|
+
}
|
82
|
+
return $(this);
|
83
|
+
|
84
|
+
// Get an RGB(A) object based on the current color/opacity
|
85
|
+
case 'rgbObject':
|
86
|
+
return rgbObject($(this), method === 'rgbaObject');
|
87
|
+
|
88
|
+
// Get an RGB(A) string based on the current color/opacity
|
89
|
+
case 'rgbString':
|
90
|
+
case 'rgbaString':
|
91
|
+
return rgbString($(this), method === 'rgbaString');
|
92
|
+
|
93
|
+
// Get/set settings on the fly
|
94
|
+
case 'settings':
|
95
|
+
if( data === undefined ) {
|
96
|
+
return $(this).data('minicolors-settings');
|
97
|
+
} else {
|
98
|
+
// Setter
|
99
|
+
$(this).each( function() {
|
100
|
+
var settings = $(this).data('minicolors-settings') || {};
|
101
|
+
destroy($(this));
|
102
|
+
$(this).minicolors($.extend(true, settings, data));
|
103
|
+
});
|
104
|
+
}
|
105
|
+
return $(this);
|
106
|
+
|
107
|
+
// Show the color picker
|
108
|
+
case 'show':
|
109
|
+
show( $(this).eq(0) );
|
110
|
+
return $(this);
|
111
|
+
|
112
|
+
// Get/set the hex color value
|
113
|
+
case 'value':
|
114
|
+
if( data === undefined ) {
|
115
|
+
// Getter
|
116
|
+
return $(this).val();
|
117
|
+
} else {
|
118
|
+
// Setter
|
119
|
+
$(this).each( function() {
|
120
|
+
if( typeof(data) === 'object' ) {
|
121
|
+
if( data.opacity ) {
|
122
|
+
$(this).attr('data-opacity', keepWithin(data.opacity, 0, 1));
|
123
|
+
}
|
124
|
+
if( data.color ) {
|
125
|
+
$(this).val(data.color);
|
126
|
+
}
|
127
|
+
} else {
|
128
|
+
$(this).val(data);
|
129
|
+
}
|
130
|
+
updateFromInput($(this));
|
131
|
+
});
|
132
|
+
}
|
133
|
+
return $(this);
|
134
|
+
|
135
|
+
// Initializes the control
|
136
|
+
default:
|
137
|
+
if( method !== 'create' ) data = method;
|
138
|
+
$(this).each( function() {
|
139
|
+
init($(this), data);
|
140
|
+
});
|
141
|
+
return $(this);
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
});
|
147
|
+
|
148
|
+
// Initialize input elements
|
149
|
+
function init(input, settings) {
|
150
|
+
|
151
|
+
var minicolors = $('<div class="minicolors" />'),
|
152
|
+
defaults = $.minicolors.defaults,
|
153
|
+
opacity = input.attr('data-opacity'),
|
154
|
+
size;
|
155
|
+
|
156
|
+
// Do nothing if already initialized
|
157
|
+
if( input.data('minicolors-initialized') ) return;
|
158
|
+
|
159
|
+
// Handle settings
|
160
|
+
settings = $.extend(true, {}, defaults, settings);
|
161
|
+
|
162
|
+
// The wrapper
|
163
|
+
minicolors
|
164
|
+
.addClass('minicolors-theme-' + settings.theme)
|
165
|
+
.toggleClass('minicolors-with-opacity', settings.opacity)
|
166
|
+
.toggleClass('minicolors-no-data-uris', settings.dataUris !== true);
|
167
|
+
|
168
|
+
// Custom positioning
|
169
|
+
if( settings.position !== undefined ) {
|
170
|
+
$.each(settings.position.split(' '), function() {
|
171
|
+
minicolors.addClass('minicolors-position-' + this);
|
172
|
+
});
|
173
|
+
}
|
174
|
+
|
175
|
+
// Input size
|
176
|
+
if( settings.format === 'rgb' ) {
|
177
|
+
size = settings.opacity ? '25' : '20';
|
178
|
+
} else {
|
179
|
+
size = settings.keywords ? '11' : '7';
|
180
|
+
}
|
181
|
+
|
182
|
+
// The input
|
183
|
+
input
|
184
|
+
.addClass('minicolors-input')
|
185
|
+
.data('minicolors-initialized', false)
|
186
|
+
.data('minicolors-settings', settings)
|
187
|
+
.prop('size', size)
|
188
|
+
.wrap(minicolors)
|
189
|
+
.after(
|
190
|
+
'<div class="minicolors-panel minicolors-slider-' + settings.control + '">' +
|
191
|
+
'<div class="minicolors-slider minicolors-sprite">' +
|
192
|
+
'<div class="minicolors-picker"></div>' +
|
193
|
+
'</div>' +
|
194
|
+
'<div class="minicolors-opacity-slider minicolors-sprite">' +
|
195
|
+
'<div class="minicolors-picker"></div>' +
|
196
|
+
'</div>' +
|
197
|
+
'<div class="minicolors-grid minicolors-sprite">' +
|
198
|
+
'<div class="minicolors-grid-inner"></div>' +
|
199
|
+
'<div class="minicolors-picker"><div></div></div>' +
|
200
|
+
'</div>' +
|
201
|
+
'</div>'
|
202
|
+
);
|
203
|
+
|
204
|
+
// The swatch
|
205
|
+
if( !settings.inline ) {
|
206
|
+
input.after('<span class="minicolors-swatch minicolors-sprite"><span class="minicolors-swatch-color"></span></span>');
|
207
|
+
input.next('.minicolors-swatch').on('click', function(event) {
|
208
|
+
event.preventDefault();
|
209
|
+
input.focus();
|
210
|
+
});
|
211
|
+
}
|
212
|
+
|
213
|
+
// Prevent text selection in IE
|
214
|
+
input.parent().find('.minicolors-panel').on('selectstart', function() { return false; }).end();
|
215
|
+
|
216
|
+
// Inline controls
|
217
|
+
if( settings.inline ) input.parent().addClass('minicolors-inline');
|
218
|
+
|
219
|
+
updateFromInput(input, false);
|
220
|
+
|
221
|
+
input.data('minicolors-initialized', true);
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
// Returns the input back to its original state
|
226
|
+
function destroy(input) {
|
227
|
+
|
228
|
+
var minicolors = input.parent();
|
229
|
+
|
230
|
+
// Revert the input element
|
231
|
+
input
|
232
|
+
.removeData('minicolors-initialized')
|
233
|
+
.removeData('minicolors-settings')
|
234
|
+
.removeProp('size')
|
235
|
+
.removeClass('minicolors-input');
|
236
|
+
|
237
|
+
// Remove the wrap and destroy whatever remains
|
238
|
+
minicolors.before(input).remove();
|
239
|
+
|
240
|
+
}
|
241
|
+
|
242
|
+
// Shows the specified dropdown panel
|
243
|
+
function show(input) {
|
244
|
+
|
245
|
+
var minicolors = input.parent(),
|
246
|
+
panel = minicolors.find('.minicolors-panel'),
|
247
|
+
settings = input.data('minicolors-settings');
|
248
|
+
|
249
|
+
// Do nothing if uninitialized, disabled, inline, or already open
|
250
|
+
if( !input.data('minicolors-initialized') ||
|
251
|
+
input.prop('disabled') ||
|
252
|
+
minicolors.hasClass('minicolors-inline') ||
|
253
|
+
minicolors.hasClass('minicolors-focus')
|
254
|
+
) return;
|
255
|
+
|
256
|
+
hide();
|
257
|
+
|
258
|
+
minicolors.addClass('minicolors-focus');
|
259
|
+
panel
|
260
|
+
.stop(true, true)
|
261
|
+
.fadeIn(settings.showSpeed, function() {
|
262
|
+
if( settings.show ) settings.show.call(input.get(0));
|
263
|
+
});
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
// Hides all dropdown panels
|
268
|
+
function hide() {
|
269
|
+
|
270
|
+
$('.minicolors-focus').each( function() {
|
271
|
+
|
272
|
+
var minicolors = $(this),
|
273
|
+
input = minicolors.find('.minicolors-input'),
|
274
|
+
panel = minicolors.find('.minicolors-panel'),
|
275
|
+
settings = input.data('minicolors-settings');
|
276
|
+
|
277
|
+
panel.fadeOut(settings.hideSpeed, function() {
|
278
|
+
if( settings.hide ) settings.hide.call(input.get(0));
|
279
|
+
minicolors.removeClass('minicolors-focus');
|
280
|
+
});
|
281
|
+
|
282
|
+
});
|
283
|
+
}
|
284
|
+
|
285
|
+
// Moves the selected picker
|
286
|
+
function move(target, event, animate) {
|
287
|
+
|
288
|
+
var input = target.parents('.minicolors').find('.minicolors-input'),
|
289
|
+
settings = input.data('minicolors-settings'),
|
290
|
+
picker = target.find('[class$=-picker]'),
|
291
|
+
offsetX = target.offset().left,
|
292
|
+
offsetY = target.offset().top,
|
293
|
+
x = Math.round(event.pageX - offsetX),
|
294
|
+
y = Math.round(event.pageY - offsetY),
|
295
|
+
duration = animate ? settings.animationSpeed : 0,
|
296
|
+
wx, wy, r, phi;
|
297
|
+
|
298
|
+
// Touch support
|
299
|
+
if( event.originalEvent.changedTouches ) {
|
300
|
+
x = event.originalEvent.changedTouches[0].pageX - offsetX;
|
301
|
+
y = event.originalEvent.changedTouches[0].pageY - offsetY;
|
302
|
+
}
|
303
|
+
|
304
|
+
// Constrain picker to its container
|
305
|
+
if( x < 0 ) x = 0;
|
306
|
+
if( y < 0 ) y = 0;
|
307
|
+
if( x > target.width() ) x = target.width();
|
308
|
+
if( y > target.height() ) y = target.height();
|
309
|
+
|
310
|
+
// Constrain color wheel values to the wheel
|
311
|
+
if( target.parent().is('.minicolors-slider-wheel') && picker.parent().is('.minicolors-grid') ) {
|
312
|
+
wx = 75 - x;
|
313
|
+
wy = 75 - y;
|
314
|
+
r = Math.sqrt(wx * wx + wy * wy);
|
315
|
+
phi = Math.atan2(wy, wx);
|
316
|
+
if( phi < 0 ) phi += Math.PI * 2;
|
317
|
+
if( r > 75 ) {
|
318
|
+
r = 75;
|
319
|
+
x = 75 - (75 * Math.cos(phi));
|
320
|
+
y = 75 - (75 * Math.sin(phi));
|
321
|
+
}
|
322
|
+
x = Math.round(x);
|
323
|
+
y = Math.round(y);
|
324
|
+
}
|
325
|
+
|
326
|
+
// Move the picker
|
327
|
+
if( target.is('.minicolors-grid') ) {
|
328
|
+
picker
|
329
|
+
.stop(true)
|
330
|
+
.animate({
|
331
|
+
top: y + 'px',
|
332
|
+
left: x + 'px'
|
333
|
+
}, duration, settings.animationEasing, function() {
|
334
|
+
updateFromControl(input, target);
|
335
|
+
});
|
336
|
+
} else {
|
337
|
+
picker
|
338
|
+
.stop(true)
|
339
|
+
.animate({
|
340
|
+
top: y + 'px'
|
341
|
+
}, duration, settings.animationEasing, function() {
|
342
|
+
updateFromControl(input, target);
|
343
|
+
});
|
344
|
+
}
|
345
|
+
|
346
|
+
}
|
347
|
+
|
348
|
+
// Sets the input based on the color picker values
|
349
|
+
function updateFromControl(input, target) {
|
350
|
+
|
351
|
+
function getCoords(picker, container) {
|
352
|
+
|
353
|
+
var left, top;
|
354
|
+
if( !picker.length || !container ) return null;
|
355
|
+
left = picker.offset().left;
|
356
|
+
top = picker.offset().top;
|
357
|
+
|
358
|
+
return {
|
359
|
+
x: left - container.offset().left + (picker.outerWidth() / 2),
|
360
|
+
y: top - container.offset().top + (picker.outerHeight() / 2)
|
361
|
+
};
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
var hue, saturation, brightness, x, y, r, phi,
|
366
|
+
|
367
|
+
hex = input.val(),
|
368
|
+
opacity = input.attr('data-opacity'),
|
369
|
+
value,
|
370
|
+
|
371
|
+
// Helpful references
|
372
|
+
minicolors = input.parent(),
|
373
|
+
settings = input.data('minicolors-settings'),
|
374
|
+
swatch = minicolors.find('.minicolors-swatch'),
|
375
|
+
|
376
|
+
// Panel objects
|
377
|
+
grid = minicolors.find('.minicolors-grid'),
|
378
|
+
slider = minicolors.find('.minicolors-slider'),
|
379
|
+
opacitySlider = minicolors.find('.minicolors-opacity-slider'),
|
380
|
+
|
381
|
+
// Picker objects
|
382
|
+
gridPicker = grid.find('[class$=-picker]'),
|
383
|
+
sliderPicker = slider.find('[class$=-picker]'),
|
384
|
+
opacityPicker = opacitySlider.find('[class$=-picker]'),
|
385
|
+
|
386
|
+
// Picker positions
|
387
|
+
gridPos = getCoords(gridPicker, grid),
|
388
|
+
sliderPos = getCoords(sliderPicker, slider),
|
389
|
+
opacityPos = getCoords(opacityPicker, opacitySlider);
|
390
|
+
|
391
|
+
// Handle colors
|
392
|
+
if( target.is('.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider') ) {
|
393
|
+
|
394
|
+
// Determine HSB values
|
395
|
+
switch(settings.control) {
|
396
|
+
|
397
|
+
case 'wheel':
|
398
|
+
// Calculate hue, saturation, and brightness
|
399
|
+
x = (grid.width() / 2) - gridPos.x;
|
400
|
+
y = (grid.height() / 2) - gridPos.y;
|
401
|
+
r = Math.sqrt(x * x + y * y);
|
402
|
+
phi = Math.atan2(y, x);
|
403
|
+
if( phi < 0 ) phi += Math.PI * 2;
|
404
|
+
if( r > 75 ) {
|
405
|
+
r = 75;
|
406
|
+
gridPos.x = 69 - (75 * Math.cos(phi));
|
407
|
+
gridPos.y = 69 - (75 * Math.sin(phi));
|
408
|
+
}
|
409
|
+
saturation = keepWithin(r / 0.75, 0, 100);
|
410
|
+
hue = keepWithin(phi * 180 / Math.PI, 0, 360);
|
411
|
+
brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
|
412
|
+
hex = hsb2hex({
|
413
|
+
h: hue,
|
414
|
+
s: saturation,
|
415
|
+
b: brightness
|
416
|
+
});
|
417
|
+
|
418
|
+
// Update UI
|
419
|
+
slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
|
420
|
+
break;
|
421
|
+
|
422
|
+
case 'saturation':
|
423
|
+
// Calculate hue, saturation, and brightness
|
424
|
+
hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
|
425
|
+
saturation = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
|
426
|
+
brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
|
427
|
+
hex = hsb2hex({
|
428
|
+
h: hue,
|
429
|
+
s: saturation,
|
430
|
+
b: brightness
|
431
|
+
});
|
432
|
+
|
433
|
+
// Update UI
|
434
|
+
slider.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: brightness }));
|
435
|
+
minicolors.find('.minicolors-grid-inner').css('opacity', saturation / 100);
|
436
|
+
break;
|
437
|
+
|
438
|
+
case 'brightness':
|
439
|
+
// Calculate hue, saturation, and brightness
|
440
|
+
hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
|
441
|
+
saturation = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
|
442
|
+
brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
|
443
|
+
hex = hsb2hex({
|
444
|
+
h: hue,
|
445
|
+
s: saturation,
|
446
|
+
b: brightness
|
447
|
+
});
|
448
|
+
|
449
|
+
// Update UI
|
450
|
+
slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
|
451
|
+
minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (brightness / 100));
|
452
|
+
break;
|
453
|
+
|
454
|
+
default:
|
455
|
+
// Calculate hue, saturation, and brightness
|
456
|
+
hue = keepWithin(360 - parseInt(sliderPos.y * (360 / slider.height()), 10), 0, 360);
|
457
|
+
saturation = keepWithin(Math.floor(gridPos.x * (100 / grid.width())), 0, 100);
|
458
|
+
brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
|
459
|
+
hex = hsb2hex({
|
460
|
+
h: hue,
|
461
|
+
s: saturation,
|
462
|
+
b: brightness
|
463
|
+
});
|
464
|
+
|
465
|
+
// Update UI
|
466
|
+
grid.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: 100 }));
|
467
|
+
break;
|
468
|
+
|
469
|
+
}
|
470
|
+
|
471
|
+
// Handle opacity
|
472
|
+
if( settings.opacity ) {
|
473
|
+
opacity = parseFloat(1 - (opacityPos.y / opacitySlider.height())).toFixed(2);
|
474
|
+
} else {
|
475
|
+
opacity = 1;
|
476
|
+
}
|
477
|
+
if( settings.opacity ) input.attr('data-opacity', opacity);
|
478
|
+
|
479
|
+
// Set color string
|
480
|
+
if( settings.format === 'rgb' ) {
|
481
|
+
// Returns RGB(A) string
|
482
|
+
var rgb = hex2rgb(hex),
|
483
|
+
opacity = input.attr('data-opacity') === '' ? 1 : keepWithin( parseFloat( input.attr('data-opacity') ).toFixed(2), 0, 1 );
|
484
|
+
if( isNaN( opacity ) || !settings.opacity ) opacity = 1;
|
485
|
+
|
486
|
+
if( input.minicolors('rgbObject').a <= 1 && rgb && settings.opacity) {
|
487
|
+
// Set RGBA string if alpha
|
488
|
+
value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat( opacity ) + ')';
|
489
|
+
} else {
|
490
|
+
// Set RGB string (alpha = 1)
|
491
|
+
value = 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
|
492
|
+
}
|
493
|
+
} else {
|
494
|
+
// Returns hex color
|
495
|
+
value = convertCase( hex, settings.letterCase );
|
496
|
+
}
|
497
|
+
|
498
|
+
// Update value from picker
|
499
|
+
input.val( value );
|
500
|
+
}
|
501
|
+
|
502
|
+
// Set swatch color
|
503
|
+
swatch.find('span').css({
|
504
|
+
backgroundColor: hex,
|
505
|
+
opacity: opacity
|
506
|
+
});
|
507
|
+
|
508
|
+
// Handle change event
|
509
|
+
doChange(input, value, opacity);
|
510
|
+
|
511
|
+
}
|
512
|
+
|
513
|
+
// Sets the color picker values from the input
|
514
|
+
function updateFromInput(input, preserveInputValue) {
|
515
|
+
|
516
|
+
var hex,
|
517
|
+
hsb,
|
518
|
+
opacity,
|
519
|
+
keywords,
|
520
|
+
alpha,
|
521
|
+
value,
|
522
|
+
x, y, r, phi,
|
523
|
+
|
524
|
+
// Helpful references
|
525
|
+
minicolors = input.parent(),
|
526
|
+
settings = input.data('minicolors-settings'),
|
527
|
+
swatch = minicolors.find('.minicolors-swatch'),
|
528
|
+
|
529
|
+
// Panel objects
|
530
|
+
grid = minicolors.find('.minicolors-grid'),
|
531
|
+
slider = minicolors.find('.minicolors-slider'),
|
532
|
+
opacitySlider = minicolors.find('.minicolors-opacity-slider'),
|
533
|
+
|
534
|
+
// Picker objects
|
535
|
+
gridPicker = grid.find('[class$=-picker]'),
|
536
|
+
sliderPicker = slider.find('[class$=-picker]'),
|
537
|
+
opacityPicker = opacitySlider.find('[class$=-picker]');
|
538
|
+
|
539
|
+
// Determine hex/HSB values
|
540
|
+
if( isRgb(input.val()) ) {
|
541
|
+
// If input value is a rgb(a) string, convert it to hex color and update opacity
|
542
|
+
hex = rgbString2hex(input.val());
|
543
|
+
alpha = keepWithin(parseFloat(getAlpha(input.val())).toFixed(2), 0, 1);
|
544
|
+
if( alpha ) {
|
545
|
+
input.attr('data-opacity', alpha);
|
546
|
+
}
|
547
|
+
} else {
|
548
|
+
hex = convertCase(parseHex(input.val(), true), settings.letterCase);
|
549
|
+
}
|
550
|
+
|
551
|
+
if( !hex ){
|
552
|
+
hex = convertCase(parseInput(settings.defaultValue, true), settings.letterCase);
|
553
|
+
}
|
554
|
+
hsb = hex2hsb(hex);
|
555
|
+
|
556
|
+
// Get array of lowercase keywords
|
557
|
+
keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
|
558
|
+
return $.trim(a.toLowerCase());
|
559
|
+
});
|
560
|
+
|
561
|
+
// Set color string
|
562
|
+
if( input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1 ) {
|
563
|
+
value = convertCase(input.val());
|
564
|
+
} else {
|
565
|
+
value = isRgb(input.val()) ? parseRgb(input.val()) : hex;
|
566
|
+
}
|
567
|
+
|
568
|
+
// Update input value
|
569
|
+
if( !preserveInputValue ) input.val(value);
|
570
|
+
|
571
|
+
// Determine opacity value
|
572
|
+
if( settings.opacity ) {
|
573
|
+
// Get from data-opacity attribute and keep within 0-1 range
|
574
|
+
opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1);
|
575
|
+
if( isNaN(opacity) ) opacity = 1;
|
576
|
+
input.attr('data-opacity', opacity);
|
577
|
+
swatch.find('span').css('opacity', opacity);
|
578
|
+
|
579
|
+
// Set opacity picker position
|
580
|
+
y = keepWithin(opacitySlider.height() - (opacitySlider.height() * opacity), 0, opacitySlider.height());
|
581
|
+
opacityPicker.css('top', y + 'px');
|
582
|
+
}
|
583
|
+
|
584
|
+
// Set opacity to zero if input value is transparent
|
585
|
+
if( input.val().toLowerCase() === 'transparent' ) {
|
586
|
+
swatch.find('span').css('opacity', 0);
|
587
|
+
}
|
588
|
+
|
589
|
+
// Update swatch
|
590
|
+
swatch.find('span').css('backgroundColor', hex);
|
591
|
+
|
592
|
+
// Determine picker locations
|
593
|
+
switch(settings.control) {
|
594
|
+
|
595
|
+
case 'wheel':
|
596
|
+
// Set grid position
|
597
|
+
r = keepWithin(Math.ceil(hsb.s * 0.75), 0, grid.height() / 2);
|
598
|
+
phi = hsb.h * Math.PI / 180;
|
599
|
+
x = keepWithin(75 - Math.cos(phi) * r, 0, grid.width());
|
600
|
+
y = keepWithin(75 - Math.sin(phi) * r, 0, grid.height());
|
601
|
+
gridPicker.css({
|
602
|
+
top: y + 'px',
|
603
|
+
left: x + 'px'
|
604
|
+
});
|
605
|
+
|
606
|
+
// Set slider position
|
607
|
+
y = 150 - (hsb.b / (100 / grid.height()));
|
608
|
+
if( hex === '' ) y = 0;
|
609
|
+
sliderPicker.css('top', y + 'px');
|
610
|
+
|
611
|
+
// Update panel color
|
612
|
+
slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
|
613
|
+
break;
|
614
|
+
|
615
|
+
case 'saturation':
|
616
|
+
// Set grid position
|
617
|
+
x = keepWithin((5 * hsb.h) / 12, 0, 150);
|
618
|
+
y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
|
619
|
+
gridPicker.css({
|
620
|
+
top: y + 'px',
|
621
|
+
left: x + 'px'
|
622
|
+
});
|
623
|
+
|
624
|
+
// Set slider position
|
625
|
+
y = keepWithin(slider.height() - (hsb.s * (slider.height() / 100)), 0, slider.height());
|
626
|
+
sliderPicker.css('top', y + 'px');
|
627
|
+
|
628
|
+
// Update UI
|
629
|
+
slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: hsb.b }));
|
630
|
+
minicolors.find('.minicolors-grid-inner').css('opacity', hsb.s / 100);
|
631
|
+
break;
|
632
|
+
|
633
|
+
case 'brightness':
|
634
|
+
// Set grid position
|
635
|
+
x = keepWithin((5 * hsb.h) / 12, 0, 150);
|
636
|
+
y = keepWithin(grid.height() - Math.ceil(hsb.s / (100 / grid.height())), 0, grid.height());
|
637
|
+
gridPicker.css({
|
638
|
+
top: y + 'px',
|
639
|
+
left: x + 'px'
|
640
|
+
});
|
641
|
+
|
642
|
+
// Set slider position
|
643
|
+
y = keepWithin(slider.height() - (hsb.b * (slider.height() / 100)), 0, slider.height());
|
644
|
+
sliderPicker.css('top', y + 'px');
|
645
|
+
|
646
|
+
// Update UI
|
647
|
+
slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
|
648
|
+
minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (hsb.b / 100));
|
649
|
+
break;
|
650
|
+
|
651
|
+
default:
|
652
|
+
// Set grid position
|
653
|
+
x = keepWithin(Math.ceil(hsb.s / (100 / grid.width())), 0, grid.width());
|
654
|
+
y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
|
655
|
+
gridPicker.css({
|
656
|
+
top: y + 'px',
|
657
|
+
left: x + 'px'
|
658
|
+
});
|
659
|
+
|
660
|
+
// Set slider position
|
661
|
+
y = keepWithin(slider.height() - (hsb.h / (360 / slider.height())), 0, slider.height());
|
662
|
+
sliderPicker.css('top', y + 'px');
|
663
|
+
|
664
|
+
// Update panel color
|
665
|
+
grid.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: 100 }));
|
666
|
+
break;
|
667
|
+
|
668
|
+
}
|
669
|
+
|
670
|
+
// Fire change event, but only if minicolors is fully initialized
|
671
|
+
if( input.data('minicolors-initialized') ) {
|
672
|
+
doChange(input, value, opacity);
|
673
|
+
}
|
674
|
+
|
675
|
+
}
|
676
|
+
|
677
|
+
// Runs the change and changeDelay callbacks
|
678
|
+
function doChange(input, value, opacity) {
|
679
|
+
|
680
|
+
var settings = input.data('minicolors-settings'),
|
681
|
+
lastChange = input.data('minicolors-lastChange');
|
682
|
+
|
683
|
+
// Only run if it actually changed
|
684
|
+
if( !lastChange || lastChange.value !== value || lastChange.opacity !== opacity ) {
|
685
|
+
|
686
|
+
// Remember last-changed value
|
687
|
+
input.data('minicolors-lastChange', {
|
688
|
+
value: value,
|
689
|
+
opacity: opacity
|
690
|
+
});
|
691
|
+
|
692
|
+
// Fire change event
|
693
|
+
if( settings.change ) {
|
694
|
+
if( settings.changeDelay ) {
|
695
|
+
// Call after a delay
|
696
|
+
clearTimeout(input.data('minicolors-changeTimeout'));
|
697
|
+
input.data('minicolors-changeTimeout', setTimeout( function() {
|
698
|
+
settings.change.call(input.get(0), value, opacity);
|
699
|
+
}, settings.changeDelay));
|
700
|
+
} else {
|
701
|
+
// Call immediately
|
702
|
+
settings.change.call(input.get(0), value, opacity);
|
703
|
+
}
|
704
|
+
}
|
705
|
+
input.trigger('change').trigger('input');
|
706
|
+
}
|
707
|
+
|
708
|
+
}
|
709
|
+
|
710
|
+
// Generates an RGB(A) object based on the input's value
|
711
|
+
function rgbObject(input) {
|
712
|
+
var hex = parseHex($(input).val(), true),
|
713
|
+
rgb = hex2rgb(hex),
|
714
|
+
opacity = $(input).attr('data-opacity');
|
715
|
+
if( !rgb ) return null;
|
716
|
+
if( opacity !== undefined ) $.extend(rgb, { a: parseFloat(opacity) });
|
717
|
+
return rgb;
|
718
|
+
}
|
719
|
+
|
720
|
+
// Generates an RGB(A) string based on the input's value
|
721
|
+
function rgbString(input, alpha) {
|
722
|
+
var hex = parseHex($(input).val(), true),
|
723
|
+
rgb = hex2rgb(hex),
|
724
|
+
opacity = $(input).attr('data-opacity');
|
725
|
+
if( !rgb ) return null;
|
726
|
+
if( opacity === undefined ) opacity = 1;
|
727
|
+
if( alpha ) {
|
728
|
+
return 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')';
|
729
|
+
} else {
|
730
|
+
return 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
|
731
|
+
}
|
732
|
+
}
|
733
|
+
|
734
|
+
// Converts to the letter case specified in settings
|
735
|
+
function convertCase(string, letterCase) {
|
736
|
+
return letterCase === 'uppercase' ? string.toUpperCase() : string.toLowerCase();
|
737
|
+
}
|
738
|
+
|
739
|
+
// Parses a string and returns a valid hex string when possible
|
740
|
+
function parseHex(string, expand) {
|
741
|
+
string = string.replace(/^#/g, '');
|
742
|
+
if( !string.match(/^[A-F0-9]{3,6}/ig) ) return '';
|
743
|
+
if( string.length !== 3 && string.length !== 6 ) return '';
|
744
|
+
if( string.length === 3 && expand ) {
|
745
|
+
string = string[0] + string[0] + string[1] + string[1] + string[2] + string[2];
|
746
|
+
}
|
747
|
+
return '#' + string;
|
748
|
+
}
|
749
|
+
|
750
|
+
// Parses a string and returns a valid RGB(A) string when possible
|
751
|
+
function parseRgb(string, obj) {
|
752
|
+
|
753
|
+
var values = string.replace(/[^\d,.]/g, ''),
|
754
|
+
rgba = values.split(','),
|
755
|
+
output;
|
756
|
+
|
757
|
+
rgba[0] = keepWithin(parseInt(rgba[0], 10), 0, 255);
|
758
|
+
rgba[1] = keepWithin(parseInt(rgba[1], 10), 0, 255);
|
759
|
+
rgba[2] = keepWithin(parseInt(rgba[2], 10), 0, 255);
|
760
|
+
if( rgba[3] ) {
|
761
|
+
rgba[3] = keepWithin(parseFloat(rgba[3], 10), 0, 1);
|
762
|
+
}
|
763
|
+
|
764
|
+
// Return RGBA object
|
765
|
+
if( obj ) {
|
766
|
+
return {
|
767
|
+
r: rgba[0],
|
768
|
+
g: rgba[1],
|
769
|
+
b: rgba[2],
|
770
|
+
a: rgba[3] ? rgba[3] : null
|
771
|
+
};
|
772
|
+
}
|
773
|
+
|
774
|
+
// Return RGBA string
|
775
|
+
if( typeof(rgba[3]) !== 'undefined' && rgba[3] <= 1 ) {
|
776
|
+
return 'rgba(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ', ' + rgba[3] + ')';
|
777
|
+
} else {
|
778
|
+
return 'rgb(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ')';
|
779
|
+
}
|
780
|
+
|
781
|
+
}
|
782
|
+
|
783
|
+
// Parses a string and returns a valid color string when possible
|
784
|
+
function parseInput(string, expand) {
|
785
|
+
if( isRgb(string) ) {
|
786
|
+
// Returns a valid rgb(a) string
|
787
|
+
return parseRgb(string);
|
788
|
+
} else {
|
789
|
+
return parseHex(string, expand);
|
790
|
+
}
|
791
|
+
}
|
792
|
+
|
793
|
+
// Keeps value within min and max
|
794
|
+
function keepWithin(value, min, max) {
|
795
|
+
if( value < min ) value = min;
|
796
|
+
if( value > max ) value = max;
|
797
|
+
return value;
|
798
|
+
}
|
799
|
+
|
800
|
+
// Checks if a string is a valid RGB(A) string
|
801
|
+
function isRgb(string) {
|
802
|
+
var rgb = string.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
|
803
|
+
return (rgb && rgb.length === 4) ? true : false;
|
804
|
+
}
|
805
|
+
|
806
|
+
// Function to get alpha from a RGB(A) string
|
807
|
+
function getAlpha(rgba) {
|
808
|
+
var rgba = rgba.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+(\.\d{1,2})?|\.\d{1,2})[\s+]?/i);
|
809
|
+
return (rgba && rgba.length === 6) ? rgba[4] : '1';
|
810
|
+
}
|
811
|
+
|
812
|
+
// Converts an HSB object to an RGB object
|
813
|
+
function hsb2rgb(hsb) {
|
814
|
+
var rgb = {};
|
815
|
+
var h = Math.round(hsb.h);
|
816
|
+
var s = Math.round(hsb.s * 255 / 100);
|
817
|
+
var v = Math.round(hsb.b * 255 / 100);
|
818
|
+
if(s === 0) {
|
819
|
+
rgb.r = rgb.g = rgb.b = v;
|
820
|
+
} else {
|
821
|
+
var t1 = v;
|
822
|
+
var t2 = (255 - s) * v / 255;
|
823
|
+
var t3 = (t1 - t2) * (h % 60) / 60;
|
824
|
+
if( h === 360 ) h = 0;
|
825
|
+
if( h < 60 ) { rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3; }
|
826
|
+
else if( h < 120 ) {rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3; }
|
827
|
+
else if( h < 180 ) {rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3; }
|
828
|
+
else if( h < 240 ) {rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3; }
|
829
|
+
else if( h < 300 ) {rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3; }
|
830
|
+
else if( h < 360 ) {rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3; }
|
831
|
+
else { rgb.r = 0; rgb.g = 0; rgb.b = 0; }
|
832
|
+
}
|
833
|
+
return {
|
834
|
+
r: Math.round(rgb.r),
|
835
|
+
g: Math.round(rgb.g),
|
836
|
+
b: Math.round(rgb.b)
|
837
|
+
};
|
838
|
+
}
|
839
|
+
|
840
|
+
// Converts an RGB string to a hex string
|
841
|
+
function rgbString2hex(rgb){
|
842
|
+
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
|
843
|
+
return (rgb && rgb.length === 4) ? '#' +
|
844
|
+
('0' + parseInt(rgb[1],10).toString(16)).slice(-2) +
|
845
|
+
('0' + parseInt(rgb[2],10).toString(16)).slice(-2) +
|
846
|
+
('0' + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
|
847
|
+
}
|
848
|
+
|
849
|
+
// Converts an RGB object to a hex string
|
850
|
+
function rgb2hex(rgb) {
|
851
|
+
var hex = [
|
852
|
+
rgb.r.toString(16),
|
853
|
+
rgb.g.toString(16),
|
854
|
+
rgb.b.toString(16)
|
855
|
+
];
|
856
|
+
$.each(hex, function(nr, val) {
|
857
|
+
if (val.length === 1) hex[nr] = '0' + val;
|
858
|
+
});
|
859
|
+
return '#' + hex.join('');
|
860
|
+
}
|
861
|
+
|
862
|
+
// Converts an HSB object to a hex string
|
863
|
+
function hsb2hex(hsb) {
|
864
|
+
return rgb2hex(hsb2rgb(hsb));
|
865
|
+
}
|
866
|
+
|
867
|
+
// Converts a hex string to an HSB object
|
868
|
+
function hex2hsb(hex) {
|
869
|
+
var hsb = rgb2hsb(hex2rgb(hex));
|
870
|
+
if( hsb.s === 0 ) hsb.h = 360;
|
871
|
+
return hsb;
|
872
|
+
}
|
873
|
+
|
874
|
+
// Converts an RGB object to an HSB object
|
875
|
+
function rgb2hsb(rgb) {
|
876
|
+
var hsb = { h: 0, s: 0, b: 0 };
|
877
|
+
var min = Math.min(rgb.r, rgb.g, rgb.b);
|
878
|
+
var max = Math.max(rgb.r, rgb.g, rgb.b);
|
879
|
+
var delta = max - min;
|
880
|
+
hsb.b = max;
|
881
|
+
hsb.s = max !== 0 ? 255 * delta / max : 0;
|
882
|
+
if( hsb.s !== 0 ) {
|
883
|
+
if( rgb.r === max ) {
|
884
|
+
hsb.h = (rgb.g - rgb.b) / delta;
|
885
|
+
} else if( rgb.g === max ) {
|
886
|
+
hsb.h = 2 + (rgb.b - rgb.r) / delta;
|
887
|
+
} else {
|
888
|
+
hsb.h = 4 + (rgb.r - rgb.g) / delta;
|
889
|
+
}
|
890
|
+
} else {
|
891
|
+
hsb.h = -1;
|
892
|
+
}
|
893
|
+
hsb.h *= 60;
|
894
|
+
if( hsb.h < 0 ) {
|
895
|
+
hsb.h += 360;
|
896
|
+
}
|
897
|
+
hsb.s *= 100/255;
|
898
|
+
hsb.b *= 100/255;
|
899
|
+
return hsb;
|
900
|
+
}
|
901
|
+
|
902
|
+
// Converts a hex string to an RGB object
|
903
|
+
function hex2rgb(hex) {
|
904
|
+
hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
|
905
|
+
return {
|
906
|
+
/* jshint ignore:start */
|
907
|
+
r: hex >> 16,
|
908
|
+
g: (hex & 0x00FF00) >> 8,
|
909
|
+
b: (hex & 0x0000FF)
|
910
|
+
/* jshint ignore:end */
|
911
|
+
};
|
912
|
+
}
|
913
|
+
|
914
|
+
// Handle events
|
915
|
+
$(document)
|
916
|
+
// Hide on clicks outside of the control
|
917
|
+
.on('mousedown.minicolors touchstart.minicolors', function(event) {
|
918
|
+
if( !$(event.target).parents().add(event.target).hasClass('minicolors') ) {
|
919
|
+
hide();
|
920
|
+
}
|
921
|
+
})
|
922
|
+
// Start moving
|
923
|
+
.on('mousedown.minicolors touchstart.minicolors', '.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider', function(event) {
|
924
|
+
var target = $(this);
|
925
|
+
event.preventDefault();
|
926
|
+
$(document).data('minicolors-target', target);
|
927
|
+
move(target, event, true);
|
928
|
+
})
|
929
|
+
// Move pickers
|
930
|
+
.on('mousemove.minicolors touchmove.minicolors', function(event) {
|
931
|
+
var target = $(document).data('minicolors-target');
|
932
|
+
if( target ) move(target, event);
|
933
|
+
})
|
934
|
+
// Stop moving
|
935
|
+
.on('mouseup.minicolors touchend.minicolors', function() {
|
936
|
+
$(this).removeData('minicolors-target');
|
937
|
+
})
|
938
|
+
// Show panel when swatch is clicked
|
939
|
+
.on('mousedown.minicolors touchstart.minicolors', '.minicolors-swatch', function(event) {
|
940
|
+
var input = $(this).parent().find('.minicolors-input');
|
941
|
+
event.preventDefault();
|
942
|
+
show(input);
|
943
|
+
})
|
944
|
+
// Show on focus
|
945
|
+
.on('focus.minicolors', '.minicolors-input', function() {
|
946
|
+
var input = $(this);
|
947
|
+
if( !input.data('minicolors-initialized') ) return;
|
948
|
+
show(input);
|
949
|
+
})
|
950
|
+
// Update value on blur
|
951
|
+
.on('blur.minicolors', '.minicolors-input', function() {
|
952
|
+
var input = $(this),
|
953
|
+
settings = input.data('minicolors-settings'),
|
954
|
+
keywords,
|
955
|
+
hex,
|
956
|
+
rgba,
|
957
|
+
swatchOpacity,
|
958
|
+
value;
|
959
|
+
|
960
|
+
if( !input.data('minicolors-initialized') ) return;
|
961
|
+
|
962
|
+
// Get array of lowercase keywords
|
963
|
+
keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
|
964
|
+
return $.trim(a.toLowerCase());
|
965
|
+
});
|
966
|
+
|
967
|
+
// Set color string
|
968
|
+
if( input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1 ) {
|
969
|
+
value = input.val();
|
970
|
+
} else {
|
971
|
+
// Get RGBA values for easy conversion
|
972
|
+
if( isRgb(input.val()) ) {
|
973
|
+
rgba = parseRgb(input.val(), true);
|
974
|
+
} else {
|
975
|
+
hex = parseHex(input.val(), true);
|
976
|
+
rgba = hex ? hex2rgb(hex) : null;
|
977
|
+
}
|
978
|
+
|
979
|
+
// Convert to format
|
980
|
+
if( rgba === null ) {
|
981
|
+
value = settings.defaultValue;
|
982
|
+
} else if( settings.format === 'rgb' ) {
|
983
|
+
value = settings.opacity ?
|
984
|
+
parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
|
985
|
+
parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
|
986
|
+
} else {
|
987
|
+
value = rgb2hex(rgba);
|
988
|
+
}
|
989
|
+
}
|
990
|
+
|
991
|
+
// Update swatch opacity
|
992
|
+
swatchOpacity = settings.opacity ? input.attr('data-opacity') : 1;
|
993
|
+
if( value.toLowerCase() === 'transparent' ) swatchOpacity = 0;
|
994
|
+
input
|
995
|
+
.closest('.minicolors')
|
996
|
+
.find('.minicolors-swatch > span')
|
997
|
+
.css('opacity', swatchOpacity);
|
998
|
+
|
999
|
+
// Set input value
|
1000
|
+
input.val(value);
|
1001
|
+
|
1002
|
+
// Is it blank?
|
1003
|
+
if( input.val() === '' ) input.val(parseInput(settings.defaultValue, true));
|
1004
|
+
|
1005
|
+
// Adjust case
|
1006
|
+
input.val( convertCase(input.val(), settings.letterCase) );
|
1007
|
+
|
1008
|
+
})
|
1009
|
+
// Handle keypresses
|
1010
|
+
.on('keydown.minicolors', '.minicolors-input', function(event) {
|
1011
|
+
var input = $(this);
|
1012
|
+
if( !input.data('minicolors-initialized') ) return;
|
1013
|
+
switch(event.keyCode) {
|
1014
|
+
case 9: // tab
|
1015
|
+
hide();
|
1016
|
+
break;
|
1017
|
+
case 13: // enter
|
1018
|
+
case 27: // esc
|
1019
|
+
hide();
|
1020
|
+
input.blur();
|
1021
|
+
break;
|
1022
|
+
}
|
1023
|
+
})
|
1024
|
+
// Update on keyup
|
1025
|
+
.on('keyup.minicolors', '.minicolors-input', function() {
|
1026
|
+
var input = $(this);
|
1027
|
+
if( !input.data('minicolors-initialized') ) return;
|
1028
|
+
updateFromInput(input, true);
|
1029
|
+
})
|
1030
|
+
// Update on paste
|
1031
|
+
.on('paste.minicolors', '.minicolors-input', function() {
|
1032
|
+
var input = $(this);
|
1033
|
+
if( !input.data('minicolors-initialized') ) return;
|
1034
|
+
setTimeout( function() {
|
1035
|
+
updateFromInput(input, true);
|
1036
|
+
}, 1);
|
1037
|
+
});
|
1038
|
+
|
1039
|
+
}));
|