]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/static/AdminLTE-2.3.7/plugins/colorpicker/bootstrap-colorpicker.js
2 * Bootstrap Colorpicker
3 * http://mjolnic.github.io/bootstrap-colorpicker/
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
14 if (typeof exports
=== 'object') {
15 module
.exports
= factory(window
.jQuery
);
16 } else if (typeof define
=== 'function' && define
.amd
) {
17 define(['jquery'], factory
);
18 } else if (window
.jQuery
&& !window
.jQuery
.fn
.colorpicker
) {
19 factory(window
.jQuery
);
26 var Color = function(val
, customColors
) {
33 this.origFormat
= null; // original string format
35 $.extend(this.colors
, customColors
);
38 if (val
.toLowerCase
!== undefined) {
42 } else if (val
.h
!== undefined) {
50 // 140 predefined colors from the HTML Colors spec
52 "aliceblue": "#f0f8ff",
53 "antiquewhite": "#faebd7",
55 "aquamarine": "#7fffd4",
60 "blanchedalmond": "#ffebcd",
62 "blueviolet": "#8a2be2",
64 "burlywood": "#deb887",
65 "cadetblue": "#5f9ea0",
66 "chartreuse": "#7fff00",
67 "chocolate": "#d2691e",
69 "cornflowerblue": "#6495ed",
70 "cornsilk": "#fff8dc",
73 "darkblue": "#00008b",
74 "darkcyan": "#008b8b",
75 "darkgoldenrod": "#b8860b",
76 "darkgray": "#a9a9a9",
77 "darkgreen": "#006400",
78 "darkkhaki": "#bdb76b",
79 "darkmagenta": "#8b008b",
80 "darkolivegreen": "#556b2f",
81 "darkorange": "#ff8c00",
82 "darkorchid": "#9932cc",
84 "darksalmon": "#e9967a",
85 "darkseagreen": "#8fbc8f",
86 "darkslateblue": "#483d8b",
87 "darkslategray": "#2f4f4f",
88 "darkturquoise": "#00ced1",
89 "darkviolet": "#9400d3",
90 "deeppink": "#ff1493",
91 "deepskyblue": "#00bfff",
93 "dodgerblue": "#1e90ff",
94 "firebrick": "#b22222",
95 "floralwhite": "#fffaf0",
96 "forestgreen": "#228b22",
98 "gainsboro": "#dcdcdc",
99 "ghostwhite": "#f8f8ff",
101 "goldenrod": "#daa520",
104 "greenyellow": "#adff2f",
105 "honeydew": "#f0fff0",
106 "hotpink": "#ff69b4",
107 "indianred": "#cd5c5c",
111 "lavender": "#e6e6fa",
112 "lavenderblush": "#fff0f5",
113 "lawngreen": "#7cfc00",
114 "lemonchiffon": "#fffacd",
115 "lightblue": "#add8e6",
116 "lightcoral": "#f08080",
117 "lightcyan": "#e0ffff",
118 "lightgoldenrodyellow": "#fafad2",
119 "lightgrey": "#d3d3d3",
120 "lightgreen": "#90ee90",
121 "lightpink": "#ffb6c1",
122 "lightsalmon": "#ffa07a",
123 "lightseagreen": "#20b2aa",
124 "lightskyblue": "#87cefa",
125 "lightslategray": "#778899",
126 "lightsteelblue": "#b0c4de",
127 "lightyellow": "#ffffe0",
129 "limegreen": "#32cd32",
131 "magenta": "#ff00ff",
133 "mediumaquamarine": "#66cdaa",
134 "mediumblue": "#0000cd",
135 "mediumorchid": "#ba55d3",
136 "mediumpurple": "#9370d8",
137 "mediumseagreen": "#3cb371",
138 "mediumslateblue": "#7b68ee",
139 "mediumspringgreen": "#00fa9a",
140 "mediumturquoise": "#48d1cc",
141 "mediumvioletred": "#c71585",
142 "midnightblue": "#191970",
143 "mintcream": "#f5fffa",
144 "mistyrose": "#ffe4e1",
145 "moccasin": "#ffe4b5",
146 "navajowhite": "#ffdead",
148 "oldlace": "#fdf5e6",
150 "olivedrab": "#6b8e23",
152 "orangered": "#ff4500",
154 "palegoldenrod": "#eee8aa",
155 "palegreen": "#98fb98",
156 "paleturquoise": "#afeeee",
157 "palevioletred": "#d87093",
158 "papayawhip": "#ffefd5",
159 "peachpuff": "#ffdab9",
163 "powderblue": "#b0e0e6",
166 "rosybrown": "#bc8f8f",
167 "royalblue": "#4169e1",
168 "saddlebrown": "#8b4513",
170 "sandybrown": "#f4a460",
171 "seagreen": "#2e8b57",
172 "seashell": "#fff5ee",
175 "skyblue": "#87ceeb",
176 "slateblue": "#6a5acd",
177 "slategray": "#708090",
179 "springgreen": "#00ff7f",
180 "steelblue": "#4682b4",
183 "thistle": "#d8bfd8",
185 "turquoise": "#40e0d0",
189 "whitesmoke": "#f5f5f5",
191 "yellowgreen": "#9acd32",
192 "transparent": "transparent"
194 _sanitizeNumber: function(val
) {
195 if (typeof val
=== 'number') {
198 if (isNaN(val
) || (val
=== null) || (val
=== '') || (val
=== undefined)) {
201 if (val
.toLowerCase
!== undefined) {
202 return parseFloat(val
);
206 isTransparent: function(strVal
) {
210 strVal
= strVal
.toLowerCase().trim();
211 return (strVal
=== 'transparent') || (strVal
.match(/#?00000000/)) || (strVal
.match(/(rgba|hsla)\(0,0,0,0?\.?0\)/));
213 rgbaIsTransparent: function(rgba
) {
214 return ((rgba
.r
=== 0) && (rgba
.g
=== 0) && (rgba
.b
=== 0) && (rgba
.a
=== 0));
216 //parse a string to HSB
217 setColor: function(strVal
) {
218 strVal
= strVal
.toLowerCase().trim();
220 if (this.isTransparent(strVal
)) {
228 this.value
= this.stringToHSB(strVal
) || {
233 }; // if parser fails, defaults to black
237 stringToHSB: function(strVal
) {
238 strVal
= strVal
.toLowerCase();
240 if (typeof this.colors
[strVal
] !== 'undefined') {
241 strVal
= this.colors
[strVal
];
246 $.each(this.stringParsers
, function(i
, parser
) {
247 var match
= parser
.re
.exec(strVal
),
248 values
= match
&& parser
.parse
.apply(that
, [match
]),
249 format
= alias
|| parser
.format
|| 'rgba';
251 if (format
.match(/hsla?/)) {
252 result
= that
.RGBtoHSB
.apply(that
, that
.HSLtoRGB
.apply(that
, values
));
254 result
= that
.RGBtoHSB
.apply(that
, values
);
256 that
.origFormat
= format
;
263 setHue: function(h
) {
264 this.value
.h
= 1 - h
;
266 setSaturation: function(s
) {
269 setBrightness: function(b
) {
270 this.value
.b
= 1 - b
;
272 setAlpha: function(a
) {
273 this.value
.a
= parseInt((1 - a
) * 100, 10) / 100;
275 toRGB: function(h
, s
, b
, a
) {
285 X
= C
* (1 - Math
.abs(h
% 2 - 1));
289 R
+= [C
, X
, 0, 0, X
, C
][h
];
290 G
+= [X
, C
, C
, X
, 0, 0][h
];
291 B
+= [0, 0, X
, C
, C
, X
][h
];
293 r
: Math
.round(R
* 255),
294 g
: Math
.round(G
* 255),
295 b
: Math
.round(B
* 255),
299 toHex: function(h
, s
, b
, a
) {
300 var rgb
= this.toRGB(h
, s
, b
, a
);
301 if (this.rgbaIsTransparent(rgb
)) {
302 return 'transparent';
304 return '#' + ((1 << 24) | (parseInt(rgb
.r
) << 16) | (parseInt(rgb
.g
) << 8) | parseInt(rgb
.b
)).toString(16).substr(1);
306 toHSL: function(h
, s
, b
, a
) {
307 h
= h
|| this.value
.h
;
308 s
= s
|| this.value
.s
;
309 b
= b
|| this.value
.b
;
310 a
= a
|| this.value
.a
;
315 if (L
> 0 && L
<= 1) {
331 toAlias: function(r
, g
, b
, a
) {
332 var rgb
= this.toHex(r
, g
, b
, a
);
333 for (var alias
in this.colors
) {
334 if (this.colors
[alias
] === rgb
) {
340 RGBtoHSB: function(r
, g
, b
, a
) {
346 V
= Math
.max(r
, g
, b
);
347 C
= V
- Math
.min(r
, g
, b
);
348 H
= (C
=== 0 ? null :
349 V
=== r
? (g
- b
) / C
:
350 V
=== g
? (b
- r
) / C
+ 2 :
353 H
= ((H
+ 360) % 6) * 60 / 360;
354 S
= C
=== 0 ? 0 : C
/ V
;
356 h
: this._sanitizeNumber(H
),
359 a
: this._sanitizeNumber(a
)
362 HueToRGB: function(p
, q
, h
) {
369 return p
+ (q
- p
) * h
* 6;
370 } else if ((h
* 2) < 1) {
372 } else if ((h
* 3) < 2) {
373 return p
+ (q
- p
) * ((2 / 3) - h
) * 6;
378 HSLtoRGB: function(h
, s
, l
, a
) {
391 var tr
= h
+ (1 / 3);
393 var tb
= h
- (1 / 3);
395 var r
= Math
.round(this.HueToRGB(p
, q
, tr
) * 255);
396 var g
= Math
.round(this.HueToRGB(p
, q
, tg
) * 255);
397 var b
= Math
.round(this.HueToRGB(p
, q
, tb
) * 255);
398 return [r
, g
, b
, this._sanitizeNumber(a
)];
400 toString: function(format
) {
401 format
= format
|| 'rgba';
407 if (this.rgbaIsTransparent(c
)) {
408 return 'transparent';
410 return 'rgb(' + c
.r
+ ',' + c
.g
+ ',' + c
.b
+ ')';
416 return 'rgba(' + c
.r
+ ',' + c
.g
+ ',' + c
.b
+ ',' + c
.a
+ ')';
422 return 'hsl(' + Math
.round(c
.h
* 360) + ',' + Math
.round(c
.s
* 100) + '%,' + Math
.round(c
.l
* 100) + '%)';
428 return 'hsla(' + Math
.round(c
.h
* 360) + ',' + Math
.round(c
.s
* 100) + '%,' + Math
.round(c
.l
* 100) + '%,' + c
.a
+ ')';
437 return this.toAlias() || this.toHex();
445 // a set of RE's that can match strings and generate color tuples.
446 // from John Resig color plugin
447 // https://github.com/jquery/jquery-color/
449 re
: /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*?\)/,
451 parse: function(execResult
) {
460 re
: /rgb\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*?\)/,
462 parse: function(execResult
) {
464 2.55 * execResult
[1],
465 2.55 * execResult
[2],
466 2.55 * execResult
[3],
471 re
: /rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
473 parse: function(execResult
) {
482 re
: /rgba\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
484 parse: function(execResult
) {
486 2.55 * execResult
[1],
487 2.55 * execResult
[2],
488 2.55 * execResult
[3],
493 re
: /hsl\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*?\)/,
495 parse: function(execResult
) {
504 re
: /hsla\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
506 parse: function(execResult
) {
515 re
: /#?([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
517 parse: function(execResult
) {
519 parseInt(execResult
[1], 16),
520 parseInt(execResult
[2], 16),
521 parseInt(execResult
[3], 16),
526 re
: /#?([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
528 parse: function(execResult
) {
530 parseInt(execResult
[1] + execResult
[1], 16),
531 parseInt(execResult
[2] + execResult
[2], 16),
532 parseInt(execResult
[3] + execResult
[3], 16),
537 colorNameToHex: function(name
) {
538 if (typeof this.colors
[name
.toLowerCase()] !== 'undefined') {
539 return this.colors
[name
.toLowerCase()];
547 horizontal
: false, // horizontal mode layout ?
548 inline
: false, //forces to show the colorpicker as an inline element
549 color
: false, //forces a color
550 format
: false, //forces a format
551 input
: 'input', // children input selector
552 container
: false, // container selector
553 component
: '.add-on, .input-group-addon', // children component selector
558 callLeft
: 'setSaturation',
559 callTop
: 'setBrightness'
578 callLeft
: 'setSaturation',
579 callTop
: 'setBrightness'
590 callLeft
: 'setAlpha',
594 template
: '<div class="colorpicker dropdown-menu">' +
595 '<div class="colorpicker-saturation"><i><b></b></i></div>' +
596 '<div class="colorpicker-hue"><i></i></div>' +
597 '<div class="colorpicker-alpha"><i></i></div>' +
598 '<div class="colorpicker-color"><div /></div>' +
599 '<div class="colorpicker-selectors"></div>' +
606 var Colorpicker = function(element
, options
) {
607 this.element
= $(element
).addClass('colorpicker-element');
608 this.options
= $.extend(true, {}, defaults
, this.element
.data(), options
);
609 this.component
= this.options
.component
;
610 this.component
= (this.component
!== false) ? this.element
.find(this.component
) : false;
611 if (this.component
&& (this.component
.length
=== 0)) {
612 this.component
= false;
614 this.container
= (this.options
.container
=== true) ? this.element
: this.options
.container
;
615 this.container
= (this.container
!== false) ? $(this.container
) : false;
617 // Is the element an input? Should we search inside for any input?
618 this.input
= this.element
.is('input') ? this.element
: (this.options
.input
?
619 this.element
.find(this.options
.input
) : false);
620 if (this.input
&& (this.input
.length
=== 0)) {
624 this.color
= new Color(this.options
.color
!== false ? this.options
.color
: this.getValue(), this.options
.colorSelectors
);
625 this.format
= this.options
.format
!== false ? this.options
.format
: this.color
.origFormat
;
628 this.picker
= $(this.options
.template
);
629 if (this.options
.customClass
) {
630 this.picker
.addClass(this.options
.customClass
);
632 if (this.options
.inline
) {
633 this.picker
.addClass('colorpicker-inline colorpicker-visible');
635 this.picker
.addClass('colorpicker-hidden');
637 if (this.options
.horizontal
) {
638 this.picker
.addClass('colorpicker-horizontal');
640 if (this.format
=== 'rgba' || this.format
=== 'hsla' || this.options
.format
=== false) {
641 this.picker
.addClass('colorpicker-with-alpha');
643 if (this.options
.align
=== 'right') {
644 this.picker
.addClass('colorpicker-right');
646 if (this.options
.colorSelectors
) {
647 var colorpicker
= this;
648 $.each(this.options
.colorSelectors
, function(name
, color
) {
649 var $btn
= $('<i />').css('background-color', color
).data('class', name
);
650 $btn
.click(function() {
651 colorpicker
.setValue($(this).css('background-color'));
653 colorpicker
.picker
.find('.colorpicker-selectors').append($btn
);
655 this.picker
.find('.colorpicker-selectors').show();
657 this.picker
.on('mousedown.colorpicker touchstart.colorpicker', $.proxy(this.mousedown
, this));
658 this.picker
.appendTo(this.container
? this.container
: $('body'));
661 if (this.input
!== false) {
663 'keyup.colorpicker': $.proxy(this.keyup
, this)
666 'change.colorpicker': $.proxy(this.change
, this)
668 if (this.component
=== false) {
670 'focus.colorpicker': $.proxy(this.show
, this)
673 if (this.options
.inline
=== false) {
675 'focusout.colorpicker': $.proxy(this.hide
, this)
680 if (this.component
!== false) {
682 'click.colorpicker': $.proxy(this.show
, this)
686 if ((this.input
=== false) && (this.component
=== false)) {
688 'click.colorpicker': $.proxy(this.show
, this)
692 // for HTML5 input[type='color']
693 if ((this.input
!== false) && (this.component
!== false) && (this.input
.attr('type') === 'color')) {
696 'click.colorpicker': $.proxy(this.show
, this),
697 'focus.colorpicker': $.proxy(this.show
, this)
702 $($.proxy(function() {
703 this.element
.trigger('create');
707 Colorpicker
.Color
= Color
;
709 Colorpicker
.prototype = {
710 constructor: Colorpicker
,
711 destroy: function() {
712 this.picker
.remove();
713 this.element
.removeData('colorpicker').off('.colorpicker');
714 if (this.input
!== false) {
715 this.input
.off('.colorpicker');
717 if (this.component
!== false) {
718 this.component
.off('.colorpicker');
720 this.element
.removeClass('colorpicker-element');
721 this.element
.trigger({
725 reposition: function() {
726 if (this.options
.inline
!== false || this.options
.container
) {
729 var type
= this.container
&& this.container
[0] !== document
.body
? 'position' : 'offset';
730 var element
= this.component
|| this.element
;
731 var offset
= element
[type
]();
732 if (this.options
.align
=== 'right') {
733 offset
.left
-= this.picker
.outerWidth() - element
.outerWidth();
736 top
: offset
.top
+ element
.outerHeight(),
741 if (this.isDisabled()) {
744 this.picker
.addClass('colorpicker-visible').removeClass('colorpicker-hidden');
746 $(window
).on('resize.colorpicker', $.proxy(this.reposition
, this));
747 if (e
&& (!this.hasInput() || this.input
.attr('type') === 'color')) {
748 if (e
.stopPropagation
&& e
.preventDefault
) {
753 if (this.options
.inline
=== false) {
754 $(window
.document
).on({
755 'mousedown.colorpicker': $.proxy(this.hide
, this)
758 this.element
.trigger({
764 this.picker
.addClass('colorpicker-hidden').removeClass('colorpicker-visible');
765 $(window
).off('resize.colorpicker', this.reposition
);
767 'mousedown.colorpicker': this.hide
770 this.element
.trigger({
775 updateData: function(val
) {
776 val
= val
|| this.color
.toString(this.format
);
777 this.element
.data('color', val
);
780 updateInput: function(val
) {
781 val
= val
|| this.color
.toString(this.format
);
782 if (this.input
!== false) {
783 if (this.options
.colorSelectors
) {
784 var color
= new Color(val
, this.options
.colorSelectors
);
785 var alias
= color
.toAlias();
786 if (typeof this.options
.colorSelectors
[alias
] !== 'undefined') {
790 this.input
.prop('value', val
);
794 updatePicker: function(val
) {
795 if (val
!== undefined) {
796 this.color
= new Color(val
, this.options
.colorSelectors
);
798 var sl
= (this.options
.horizontal
=== false) ? this.options
.sliders
: this.options
.slidersHorz
;
799 var icns
= this.picker
.find('i');
800 if (icns
.length
=== 0) {
803 if (this.options
.horizontal
=== false) {
804 sl
= this.options
.sliders
;
805 icns
.eq(1).css('top', sl
.hue
.maxTop
* (1 - this.color
.value
.h
)).end()
806 .eq(2).css('top', sl
.alpha
.maxTop
* (1 - this.color
.value
.a
));
808 sl
= this.options
.slidersHorz
;
809 icns
.eq(1).css('left', sl
.hue
.maxLeft
* (1 - this.color
.value
.h
)).end()
810 .eq(2).css('left', sl
.alpha
.maxLeft
* (1 - this.color
.value
.a
));
813 'top': sl
.saturation
.maxTop
- this.color
.value
.b
* sl
.saturation
.maxTop
,
814 'left': this.color
.value
.s
* sl
.saturation
.maxLeft
816 this.picker
.find('.colorpicker-saturation').css('backgroundColor', this.color
.toHex(this.color
.value
.h
, 1, 1, 1));
817 this.picker
.find('.colorpicker-alpha').css('backgroundColor', this.color
.toHex());
818 this.picker
.find('.colorpicker-color, .colorpicker-color div').css('backgroundColor', this.color
.toString(this.format
));
821 updateComponent: function(val
) {
822 val
= val
|| this.color
.toString(this.format
);
823 if (this.component
!== false) {
824 var icn
= this.component
.find('i').eq(0);
825 if (icn
.length
> 0) {
827 'backgroundColor': val
831 'backgroundColor': val
837 update: function(force
) {
839 if ((this.getValue(false) !== false) || (force
=== true)) {
840 // Update input/data only if the current value is not empty
841 val
= this.updateComponent();
842 this.updateInput(val
);
843 this.updateData(val
);
844 this.updatePicker(); // only update picker if value is not empty
849 setValue: function(val
) { // set color manually
850 this.color
= new Color(val
, this.options
.colorSelectors
);
852 this.element
.trigger({
858 getValue: function(defaultValue
) {
859 defaultValue
= (defaultValue
=== undefined) ? '#000000' : defaultValue
;
861 if (this.hasInput()) {
862 val
= this.input
.val();
864 val
= this.element
.data('color');
866 if ((val
=== undefined) || (val
=== '') || (val
=== null)) {
867 // if not defined or empty, return default
872 hasInput: function() {
873 return (this.input
!== false);
875 isDisabled: function() {
876 if (this.hasInput()) {
877 return (this.input
.prop('disabled') === true);
881 disable: function() {
882 if (this.hasInput()) {
883 this.input
.prop('disabled', true);
884 this.element
.trigger({
887 value
: this.getValue()
894 if (this.hasInput()) {
895 this.input
.prop('disabled', false);
896 this.element
.trigger({
899 value
: this.getValue()
910 mousedown: function(e
) {
911 if (!e
.pageX
&& !e
.pageY
&& e
.originalEvent
) {
912 e
.pageX
= e
.originalEvent
.touches
[0].pageX
;
913 e
.pageY
= e
.originalEvent
.touches
[0].pageY
;
918 var target
= $(e
.target
);
920 //detect the slider and set the limits and callbacks
921 var zone
= target
.closest('div');
922 var sl
= this.options
.horizontal
? this.options
.slidersHorz
: this.options
.sliders
;
923 if (!zone
.is('.colorpicker')) {
924 if (zone
.is('.colorpicker-saturation')) {
925 this.currentSlider
= $.extend({}, sl
.saturation
);
926 } else if (zone
.is('.colorpicker-hue')) {
927 this.currentSlider
= $.extend({}, sl
.hue
);
928 } else if (zone
.is('.colorpicker-alpha')) {
929 this.currentSlider
= $.extend({}, sl
.alpha
);
933 var offset
= zone
.offset();
934 //reference to guide's style
935 this.currentSlider
.guide
= zone
.find('i')[0].style
;
936 this.currentSlider
.left
= e
.pageX
- offset
.left
;
937 this.currentSlider
.top
= e
.pageY
- offset
.top
;
938 this.mousePointer
= {
942 //trigger mousemove to move the guide to the current position
944 'mousemove.colorpicker': $.proxy(this.mousemove
, this),
945 'touchmove.colorpicker': $.proxy(this.mousemove
, this),
946 'mouseup.colorpicker': $.proxy(this.mouseup
, this),
947 'touchend.colorpicker': $.proxy(this.mouseup
, this)
948 }).trigger('mousemove');
952 mousemove: function(e
) {
953 if (!e
.pageX
&& !e
.pageY
&& e
.originalEvent
) {
954 e
.pageX
= e
.originalEvent
.touches
[0].pageX
;
955 e
.pageY
= e
.originalEvent
.touches
[0].pageY
;
962 this.currentSlider
.maxLeft
,
963 this.currentSlider
.left
+ ((e
.pageX
|| this.mousePointer
.left
) - this.mousePointer
.left
)
969 this.currentSlider
.maxTop
,
970 this.currentSlider
.top
+ ((e
.pageY
|| this.mousePointer
.top
) - this.mousePointer
.top
)
973 this.currentSlider
.guide
.left
= left
+ 'px';
974 this.currentSlider
.guide
.top
= top
+ 'px';
975 if (this.currentSlider
.callLeft
) {
976 this.color
[this.currentSlider
.callLeft
].call(this.color
, left
/ this.currentSlider
.maxLeft
);
978 if (this.currentSlider
.callTop
) {
979 this.color
[this.currentSlider
.callTop
].call(this.color
, top
/ this.currentSlider
.maxTop
);
981 // Change format dynamically
982 // Only occurs if user choose the dynamic format by
983 // setting option format to false
984 if (this.currentSlider
.callTop
=== 'setAlpha' && this.options
.format
=== false) {
986 // Converting from hex / rgb to rgba
987 if (this.color
.value
.a
!== 1) {
988 this.format
= 'rgba';
989 this.color
.origFormat
= 'rgba';
992 // Converting from rgba to hex
995 this.color
.origFormat
= 'hex';
1000 this.element
.trigger({
1001 type
: 'changeColor',
1006 mouseup: function(e
) {
1007 e
.stopPropagation();
1010 'mousemove.colorpicker': this.mousemove
,
1011 'touchmove.colorpicker': this.mousemove
,
1012 'mouseup.colorpicker': this.mouseup
,
1013 'touchend.colorpicker': this.mouseup
1017 change: function(e
) {
1020 keyup: function(e
) {
1021 if ((e
.keyCode
=== 38)) {
1022 if (this.color
.value
.a
< 1) {
1023 this.color
.value
.a
= Math
.round((this.color
.value
.a
+ 0.01) * 100) / 100;
1026 } else if ((e
.keyCode
=== 40)) {
1027 if (this.color
.value
.a
> 0) {
1028 this.color
.value
.a
= Math
.round((this.color
.value
.a
- 0.01) * 100) / 100;
1032 this.color
= new Color(this.input
.val(), this.options
.colorSelectors
);
1033 // Change format dynamically
1034 // Only occurs if user choose the dynamic format by
1035 // setting option format to false
1036 if (this.color
.origFormat
&& this.options
.format
=== false) {
1037 this.format
= this.color
.origFormat
;
1039 if (this.getValue(false) !== false) {
1041 this.updateComponent();
1042 this.updatePicker();
1045 this.element
.trigger({
1046 type
: 'changeColor',
1048 value
: this.input
.val()
1053 $.colorpicker
= Colorpicker
;
1055 $.fn
.colorpicker = function(option
) {
1056 var pickerArgs
= arguments
,
1059 var $returnValue
= this.each(function() {
1060 var $this = $(this),
1061 inst
= $this.data('colorpicker'),
1062 options
= ((typeof option
=== 'object') ? option
: {});
1063 if ((!inst
) && (typeof option
!== 'string')) {
1064 $this.data('colorpicker', new Colorpicker(this, options
));
1066 if (typeof option
=== 'string') {
1067 rv
= inst
[option
].apply(inst
, Array
.prototype.slice
.call(pickerArgs
, 1));
1071 if (option
=== 'getValue') {
1074 return $returnValue
;
1077 $.fn
.colorpicker
.constructor = Colorpicker
;