├── .gitignore
├── LICENSE.txt
├── README.md
├── bower.json
├── demo.html
├── jquery-simplecolorpicker-inline.png
├── jquery-simplecolorpicker-picker.png
├── jquery.simplecolorpicker-fontawesome.css
├── jquery.simplecolorpicker-glyphicons.css
├── jquery.simplecolorpicker-regularfont.css
├── jquery.simplecolorpicker.css
├── jquery.simplecolorpicker.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012-2013 Tanguy Krotoff
2 |
3 | MIT License
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **I don't use jquery-simplecolorpicker anymore so I won't update this repository. If you have a well maintained fork, I will be happy to promote it here.**
2 |
3 | # Very simple jQuery color picker
4 |
5 | Yet another jQuery color picker. This plugin is unobtrusive and integrates well with Twitter Bootstrap (it works just fine without).
6 | The source code only requires jQuery and is about 200 lines of JavaScript and 100 lines of CSS.
7 |
8 | See the [online demo](http://plnkr.co/edit/VVclW0?p=preview).
9 |
10 | 
11 |
12 | 
13 |
14 | ## npm
15 |
16 | ```
17 | npm install jquery-simplecolorpicker
18 | ```
19 |
20 | ## Bower
21 |
22 | ```
23 | bower install jquery-simplecolorpicker
24 | ```
25 |
26 | ## How to use
27 |
28 | Create a HTML select:
29 |
30 | ```HTML
31 |
32 | Green
33 | Bold blue
34 | Blue
35 | Turquoise
36 | Light green
37 | Bold green
38 | Yellow
39 | Orange
40 | Red
41 | Bold red
42 | Purple
43 | Gray
44 |
45 | ```
46 |
47 | add the plugin files:
48 |
49 | ```HTML
50 |
51 |
52 |
53 |
54 | ```
55 |
56 | then call the plugin:
57 |
58 | ```JavaScript
59 | $('select[name="colorpicker"]').simplecolorpicker();
60 | $('select[name="colorpicker"]').simplecolorpicker('selectColor', '#7bd148');
61 | $('select[name="colorpicker"]').simplecolorpicker('destroy');
62 | ```
63 |
64 | and pass some options if needed:
65 |
66 | ```JavaScript
67 | $('select[name="colorpicker"]').simplecolorpicker({
68 | picker: true
69 | }).on('change', function() {
70 | $(document.body).css('background-color', $('select[name="colorpicker"]').val());
71 | });
72 | ```
73 |
74 | ### Options
75 |
76 | - theme: font to use for the ok/check mark (default: `''`), available themes: [`regularfont`](https://github.com/tkrotoff/jquery-simplecolorpicker/blob/master/jquery.simplecolorpicker-regularfont.css), [`fontawesome`](https://github.com/tkrotoff/jquery-simplecolorpicker/blob/master/jquery.simplecolorpicker-fontawesome.css), [`glyphicons`](https://github.com/tkrotoff/jquery-simplecolorpicker/blob/master/jquery.simplecolorpicker-glyphicons.css)
77 | - picker: show the colors inside a picker instead of inline (default: `false`)
78 | - pickerDelay: show and hide animation delay in milliseconds (default: `0`)
79 |
80 | ## Browser support
81 |
82 | Simplecolorpicker supports all modern browsers starting with Internet Explorer 8 included.
83 | It is recommended to not use any font theme with IE8.
84 |
85 | ## HTML5 new color input
86 |
87 | HTML5 provides a new input to select colors. Its implementation inside modern browsers is still lacking.
88 | The new color input does not provide any option to customize the color list and
89 | most of the time the widget is less user-friendly than the one provided by simplecolorpicker.
90 |
91 | See http://slides.html5rocks.com/#new-form-types
92 |
93 | See http://dev.w3.org/html5/markup/input.color.html#input.color
94 |
95 | ## AngularJS directive
96 |
97 | See [simplecolorpicker directive](http://plnkr.co/edit/rKM3QWXDC3vGVPe3QFWV?p=preview).
98 | If you find a solution for the `setTimeout()` hack, please tell me.
99 |
100 | Here [another directive](http://plnkr.co/edit/zlP0RSH3m0ghsefHeaLI?p=preview) written by [KGZM](https://github.com/KGZM) that re-implements simplecolorpicker.
101 | For the explanations, read this [Google Groups discussion](https://groups.google.com/d/topic/angular/nBZsvLOZxvI/discussion).
102 |
103 | ## Ruby on Rails
104 |
105 | A gem is available at https://github.com/tkrotoff/jquery-simplecolorpicker-rails
106 |
107 | ## Copyright and license
108 |
109 | Licensed under the MIT license.
110 | Copyright (C) 2012-2013 Tanguy Krotoff
111 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-simplecolorpicker",
3 | "version": "0.3.1",
4 | "dependencies": {
5 | "jquery": ">=1.10"
6 | },
7 | "repository": {
8 | "type": "git",
9 | "url": "git://github.com/tkrotoff/jquery-simplecolorpicker.git"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Color picker for jQuery
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | Init the jQuery plugin
20 |
21 |
22 | Destroy the jQuery plugin
23 |
24 |
25 |
26 | Short list of colors
27 | colorpicker-shortlist:
28 |
29 | Green
30 | Bold blue
31 | Blue
32 | Turquoise
33 | Light green
34 | Bold green
35 | Yellow
36 | Orange
37 | Red
38 | Bold red
39 | Purple
40 | Gray
41 |
42 |
43 | Long list of colors
44 | colorpicker-longlist:
45 |
46 | #ac725e
47 | #d06b64
48 | #f83a22
49 | #fa573c
50 | #ff7537
51 | #ffad46
52 | #42d692
53 | #16a765
54 | #7bd148
55 | #b3dc6c
56 | #fbe983
57 | #fad165
58 | #92e1c0
59 | #9fe1e7
60 | #9fc6e7
61 | #4986e7
62 | #9a9cff
63 | #b99aff
64 | #c2c2c2
65 | #cabdbf
66 | #cca6ac
67 | #f691b2
68 | #cd74e6
69 | #a47ae2
70 |
71 |
72 | No theme
73 | colorpicker-notheme:
74 |
75 | Green
76 | Bold blue
77 | Blue
78 | Turquoise
79 | Light green
80 | Bold green
81 | Yellow
82 | Orange
83 | Red
84 | Bold red
85 | Purple
86 | Gray
87 |
88 |
89 | 'regularfont' theme
90 | colorpicker-regularfont:
91 |
92 | Green
93 | Bold blue
94 | Blue
95 | Turquoise
96 | Light green
97 | Bold green
98 | Yellow
99 | Orange
100 | Red
101 | Bold red
102 | Purple
103 | Gray
104 |
105 |
106 | 'glyphicons' theme
107 | colorpicker-glyphicons:
108 |
109 | Green
110 | Bold blue
111 | Blue
112 | Turquoise
113 | Light green
114 | Bold green
115 | Yellow
116 | Orange
117 | Red
118 | Bold red
119 | Purple
120 | Gray
121 |
122 |
123 | 'fontawesome' theme
124 | colorpicker-fontawesome:
125 |
126 | Green
127 | Bold blue
128 | Blue
129 | Turquoise
130 | Light green
131 | Bold green
132 | Yellow
133 | Orange
134 | Red
135 | Bold red
136 | Purple
137 | Gray
138 |
139 |
140 | Bootstrap 3 form
141 |
201 |
202 | Bootstrap 3 modal window
203 | Launch demo modal
204 |
205 |
206 |
207 |
211 |
212 | colorpicker-modal-inline:
213 |
214 | Green
215 | Bold blue
216 | Blue
217 | Turquoise
218 | Light green
219 | Bold green
220 | Yellow
221 | Orange
222 | Red
223 | Bold red
224 | Purple
225 | Gray
226 |
227 |
228 | colorpicker-modal-picker:
229 |
230 | Green
231 | Bold blue
232 | Blue
233 | Turquoise
234 | Light green
235 | Bold green
236 | Yellow
237 | Orange
238 | Red
239 | Bold red
240 | Purple
241 | Gray
242 |
243 |
244 |
248 |
249 |
250 |
251 |
252 | Option selected
253 | colorpicker-option-selected:
254 |
255 | Green
256 | Bold blue
257 | Blue
258 | Turquoise
259 | Light green
260 | Bold green
261 | Yellow
262 | Orange
263 | Red
264 | Bold red
265 | Purple
266 | Gray
267 |
268 |
269 | Options disabled
270 | colorpicker-options-disabled:
271 |
272 | Green
273 | Bold blue
274 | Blue
275 | Turquoise
276 | Light green
277 | Bold green
278 | Yellow
279 | Orange
280 | Red
281 | Bold red
282 | Purple
283 | Gray
284 |
285 |
286 | Option selected and disabled at the same time
287 | colorpicker-option-selected-disabled:
288 |
289 | Green
290 | Bold blue
291 | Blue
292 | Turquoise
293 | Light green
294 | Bold green
295 | Yellow
296 | Orange
297 | Red
298 | Bold red
299 | Purple
300 | Gray
301 |
302 |
303 | Optgroups
304 | colorpicker-optgroups:
305 |
306 | Green
307 | Bold blue
308 |
309 | Blue
310 | Turquoise
311 | Light green
312 | Bold green
313 | Yellow
314 | Orange
315 | Red
316 | Bold red
317 |
318 | Purple
319 | Gray
320 |
321 |
322 | Change background color
323 | colorpicker-change-background-color:
324 |
325 | Green
326 | Bold blue
327 | Blue
328 | Turquoise
329 | Light green
330 | Bold green
331 | Yellow
332 | Orange
333 | Red
334 | Bold red
335 | Purple
336 | Gray
337 |
338 |
339 | selectColor('#fbd75b') after 5 seconds
340 | colorpicker-selectColor-#fbd75b:
341 |
342 | Green
343 | Bold blue
344 | Blue
345 | Turquoise
346 | Light green
347 | Bold green
348 | Yellow
349 | Orange
350 | Red
351 | Bold red
352 | Purple
353 | Gray
354 |
355 |
356 | selectColor('#FBD75B') after 5 seconds
357 | colorpicker-selectColor-#FBD75B:
358 |
359 | Green
360 | Bold blue
361 | Blue
362 | Turquoise
363 | Light green
364 | Bold green
365 | Yellow
366 | Orange
367 | Red
368 | Bold red
369 | Purple
370 | Gray
371 |
372 |
373 | Multiple selectColor('#fbd75b') after 5 seconds
374 | colorpicker-selectColor-#fbd75b-multiple:
375 |
376 | Green
377 | Bold blue
378 | Blue
379 | Turquoise
380 | Light green
381 | Bold green
382 | Yellow
383 | Yellow
384 | Yellow
385 | Orange
386 | Red
387 | Bold red
388 | Purple
389 | Gray
390 |
391 |
392 | selectColor('unknown') after 5 seconds
393 | colorpicker-selectColor-unknown:
394 |
395 | Green
396 | Bold blue
397 | Blue
398 | Turquoise
399 | Light green
400 | Bold green
401 | Yellow
402 | Orange
403 | Red
404 | Bold red
405 | Purple
406 | Gray
407 |
408 |
409 | Picker short list
410 | colorpicker-picker-shortlist:
411 |
412 | Green
413 | Bold blue
414 | Blue
415 | Turquoise
416 | Light green
417 | Bold green
418 | Yellow
419 | Orange
420 | Red
421 | Bold red
422 | Purple
423 | Gray
424 |
425 |
426 | Picker long list
427 | colorpicker-picker-longlist:
428 |
429 | #ac725e
430 | #d06b64
431 | #f83a22
432 | #fa573c
433 | #ff7537
434 | #ffad46
435 | #42d692
436 | #16a765
437 | #7bd148
438 | #b3dc6c
439 | #fbe983
440 | #fad165
441 | #92e1c0
442 | #9fe1e7
443 | #9fc6e7
444 | #4986e7
445 | #9a9cff
446 | #b99aff
447 | #c2c2c2
448 | #cabdbf
449 | #cca6ac
450 | #f691b2
451 | #cd74e6
452 | #a47ae2
453 |
454 |
455 | Picker with 1s animation delay
456 | colorpicker-picker-delay:
457 |
458 | Green
459 | Bold blue
460 | Blue
461 | Turquoise
462 | Light green
463 | Bold green
464 | Yellow
465 | Orange
466 | Red
467 | Bold red
468 | Purple
469 | Gray
470 |
471 |
472 | Picker with option selected
473 | colorpicker-picker-option-selected:
474 |
475 | Green
476 | Bold blue
477 | Blue
478 | Turquoise
479 | Light green
480 | Bold green
481 | Yellow
482 | Orange
483 | Red
484 | Bold red
485 | Purple
486 | Gray
487 |
488 |
489 | Picker with options disabled
490 | colorpicker-picker-options-disabled:
491 |
492 | Green
493 | Bold blue
494 | Blue
495 | Turquoise
496 | Light green
497 | Bold green
498 | Yellow
499 | Orange
500 | Red
501 | Bold red
502 | Purple
503 | Gray
504 |
505 |
506 | Picker with option selected and disabled at the same time
507 | colorpicker-picker-option-selected-disabled:
508 |
509 | Green
510 | Bold blue
511 | Blue
512 | Turquoise
513 | Light green
514 | Bold green
515 | Yellow
516 | Orange
517 | Red
518 | Bold red
519 | Purple
520 | Gray
521 |
522 |
523 | Picker with Optgroups
524 | colorpicker-picker-optgroups:
525 |
526 | Green
527 | Bold blue
528 |
529 | Blue
530 | Turquoise
531 | Light green
532 | Bold green
533 | Yellow
534 | Orange
535 | Red
536 | Bold red
537 |
538 | Purple
539 | Gray
540 |
541 |
542 | Picker with selectColor('#fbd75b') after 5 seconds
543 | colorpicker-picker-selectColor-#fbd75b:
544 |
545 | Green
546 | Bold blue
547 | Blue
548 | Turquoise
549 | Light green
550 | Bold green
551 | Yellow
552 | Orange
553 | Red
554 | Bold red
555 | Purple
556 | Gray
557 |
558 |
559 | Picker with selectColor('unknown') after 5 seconds
560 | colorpicker-picker-selectColor-unknown:
561 |
562 | Green
563 | Bold blue
564 | Blue
565 | Turquoise
566 | Light green
567 | Bold green
568 | Yellow
569 | Orange
570 | Red
571 | Bold red
572 | Purple
573 | Gray
574 |
575 |
576 |
577 |
578 |
579 |
580 |
653 |
654 |
655 |
656 |
--------------------------------------------------------------------------------
/jquery-simplecolorpicker-inline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkrotoff/jquery-simplecolorpicker/81b652ac5ff40065a2f4bb50392d727d69a23af0/jquery-simplecolorpicker-inline.png
--------------------------------------------------------------------------------
/jquery-simplecolorpicker-picker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkrotoff/jquery-simplecolorpicker/81b652ac5ff40065a2f4bb50392d727d69a23af0/jquery-simplecolorpicker-picker.png
--------------------------------------------------------------------------------
/jquery.simplecolorpicker-fontawesome.css:
--------------------------------------------------------------------------------
1 | .simplecolorpicker.fontawesome span.color[data-selected]:after {
2 | font-family: 'FontAwesome';
3 | -webkit-font-smoothing: antialiased;
4 |
5 | content: '\f00c'; /* Ok/check mark */
6 |
7 | margin-right: 1px;
8 | margin-left: 1px;
9 | }
10 |
--------------------------------------------------------------------------------
/jquery.simplecolorpicker-glyphicons.css:
--------------------------------------------------------------------------------
1 | .simplecolorpicker.glyphicons span.color[data-selected]:after {
2 | /* Taken from glyphicon class. */
3 | position: relative;
4 | top: 1px;
5 | font-family: 'Glyphicons Halflings';
6 | line-height: .9;
7 | -webkit-font-smoothing: antialiased;
8 |
9 | content: '\e013'; /* Ok/check mark */
10 |
11 | margin-right: 1px;
12 | margin-left: 1px;
13 | }
14 |
--------------------------------------------------------------------------------
/jquery.simplecolorpicker-regularfont.css:
--------------------------------------------------------------------------------
1 | .simplecolorpicker.regularfont span.color[data-selected]:after {
2 | content: '\2714'; /* Ok/check mark */
3 |
4 | margin-right: 2.2px;
5 | margin-left: 2.2px;
6 | }
7 |
--------------------------------------------------------------------------------
/jquery.simplecolorpicker.css:
--------------------------------------------------------------------------------
1 | /*!
2 | * Very simple jQuery Color Picker
3 | * https://github.com/tkrotoff/jquery-simplecolorpicker
4 | *
5 | * Copyright (C) 2012-2013 Tanguy Krotoff
6 | *
7 | * Licensed under the MIT license
8 | */
9 |
10 | /**
11 | * Inspired by Bootstrap Twitter.
12 | * See https://github.com/twbs/bootstrap/blob/master/less/navbar.less
13 | * See https://github.com/twbs/bootstrap/blob/master/less/dropdowns.less
14 | */
15 |
16 | .simplecolorpicker.picker {
17 | position: absolute;
18 | top: 100%;
19 | left: 0;
20 | z-index: 1051; /* Above Bootstrap modal (@zindex-modal = 1050) */
21 | display: none;
22 | float: left;
23 |
24 | min-width: 160px;
25 | max-width: 283px; /* @popover-max-width = 276px + 7 */
26 |
27 | padding: 5px 0 0 5px;
28 | margin: 2px 0 0;
29 | list-style: none;
30 | background-color: #fff; /* @dropdown-bg */
31 |
32 | border: 1px solid #ccc; /* @dropdown-fallback-border */
33 | border: 1px solid rgba(0, 0, 0, .15); /* @dropdown-border */
34 |
35 | -webkit-border-radius: 4px; /* @border-radius-base */
36 | -moz-border-radius: 4px;
37 | border-radius: 4px;
38 |
39 | -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
40 | -moz-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
41 | box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
42 |
43 | -webkit-background-clip: padding-box;
44 | -moz-background-clip: padding;
45 | background-clip: padding-box;
46 | }
47 |
48 | .simplecolorpicker.inline {
49 | display: inline-block;
50 | padding: 6px 0;
51 | }
52 |
53 | .simplecolorpicker span {
54 | margin: 0 5px 5px 0;
55 | }
56 |
57 | .simplecolorpicker.icon,
58 | .simplecolorpicker span.color {
59 | display: inline-block;
60 |
61 | cursor: pointer;
62 | border: 1px solid transparent;
63 | }
64 |
65 | .simplecolorpicker.icon:after,
66 | .simplecolorpicker span.color:after {
67 | content: '\00a0\00a0\00a0\00a0'; /* Spaces */
68 | }
69 |
70 | .simplecolorpicker span.color[data-disabled]:hover {
71 | cursor: not-allowed;
72 | border: 1px solid transparent;
73 | }
74 |
75 | .simplecolorpicker span.color:hover,
76 | .simplecolorpicker span.color[data-selected],
77 | .simplecolorpicker span.color[data-selected]:hover {
78 | border: 1px solid #222; /* @gray-dark */
79 | }
80 | .simplecolorpicker span.color[data-selected]:after {
81 | color: #fff;
82 | }
83 |
84 | /* Vertical separator, replaces optgroup. */
85 | .simplecolorpicker span.vr {
86 | border-left: 1px solid #222; /* @gray-dark */
87 | }
88 |
--------------------------------------------------------------------------------
/jquery.simplecolorpicker.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * Very simple jQuery Color Picker
3 | * https://github.com/tkrotoff/jquery-simplecolorpicker
4 | *
5 | * Copyright (C) 2012-2013 Tanguy Krotoff
6 | *
7 | * Licensed under the MIT license
8 | */
9 |
10 | (function($) {
11 | 'use strict';
12 |
13 | /**
14 | * Constructor.
15 | */
16 | var SimpleColorPicker = function(select, options) {
17 | this.init('simplecolorpicker', select, options);
18 | };
19 |
20 | /**
21 | * SimpleColorPicker class.
22 | */
23 | SimpleColorPicker.prototype = {
24 | constructor: SimpleColorPicker,
25 |
26 | init: function(type, select, options) {
27 | var self = this;
28 |
29 | self.type = type;
30 |
31 | self.$select = $(select);
32 | self.$select.hide();
33 |
34 | self.options = $.extend({}, $.fn.simplecolorpicker.defaults, options);
35 |
36 | self.$colorList = null;
37 |
38 | if (self.options.picker === true) {
39 | var selectText = self.$select.find('> option:selected').text();
40 | self.$icon = $(''
44 | + ' ').insertAfter(self.$select);
45 | self.$icon.on('click.' + self.type, $.proxy(self.showPicker, self));
46 |
47 | self.$picker = $(' ').appendTo(document.body);
48 | self.$colorList = self.$picker;
49 |
50 | // Hide picker when clicking outside
51 | $(document).on('mousedown.' + self.type, $.proxy(self.hidePicker, self));
52 | self.$picker.on('mousedown.' + self.type, $.proxy(self.mousedown, self));
53 | } else {
54 | self.$inline = $(' ').insertAfter(self.$select);
55 | self.$colorList = self.$inline;
56 | }
57 |
58 | // Build the list of colors
59 | //
60 | self.$select.find('> option').each(function() {
61 | var $option = $(this);
62 | var color = $option.val();
63 |
64 | var isSelected = $option.is(':selected');
65 | var isDisabled = $option.is(':disabled');
66 |
67 | var selected = '';
68 | if (isSelected === true) {
69 | selected = ' data-selected';
70 | }
71 |
72 | var disabled = '';
73 | if (isDisabled === true) {
74 | disabled = ' data-disabled';
75 | }
76 |
77 | var title = '';
78 | if (isDisabled === false) {
79 | title = ' title="' + $option.text() + '"';
80 | }
81 |
82 | var role = '';
83 | if (isDisabled === false) {
84 | role = ' role="button" tabindex="0"';
85 | }
86 |
87 | var $colorSpan = $(''
94 | + ' ');
95 |
96 | self.$colorList.append($colorSpan);
97 | $colorSpan.on('click.' + self.type, $.proxy(self.colorSpanClicked, self));
98 |
99 | var $next = $option.next();
100 | if ($next.is('optgroup') === true) {
101 | // Vertical break, like hr
102 | self.$colorList.append(' ');
103 | }
104 | });
105 | },
106 |
107 | /**
108 | * Changes the selected color.
109 | *
110 | * @param color the hexadecimal color to select, ex: '#fbd75b'
111 | */
112 | selectColor: function(color) {
113 | var self = this;
114 |
115 | var $colorSpan = self.$colorList.find('> span.color').filter(function() {
116 | return $(this).data('color').toLowerCase() === color.toLowerCase();
117 | });
118 |
119 | if ($colorSpan.length > 0) {
120 | self.selectColorSpan($colorSpan);
121 | } else {
122 | console.error("The given color '" + color + "' could not be found");
123 | }
124 | },
125 |
126 | showPicker: function() {
127 | var pos = this.$icon.offset();
128 | this.$picker.css({
129 | // Remove some pixels to align the picker icon with the icons inside the dropdown
130 | left: pos.left - 6,
131 | top: pos.top + this.$icon.outerHeight()
132 | });
133 |
134 | this.$picker.show(this.options.pickerDelay);
135 | },
136 |
137 | hidePicker: function() {
138 | this.$picker.hide(this.options.pickerDelay);
139 | },
140 |
141 | /**
142 | * Selects the given span inside $colorList.
143 | *
144 | * The given span becomes the selected one.
145 | * It also changes the HTML select value, this will emit the 'change' event.
146 | */
147 | selectColorSpan: function($colorSpan) {
148 | var color = $colorSpan.data('color');
149 | var title = $colorSpan.prop('title');
150 |
151 | // Mark this span as the selected one
152 | $colorSpan.siblings().removeAttr('data-selected');
153 | $colorSpan.attr('data-selected', '');
154 |
155 | if (this.options.picker === true) {
156 | this.$icon.css('background-color', color);
157 | this.$icon.prop('title', title);
158 | this.hidePicker();
159 | }
160 |
161 | // Change HTML select value
162 | this.$select.val(color);
163 | },
164 |
165 | /**
166 | * The user clicked on a color inside $colorList.
167 | */
168 | colorSpanClicked: function(e) {
169 | // When a color is clicked, make it the new selected one (unless disabled)
170 | if ($(e.target).is('[data-disabled]') === false) {
171 | this.selectColorSpan($(e.target));
172 | this.$select.trigger('change');
173 | }
174 | },
175 |
176 | /**
177 | * Prevents the mousedown event from "eating" the click event.
178 | */
179 | mousedown: function(e) {
180 | e.stopPropagation();
181 | e.preventDefault();
182 | },
183 |
184 | destroy: function() {
185 | if (this.options.picker === true) {
186 | this.$icon.off('.' + this.type);
187 | this.$icon.remove();
188 | $(document).off('.' + this.type);
189 | }
190 |
191 | this.$colorList.off('.' + this.type);
192 | this.$colorList.remove();
193 |
194 | this.$select.removeData(this.type);
195 | this.$select.show();
196 | }
197 | };
198 |
199 | /**
200 | * Plugin definition.
201 | * How to use: $('#id').simplecolorpicker()
202 | */
203 | $.fn.simplecolorpicker = function(option) {
204 | var args = $.makeArray(arguments);
205 | args.shift();
206 |
207 | // For HTML element passed to the plugin
208 | return this.each(function() {
209 | var $this = $(this),
210 | data = $this.data('simplecolorpicker'),
211 | options = typeof option === 'object' && option;
212 | if (data === undefined) {
213 | $this.data('simplecolorpicker', (data = new SimpleColorPicker(this, options)));
214 | }
215 | if (typeof option === 'string') {
216 | data[option].apply(data, args);
217 | }
218 | });
219 | };
220 |
221 | /**
222 | * Default options.
223 | */
224 | $.fn.simplecolorpicker.defaults = {
225 | // No theme by default
226 | theme: '',
227 |
228 | // Show the picker or make it inline
229 | picker: false,
230 |
231 | // Animation delay in milliseconds
232 | pickerDelay: 0
233 | };
234 |
235 | })(jQuery);
236 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery-simplecolorpicker",
3 | "version": "0.3.1",
4 | "description": "Very simple jQuery color picker",
5 | "main": "jquery.simplecolorpicker.js",
6 | "repository": {
7 | "type": "git",
8 | "url": "git://github.com/tkrotoff/jquery-simplecolorpicker"
9 | },
10 | "keywords": [
11 | "jQuery",
12 | "color",
13 | "picker",
14 | "colorpicker"
15 | ],
16 | "author": "Tanguy Krotoff",
17 | "license": "MIT",
18 | "bugs": {
19 | "url": "https://github.com/tkrotoff/jquery-simplecolorpicker/issues"
20 | },
21 | "homepage": "https://github.com/tkrotoff/jquery-simplecolorpicker"
22 | }
23 |
--------------------------------------------------------------------------------