Update to bootstrap-colorpicker version 2.3.0

pull/831/head
Martin Fischer 9 years ago
parent 1ee281b3b9
commit d30707611d

@ -72,6 +72,12 @@
background-image: url("img/alpha.png");
}
.colorpicker-saturation,
.colorpicker-hue,
.colorpicker-alpha {
background-size: contain;
}
.colorpicker {
top: 0;
left: 0;
@ -143,15 +149,36 @@
height: 10px;
}
.colorpicker-element .input-group-addon i {
display: block;
.colorpicker-selectors {
display: none;
height: 10px;
margin-top: 5px;
clear: both;
}
.colorpicker-selectors i {
float: left;
width: 10px;
height: 10px;
cursor: pointer;
}
.colorpicker-selectors i + i {
margin-left: 3px;
}
.colorpicker-element .input-group-addon i,
.colorpicker-element .add-on i {
display: inline-block;
width: 16px;
height: 16px;
vertical-align: text-top;
cursor: pointer;
}
.colorpicker.colorpicker-inline {
position: relative;
z-index: auto;
display: inline-block;
float: none;
}
@ -212,3 +239,13 @@
.colorpicker-inline.colorpicker-visible {
display: inline-block;
}
.colorpicker-right:before {
right: 6px;
left: auto;
}
.colorpicker-right:after {
right: 7px;
left: auto;
}

@ -8,11 +8,22 @@
*
* @todo Update DOCS
*/
(function(factory) {
"use strict";
if (typeof exports === 'object') {
module.exports = factory(window.jQuery);
} else if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (window.jQuery && !window.jQuery.fn.colorpicker) {
factory(window.jQuery);
}
}
(function($) {
'use strict';
// Color object
var Color = function(val) {
var Color = function(val, customColors) {
this.value = {
h: 0,
s: 0,
@ -20,8 +31,13 @@
a: 1
};
this.origFormat = null; // original string format
if (customColors) {
$.extend(this.colors, customColors);
}
if (val) {
if (val.toLowerCase !== undefined) {
// cast to string
val = val + '';
this.setColor(val);
} else if (val.h !== undefined) {
this.value = val;
@ -31,6 +47,150 @@
Color.prototype = {
constructor: Color,
// 140 predefined colors from the HTML Colors spec
colors: {
"aliceblue": "#f0f8ff",
"antiquewhite": "#faebd7",
"aqua": "#00ffff",
"aquamarine": "#7fffd4",
"azure": "#f0ffff",
"beige": "#f5f5dc",
"bisque": "#ffe4c4",
"black": "#000000",
"blanchedalmond": "#ffebcd",
"blue": "#0000ff",
"blueviolet": "#8a2be2",
"brown": "#a52a2a",
"burlywood": "#deb887",
"cadetblue": "#5f9ea0",
"chartreuse": "#7fff00",
"chocolate": "#d2691e",
"coral": "#ff7f50",
"cornflowerblue": "#6495ed",
"cornsilk": "#fff8dc",
"crimson": "#dc143c",
"cyan": "#00ffff",
"darkblue": "#00008b",
"darkcyan": "#008b8b",
"darkgoldenrod": "#b8860b",
"darkgray": "#a9a9a9",
"darkgreen": "#006400",
"darkkhaki": "#bdb76b",
"darkmagenta": "#8b008b",
"darkolivegreen": "#556b2f",
"darkorange": "#ff8c00",
"darkorchid": "#9932cc",
"darkred": "#8b0000",
"darksalmon": "#e9967a",
"darkseagreen": "#8fbc8f",
"darkslateblue": "#483d8b",
"darkslategray": "#2f4f4f",
"darkturquoise": "#00ced1",
"darkviolet": "#9400d3",
"deeppink": "#ff1493",
"deepskyblue": "#00bfff",
"dimgray": "#696969",
"dodgerblue": "#1e90ff",
"firebrick": "#b22222",
"floralwhite": "#fffaf0",
"forestgreen": "#228b22",
"fuchsia": "#ff00ff",
"gainsboro": "#dcdcdc",
"ghostwhite": "#f8f8ff",
"gold": "#ffd700",
"goldenrod": "#daa520",
"gray": "#808080",
"green": "#008000",
"greenyellow": "#adff2f",
"honeydew": "#f0fff0",
"hotpink": "#ff69b4",
"indianred": "#cd5c5c",
"indigo": "#4b0082",
"ivory": "#fffff0",
"khaki": "#f0e68c",
"lavender": "#e6e6fa",
"lavenderblush": "#fff0f5",
"lawngreen": "#7cfc00",
"lemonchiffon": "#fffacd",
"lightblue": "#add8e6",
"lightcoral": "#f08080",
"lightcyan": "#e0ffff",
"lightgoldenrodyellow": "#fafad2",
"lightgrey": "#d3d3d3",
"lightgreen": "#90ee90",
"lightpink": "#ffb6c1",
"lightsalmon": "#ffa07a",
"lightseagreen": "#20b2aa",
"lightskyblue": "#87cefa",
"lightslategray": "#778899",
"lightsteelblue": "#b0c4de",
"lightyellow": "#ffffe0",
"lime": "#00ff00",
"limegreen": "#32cd32",
"linen": "#faf0e6",
"magenta": "#ff00ff",
"maroon": "#800000",
"mediumaquamarine": "#66cdaa",
"mediumblue": "#0000cd",
"mediumorchid": "#ba55d3",
"mediumpurple": "#9370d8",
"mediumseagreen": "#3cb371",
"mediumslateblue": "#7b68ee",
"mediumspringgreen": "#00fa9a",
"mediumturquoise": "#48d1cc",
"mediumvioletred": "#c71585",
"midnightblue": "#191970",
"mintcream": "#f5fffa",
"mistyrose": "#ffe4e1",
"moccasin": "#ffe4b5",
"navajowhite": "#ffdead",
"navy": "#000080",
"oldlace": "#fdf5e6",
"olive": "#808000",
"olivedrab": "#6b8e23",
"orange": "#ffa500",
"orangered": "#ff4500",
"orchid": "#da70d6",
"palegoldenrod": "#eee8aa",
"palegreen": "#98fb98",
"paleturquoise": "#afeeee",
"palevioletred": "#d87093",
"papayawhip": "#ffefd5",
"peachpuff": "#ffdab9",
"peru": "#cd853f",
"pink": "#ffc0cb",
"plum": "#dda0dd",
"powderblue": "#b0e0e6",
"purple": "#800080",
"red": "#ff0000",
"rosybrown": "#bc8f8f",
"royalblue": "#4169e1",
"saddlebrown": "#8b4513",
"salmon": "#fa8072",
"sandybrown": "#f4a460",
"seagreen": "#2e8b57",
"seashell": "#fff5ee",
"sienna": "#a0522d",
"silver": "#c0c0c0",
"skyblue": "#87ceeb",
"slateblue": "#6a5acd",
"slategray": "#708090",
"snow": "#fffafa",
"springgreen": "#00ff7f",
"steelblue": "#4682b4",
"tan": "#d2b48c",
"teal": "#008080",
"thistle": "#d8bfd8",
"tomato": "#ff6347",
"turquoise": "#40e0d0",
"violet": "#ee82ee",
"wheat": "#f5deb3",
"white": "#ffffff",
"whitesmoke": "#f5f5f5",
"yellow": "#ffff00",
"yellowgreen": "#9acd32",
"transparent": "transparent"
},
_sanitizeNumber: function(val) {
if (typeof val === 'number') {
return val;
@ -43,24 +203,50 @@
}
return 1;
},
isTransparent: function(strVal) {
if (!strVal) {
return false;
}
strVal = strVal.toLowerCase().trim();
return (strVal === 'transparent') || (strVal.match(/#?00000000/)) || (strVal.match(/(rgba|hsla)\(0,0,0,0?\.?0\)/));
},
rgbaIsTransparent: function(rgba) {
return ((rgba.r === 0) && (rgba.g === 0) && (rgba.b === 0) && (rgba.a === 0));
},
//parse a string to HSB
setColor: function(strVal) {
strVal = strVal.toLowerCase();
this.value = this.stringToHSB(strVal) ||  {
strVal = strVal.toLowerCase().trim();
if (strVal) {
if (this.isTransparent(strVal)) {
this.value = {
h: 0,
s: 0,
b: 0,
a: 1
a: 0
};
} else {
this.value = this.stringToHSB(strVal) || {
h: 0,
s: 0,
b: 0,
a: 1
}; // if parser fails, defaults to black
}
}
},
stringToHSB: function(strVal) {
strVal = strVal.toLowerCase();
var alias;
if (typeof this.colors[strVal] !== 'undefined') {
strVal = this.colors[strVal];
alias = 'alias';
}
var that = this,
result = false;
$.each(this.stringParsers, function(i, parser) {
var match = parser.re.exec(strVal),
values = match && parser.parse.apply(that, [match]),
format = parser.format || 'rgba';
format = alias || parser.format || 'rgba';
if (values) {
if (format.match(/hsla?/)) {
result = that.RGBtoHSB.apply(that, that.HSLtoRGB.apply(that, values));
@ -86,50 +272,35 @@
setAlpha: function(a) {
this.value.a = parseInt((1 - a) * 100, 10) / 100;
},
toRGB: function(h, s, v, a) {
h = h || this.value.h;
s = s || this.value.s;
v = v || this.value.b;
a = a || this.value.a;
toRGB: function(h, s, b, a) {
if (!h) {
h = this.value.h;
s = this.value.s;
b = this.value.b;
}
h *= 360;
var R, G, B, X, C;
h = (h % 360) / 60;
C = b * s;
X = C * (1 - Math.abs(h % 2 - 1));
R = G = B = b - C;
var r, g, b, i, f, p, q, t;
if (h && s === undefined && v === undefined) {
s = h.s, v = h.v, h = h.h;
}
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
r = v, g = t, b = p;
break;
case 1:
r = q, g = v, b = p;
break;
case 2:
r = p, g = v, b = t;
break;
case 3:
r = p, g = q, b = v;
break;
case 4:
r = t, g = p, b = v;
break;
case 5:
r = v, g = p, b = q;
break;
}
h = ~~h;
R += [C, X, 0, 0, X, C][h];
G += [X, C, C, X, 0, 0][h];
B += [0, 0, X, C, C, X][h];
return {
r: Math.floor(r * 255),
g: Math.floor(g * 255),
b: Math.floor(b * 255),
a: a
r: Math.round(R * 255),
g: Math.round(G * 255),
b: Math.round(B * 255),
a: a || this.value.a
};
},
toHex: function(h, s, b, a) {
var rgb = this.toRGB(h, s, b, a);
if (this.rgbaIsTransparent(rgb)) {
return 'transparent';
}
return '#' + ((1 << 24) | (parseInt(rgb.r) << 16) | (parseInt(rgb.g) << 8) | parseInt(rgb.b)).toString(16).substr(1);
},
toHSL: function(h, s, b, a) {
@ -151,12 +322,21 @@
S = 1;
}
return {
h: H,
s: S,
l: L,
a: a
h: isNaN(H) ? 0 : H,
s: isNaN(S) ? 0 : S,
l: isNaN(L) ? 0 : L,
a: isNaN(a) ? 0 : a
};
},
toAlias: function(r, g, b, a) {
var rgb = this.toHex(r, g, b, a);
for (var alias in this.colors) {
if (this.colors[alias] === rgb) {
return alias;
}
}
return false;
},
RGBtoHSB: function(r, g, b, a) {
r /= 255;
g /= 255;
@ -218,30 +398,34 @@
return [r, g, b, this._sanitizeNumber(a)];
},
toString: function(format) {
format = format ||  'rgba';
format = format || 'rgba';
var c = false;
switch (format) {
case 'rgb':
{
var rgb = this.toRGB();
return 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')';
c = this.toRGB();
if (this.rgbaIsTransparent(c)) {
return 'transparent';
}
return 'rgb(' + c.r + ',' + c.g + ',' + c.b + ')';
}
break;
case 'rgba':
{
var rgb = this.toRGB();
return 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + rgb.a + ')';
c = this.toRGB();
return 'rgba(' + c.r + ',' + c.g + ',' + c.b + ',' + c.a + ')';
}
break;
case 'hsl':
{
var hsl = this.toHSL();
return 'hsl(' + Math.round(hsl.h * 360) + ',' + Math.round(hsl.s * 100) + '%,' + Math.round(hsl.l * 100) + '%)';
c = this.toHSL();
return 'hsl(' + Math.round(c.h * 360) + ',' + Math.round(c.s * 100) + '%,' + Math.round(c.l * 100) + '%)';
}
break;
case 'hsla':
{
var hsl = this.toHSL();
return 'hsla(' + Math.round(hsl.h * 360) + ',' + Math.round(hsl.s * 100) + '%,' + Math.round(hsl.l * 100) + '%,' + hsl.a + ')';
c = this.toHSL();
return 'hsla(' + Math.round(c.h * 360) + ',' + Math.round(c.s * 100) + '%,' + Math.round(c.l * 100) + '%,' + c.a + ')';
}
break;
case 'hex':
@ -249,9 +433,11 @@
return this.toHex();
}
break;
case 'alias':
return this.toAlias() || this.toHex();
default:
{
return false;
return c;
}
break;
}
@ -260,28 +446,6 @@
// from John Resig color plugin
// https://github.com/jquery/jquery-color/
stringParsers: [{
re: /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
format: 'hex',
parse: function(execResult) {
return [
parseInt(execResult[1], 16),
parseInt(execResult[2], 16),
parseInt(execResult[3], 16),
1
];
}
}, {
re: /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
format: 'hex',
parse: function(execResult) {
return [
parseInt(execResult[1] + execResult[1], 16),
parseInt(execResult[2] + execResult[2], 16),
parseInt(execResult[3] + execResult[3], 16),
1
];
}
}, {
re: /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*?\)/,
format: 'rgb',
parse: function(execResult) {
@ -348,163 +512,31 @@
];
}
}, {
//predefined color name
re: /^([a-z]{3,})$/,
format: 'alias',
re: /#?([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
format: 'hex',
parse: function(execResult) {
var hexval = this.colorNameToHex(execResult[0]) ||  '#000000';
var match = this.stringParsers[0].re.exec(hexval),
values = match && this.stringParsers[0].parse.apply(this, [match]);
return values;
return [
parseInt(execResult[1], 16),
parseInt(execResult[2], 16),
parseInt(execResult[3], 16),
1
];
}
}, {
re: /#?([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
format: 'hex',
parse: function(execResult) {
return [
parseInt(execResult[1] + execResult[1], 16),
parseInt(execResult[2] + execResult[2], 16),
parseInt(execResult[3] + execResult[3], 16),
1
];
}
}],
colorNameToHex: function(name) {
// 140 predefined colors from the HTML Colors spec
var colors = {
"aliceblue": "#f0f8ff",
"antiquewhite": "#faebd7",
"aqua": "#00ffff",
"aquamarine": "#7fffd4",
"azure": "#f0ffff",
"beige": "#f5f5dc",
"bisque": "#ffe4c4",
"black": "#000000",
"blanchedalmond": "#ffebcd",
"blue": "#0000ff",
"blueviolet": "#8a2be2",
"brown": "#a52a2a",
"burlywood": "#deb887",
"cadetblue": "#5f9ea0",
"chartreuse": "#7fff00",
"chocolate": "#d2691e",
"coral": "#ff7f50",
"cornflowerblue": "#6495ed",
"cornsilk": "#fff8dc",
"crimson": "#dc143c",
"cyan": "#00ffff",
"darkblue": "#00008b",
"darkcyan": "#008b8b",
"darkgoldenrod": "#b8860b",
"darkgray": "#a9a9a9",
"darkgreen": "#006400",
"darkkhaki": "#bdb76b",
"darkmagenta": "#8b008b",
"darkolivegreen": "#556b2f",
"darkorange": "#ff8c00",
"darkorchid": "#9932cc",
"darkred": "#8b0000",
"darksalmon": "#e9967a",
"darkseagreen": "#8fbc8f",
"darkslateblue": "#483d8b",
"darkslategray": "#2f4f4f",
"darkturquoise": "#00ced1",
"darkviolet": "#9400d3",
"deeppink": "#ff1493",
"deepskyblue": "#00bfff",
"dimgray": "#696969",
"dodgerblue": "#1e90ff",
"firebrick": "#b22222",
"floralwhite": "#fffaf0",
"forestgreen": "#228b22",
"fuchsia": "#ff00ff",
"gainsboro": "#dcdcdc",
"ghostwhite": "#f8f8ff",
"gold": "#ffd700",
"goldenrod": "#daa520",
"gray": "#808080",
"green": "#008000",
"greenyellow": "#adff2f",
"honeydew": "#f0fff0",
"hotpink": "#ff69b4",
"indianred ": "#cd5c5c",
"indigo ": "#4b0082",
"ivory": "#fffff0",
"khaki": "#f0e68c",
"lavender": "#e6e6fa",
"lavenderblush": "#fff0f5",
"lawngreen": "#7cfc00",
"lemonchiffon": "#fffacd",
"lightblue": "#add8e6",
"lightcoral": "#f08080",
"lightcyan": "#e0ffff",
"lightgoldenrodyellow": "#fafad2",
"lightgrey": "#d3d3d3",
"lightgreen": "#90ee90",
"lightpink": "#ffb6c1",
"lightsalmon": "#ffa07a",
"lightseagreen": "#20b2aa",
"lightskyblue": "#87cefa",
"lightslategray": "#778899",
"lightsteelblue": "#b0c4de",
"lightyellow": "#ffffe0",
"lime": "#00ff00",
"limegreen": "#32cd32",
"linen": "#faf0e6",
"magenta": "#ff00ff",
"maroon": "#800000",
"mediumaquamarine": "#66cdaa",
"mediumblue": "#0000cd",
"mediumorchid": "#ba55d3",
"mediumpurple": "#9370d8",
"mediumseagreen": "#3cb371",
"mediumslateblue": "#7b68ee",
"mediumspringgreen": "#00fa9a",
"mediumturquoise": "#48d1cc",
"mediumvioletred": "#c71585",
"midnightblue": "#191970",
"mintcream": "#f5fffa",
"mistyrose": "#ffe4e1",
"moccasin": "#ffe4b5",
"navajowhite": "#ffdead",
"navy": "#000080",
"oldlace": "#fdf5e6",
"olive": "#808000",
"olivedrab": "#6b8e23",
"orange": "#ffa500",
"orangered": "#ff4500",
"orchid": "#da70d6",
"palegoldenrod": "#eee8aa",
"palegreen": "#98fb98",
"paleturquoise": "#afeeee",
"palevioletred": "#d87093",
"papayawhip": "#ffefd5",
"peachpuff": "#ffdab9",
"peru": "#cd853f",
"pink": "#ffc0cb",
"plum": "#dda0dd",
"powderblue": "#b0e0e6",
"purple": "#800080",
"red": "#ff0000",
"rosybrown": "#bc8f8f",
"royalblue": "#4169e1",
"saddlebrown": "#8b4513",
"salmon": "#fa8072",
"sandybrown": "#f4a460",
"seagreen": "#2e8b57",
"seashell": "#fff5ee",
"sienna": "#a0522d",
"silver": "#c0c0c0",
"skyblue": "#87ceeb",
"slateblue": "#6a5acd",
"slategray": "#708090",
"snow": "#fffafa",
"springgreen": "#00ff7f",
"steelblue": "#4682b4",
"tan": "#d2b48c",
"teal": "#008080",
"thistle": "#d8bfd8",
"tomato": "#ff6347",
"turquoise": "#40e0d0",
"violet": "#ee82ee",
"wheat": "#f5deb3",
"white": "#ffffff",
"whitesmoke": "#f5f5f5",
"yellow": "#ffff00",
"yellowgreen": "#9acd32"
};
if (typeof colors[name.toLowerCase()] !== 'undefined') {
return colors[name.toLowerCase()];
if (typeof this.colors[name.toLowerCase()] !== 'undefined') {
return this.colors[name.toLowerCase()];
}
return false;
}
@ -564,12 +596,16 @@
'<div class="colorpicker-hue"><i></i></div>' +
'<div class="colorpicker-alpha"><i></i></div>' +
'<div class="colorpicker-color"><div /></div>' +
'</div>'
'<div class="colorpicker-selectors"></div>' +
'</div>',
align: 'right',
customClass: null,
colorSelectors: null
};
var Colorpicker = function(element, options) {
this.element = $(element).addClass('colorpicker-element');
this.options = $.extend({}, defaults, this.element.data(), options);
this.options = $.extend(true, {}, defaults, this.element.data(), options);
this.component = this.options.component;
this.component = (this.component !== false) ? this.element.find(this.component) : false;
if (this.component && (this.component.length === 0)) {
@ -585,11 +621,14 @@
this.input = false;
}
// Set HSB color
this.color = new Color(this.options.color !== false ? this.options.color : this.getValue());
this.color = new Color(this.options.color !== false ? this.options.color : this.getValue(), this.options.colorSelectors);
this.format = this.options.format !== false ? this.options.format : this.color.origFormat;
// Setup picker
this.picker = $(this.options.template);
if (this.options.customClass) {
this.picker.addClass(this.options.customClass);
}
if (this.options.inline) {
this.picker.addClass('colorpicker-inline colorpicker-visible');
} else {
@ -598,10 +637,24 @@
if (this.options.horizontal) {
this.picker.addClass('colorpicker-horizontal');
}
if (this.format === 'rgba' || this.format === 'hsla') {
if (this.format === 'rgba' || this.format === 'hsla' || this.options.format === false) {
this.picker.addClass('colorpicker-with-alpha');
}
this.picker.on('mousedown.colorpicker', $.proxy(this.mousedown, this));
if (this.options.align === 'right') {
this.picker.addClass('colorpicker-right');
}
if (this.options.colorSelectors) {
var colorpicker = this;
$.each(this.options.colorSelectors, function(name, color) {
var $btn = $('<i />').css('background-color', color).data('class', name);
$btn.click(function() {
colorpicker.setValue($(this).css('background-color'));
});
colorpicker.picker.find('.colorpicker-selectors').append($btn);
});
this.picker.find('.colorpicker-selectors').show();
}
this.picker.on('mousedown.colorpicker touchstart.colorpicker', $.proxy(this.mousedown, this));
this.picker.appendTo(this.container ? this.container : $('body'));
// Bind events
@ -609,6 +662,9 @@
this.input.on({
'keyup.colorpicker': $.proxy(this.keyup, this)
});
this.input.on({
'change.colorpicker': $.proxy(this.change, this)
});
if (this.component === false) {
this.element.on({
'focus.colorpicker': $.proxy(this.show, this)
@ -632,6 +688,15 @@
'click.colorpicker': $.proxy(this.show, this)
});
}
// for HTML5 input[type='color']
if ((this.input !== false) && (this.component !== false) && (this.input.attr('type') === 'color')) {
this.input.on({
'click.colorpicker': $.proxy(this.show, this),
'focus.colorpicker': $.proxy(this.show, this)
});
}
this.update();
$($.proxy(function() {
@ -639,8 +704,6 @@
}, this));
};
Colorpicker.version = '2.0.0-beta';
Colorpicker.Color = Color;
Colorpicker.prototype = {
@ -660,12 +723,17 @@
});
},
reposition: function() {
if (this.options.inline !== false) {
if (this.options.inline !== false || this.options.container) {
return false;
}
var offset = this.component ? this.component.offset() : this.element.offset();
var type = this.container && this.container[0] !== document.body ? 'position' : 'offset';
var element = this.component || this.element;
var offset = element[type]();
if (this.options.align === 'right') {
offset.left -= this.picker.outerWidth() - element.outerWidth();
}
this.picker.css({
top: offset.top + (this.component ? this.component.outerHeight() : this.element.outerHeight()),
top: offset.top + element.outerHeight(),
left: offset.left
});
},
@ -676,7 +744,7 @@
this.picker.addClass('colorpicker-visible').removeClass('colorpicker-hidden');
this.reposition();
$(window).on('resize.colorpicker', $.proxy(this.reposition, this));
if (!this.hasInput() && e) {
if (e && (!this.hasInput() || this.input.attr('type') === 'color')) {
if (e.stopPropagation && e.preventDefault) {
e.stopPropagation();
e.preventDefault();
@ -705,20 +773,27 @@
});
},
updateData: function(val) {
val = val ||  this.color.toString(this.format);
val = val || this.color.toString(this.format);
this.element.data('color', val);
return val;
},
updateInput: function(val) {
val = val ||  this.color.toString(this.format);
val = val || this.color.toString(this.format);
if (this.input !== false) {
if (this.options.colorSelectors) {
var color = new Color(val, this.options.colorSelectors);
var alias = color.toAlias();
if (typeof this.options.colorSelectors[alias] !== 'undefined') {
val = alias;
}
}
this.input.prop('value', val);
}
return val;
},
updatePicker: function(val) {
if (val !== undefined) {
this.color = new Color(val);
this.color = new Color(val, this.options.colorSelectors);
}
var sl = (this.options.horizontal === false) ? this.options.sliders : this.options.slidersHorz;
var icns = this.picker.find('i');
@ -744,7 +819,7 @@
return val;
},
updateComponent: function(val) {
val = val ||  this.color.toString(this.format);
val = val || this.color.toString(this.format);
if (this.component !== false) {
var icn = this.component.find('i').eq(0);
if (icn.length > 0) {
@ -760,19 +835,20 @@
return val;
},
update: function(force) {
var val = this.updateComponent();
var val;
if ((this.getValue(false) !== false) || (force === true)) {
// Update input/data only if the current value is not blank
// Update input/data only if the current value is not empty
val = this.updateComponent();
this.updateInput(val);
this.updateData(val);
this.updatePicker(); // only update picker if value is not empty
}
this.updatePicker();
return val;
},
setValue: function(val) { // set color manually
this.color = new Color(val);
this.update();
this.color = new Color(val, this.options.colorSelectors);
this.update(true);
this.element.trigger({
type: 'changeColor',
color: this.color,
@ -805,6 +881,11 @@
disable: function() {
if (this.hasInput()) {
this.input.prop('disabled', true);
this.element.trigger({
type: 'disable',
color: this.color,
value: this.getValue()
});
return true;
}
return false;
@ -812,6 +893,11 @@
enable: function() {
if (this.hasInput()) {
this.input.prop('disabled', false);
this.element.trigger({
type: 'enable',
color: this.color,
value: this.getValue()
});
return true;
}
return false;
@ -822,6 +908,10 @@
top: 0
},
mousedown: function(e) {
if (!e.pageX && !e.pageY && e.originalEvent) {
e.pageX = e.originalEvent.touches[0].pageX;
e.pageY = e.originalEvent.touches[0].pageY;
}
e.stopPropagation();
e.preventDefault();
@ -852,12 +942,18 @@
//trigger mousemove to move the guide to the current position
$(document).on({
'mousemove.colorpicker': $.proxy(this.mousemove, this),
'mouseup.colorpicker': $.proxy(this.mouseup, this)
'touchmove.colorpicker': $.proxy(this.mousemove, this),
'mouseup.colorpicker': $.proxy(this.mouseup, this),
'touchend.colorpicker': $.proxy(this.mouseup, this)
}).trigger('mousemove');
}
return false;
},
mousemove: function(e) {
if (!e.pageX && !e.pageY && e.originalEvent) {
e.pageX = e.originalEvent.touches[0].pageX;
e.pageY = e.originalEvent.touches[0].pageY;
}
e.stopPropagation();
e.preventDefault();
var left = Math.max(
@ -877,10 +973,27 @@
this.currentSlider.guide.left = left + 'px';
this.currentSlider.guide.top = top + 'px';
if (this.currentSlider.callLeft) {
this.color[this.currentSlider.callLeft].call(this.color, left / 100);
this.color[this.currentSlider.callLeft].call(this.color, left / this.currentSlider.maxLeft);
}
if (this.currentSlider.callTop) {
this.color[this.currentSlider.callTop].call(this.color, top / 100);
this.color[this.currentSlider.callTop].call(this.color, top / this.currentSlider.maxTop);
}
// Change format dynamically
// Only occurs if user choose the dynamic format by
// setting option format to false
if (this.currentSlider.callTop === 'setAlpha' && this.options.format === false) {
// Converting from hex / rgb to rgba
if (this.color.value.a !== 1) {
this.format = 'rgba';
this.color.origFormat = 'rgba';
}
// Converting from rgba to hex
else {
this.format = 'hex';
this.color.origFormat = 'hex';
}
}
this.update(true);
@ -895,10 +1008,15 @@
e.preventDefault();
$(document).off({
'mousemove.colorpicker': this.mousemove,
'mouseup.colorpicker': this.mouseup
'touchmove.colorpicker': this.mousemove,
'mouseup.colorpicker': this.mouseup,
'touchend.colorpicker': this.mouseup
});
return false;
},
change: function(e) {
this.keyup(e);
},
keyup: function(e) {
if ((e.keyCode === 38)) {
if (this.color.value.a < 1) {
@ -911,8 +1029,13 @@
}
this.update(true);
} else {
var val = this.input.val();
this.color = new Color(val);
this.color = new Color(this.input.val(), this.options.colorSelectors);
// Change format dynamically
// Only occurs if user choose the dynamic format by
// setting option format to false
if (this.color.origFormat && this.options.format === false) {
this.format = this.color.origFormat;
}
if (this.getValue(false) !== false) {
this.updateData();
this.updateComponent();
@ -922,7 +1045,7 @@
this.element.trigger({
type: 'changeColor',
color: this.color,
value: val
value: this.input.val()
});
}
};
@ -930,7 +1053,10 @@
$.colorpicker = Colorpicker;
$.fn.colorpicker = function(option) {
return this.each(function() {
var pickerArgs = arguments,
rv;
var $returnValue = this.each(function() {
var $this = $(this),
inst = $this.data('colorpicker'),
options = ((typeof option === 'object') ? option : {});
@ -938,12 +1064,16 @@
$this.data('colorpicker', new Colorpicker(this, options));
} else {
if (typeof option === 'string') {
inst[option].apply(inst, Array.prototype.slice.call(arguments, 1));
rv = inst[option].apply(inst, Array.prototype.slice.call(pickerArgs, 1));
}
}
});
if (option === 'getValue') {
return rv;
}
return $returnValue;
};
$.fn.colorpicker.constructor = Colorpicker;
})(window.jQuery);
}));

@ -6,4 +6,4 @@
* Licensed under the Apache License v2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
*/.colorpicker-saturation{float:left;width:100px;height:100px;cursor:crosshair;background-image:url("img/saturation.png")}.colorpicker-saturation i{position:absolute;top:0;left:0;display:block;width:5px;height:5px;margin:-4px 0 0 -4px;border:1px solid #000;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.colorpicker-saturation i b{display:block;width:5px;height:5px;border:1px solid #fff;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.colorpicker-hue,.colorpicker-alpha{float:left;width:15px;height:100px;margin-bottom:4px;margin-left:4px;cursor:row-resize}.colorpicker-hue i,.colorpicker-alpha i{position:absolute;top:0;left:0;display:block;width:100%;height:1px;margin-top:-1px;background:#000;border-top:1px solid #fff}.colorpicker-hue{background-image:url("img/hue.png")}.colorpicker-alpha{display:none;background-image:url("img/alpha.png")}.colorpicker{top:0;left:0;z-index:2500;min-width:130px;padding:4px;margin-top:1px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*zoom:1}.colorpicker:before,.colorpicker:after{display:table;line-height:0;content:""}.colorpicker:after{clear:both}.colorpicker:before{position:absolute;top:-7px;left:6px;display:inline-block;border-right:7px solid transparent;border-bottom:7px solid #ccc;border-left:7px solid transparent;border-bottom-color:rgba(0,0,0,0.2);content:''}.colorpicker:after{position:absolute;top:-6px;left:7px;display:inline-block;border-right:6px solid transparent;border-bottom:6px solid #fff;border-left:6px solid transparent;content:''}.colorpicker div{position:relative}.colorpicker.colorpicker-with-alpha{min-width:140px}.colorpicker.colorpicker-with-alpha .colorpicker-alpha{display:block}.colorpicker-color{height:10px;margin-top:5px;clear:both;background-image:url("img/alpha.png");background-position:0 100%}.colorpicker-color div{height:10px}.colorpicker-element .input-group-addon i{display:block;width:16px;height:16px;cursor:pointer}.colorpicker.colorpicker-inline{position:relative;display:inline-block;float:none}.colorpicker.colorpicker-horizontal{width:110px;height:auto;min-width:110px}.colorpicker.colorpicker-horizontal .colorpicker-saturation{margin-bottom:4px}.colorpicker.colorpicker-horizontal .colorpicker-color{width:100px}.colorpicker.colorpicker-horizontal .colorpicker-hue,.colorpicker.colorpicker-horizontal .colorpicker-alpha{float:left;width:100px;height:15px;margin-bottom:4px;margin-left:0;cursor:col-resize}.colorpicker.colorpicker-horizontal .colorpicker-hue i,.colorpicker.colorpicker-horizontal .colorpicker-alpha i{position:absolute;top:0;left:0;display:block;width:1px;height:15px;margin-top:0;background:#fff;border:0}.colorpicker.colorpicker-horizontal .colorpicker-hue{background-image:url("img/hue-horizontal.png")}.colorpicker.colorpicker-horizontal .colorpicker-alpha{background-image:url("img/alpha-horizontal.png")}.colorpicker.colorpicker-hidden{display:none}.colorpicker.colorpicker-visible{display:block}.colorpicker-inline.colorpicker-visible{display:inline-block}
*/.colorpicker-saturation{float:left;width:100px;height:100px;cursor:crosshair;background-image:url("img/saturation.png")}.colorpicker-saturation i{position:absolute;top:0;left:0;display:block;width:5px;height:5px;margin:-4px 0 0 -4px;border:1px solid #000;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.colorpicker-saturation i b{display:block;width:5px;height:5px;border:1px solid #fff;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.colorpicker-hue,.colorpicker-alpha{float:left;width:15px;height:100px;margin-bottom:4px;margin-left:4px;cursor:row-resize}.colorpicker-hue i,.colorpicker-alpha i{position:absolute;top:0;left:0;display:block;width:100%;height:1px;margin-top:-1px;background:#000;border-top:1px solid #fff}.colorpicker-hue{background-image:url("img/hue.png")}.colorpicker-alpha{display:none;background-image:url("img/alpha.png")}.colorpicker-saturation,.colorpicker-hue,.colorpicker-alpha{background-size:contain}.colorpicker{top:0;left:0;z-index:2500;min-width:130px;padding:4px;margin-top:1px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*zoom:1}.colorpicker:before,.colorpicker:after{display:table;line-height:0;content:""}.colorpicker:after{clear:both}.colorpicker:before{position:absolute;top:-7px;left:6px;display:inline-block;border-right:7px solid transparent;border-bottom:7px solid #ccc;border-left:7px solid transparent;border-bottom-color:rgba(0,0,0,0.2);content:''}.colorpicker:after{position:absolute;top:-6px;left:7px;display:inline-block;border-right:6px solid transparent;border-bottom:6px solid #fff;border-left:6px solid transparent;content:''}.colorpicker div{position:relative}.colorpicker.colorpicker-with-alpha{min-width:140px}.colorpicker.colorpicker-with-alpha .colorpicker-alpha{display:block}.colorpicker-color{height:10px;margin-top:5px;clear:both;background-image:url("img/alpha.png");background-position:0 100%}.colorpicker-color div{height:10px}.colorpicker-selectors{display:none;height:10px;margin-top:5px;clear:both}.colorpicker-selectors i{float:left;width:10px;height:10px;cursor:pointer}.colorpicker-selectors i+i{margin-left:3px}.colorpicker-element .input-group-addon i,.colorpicker-element .add-on i{display:inline-block;width:16px;height:16px;vertical-align:text-top;cursor:pointer}.colorpicker.colorpicker-inline{position:relative;z-index:auto;display:inline-block;float:none}.colorpicker.colorpicker-horizontal{width:110px;height:auto;min-width:110px}.colorpicker.colorpicker-horizontal .colorpicker-saturation{margin-bottom:4px}.colorpicker.colorpicker-horizontal .colorpicker-color{width:100px}.colorpicker.colorpicker-horizontal .colorpicker-hue,.colorpicker.colorpicker-horizontal .colorpicker-alpha{float:left;width:100px;height:15px;margin-bottom:4px;margin-left:0;cursor:col-resize}.colorpicker.colorpicker-horizontal .colorpicker-hue i,.colorpicker.colorpicker-horizontal .colorpicker-alpha i{position:absolute;top:0;left:0;display:block;width:1px;height:15px;margin-top:0;background:#fff;border:0}.colorpicker.colorpicker-horizontal .colorpicker-hue{background-image:url("img/hue-horizontal.png")}.colorpicker.colorpicker-horizontal .colorpicker-alpha{background-image:url("img/alpha-horizontal.png")}.colorpicker.colorpicker-hidden{display:none}.colorpicker.colorpicker-visible{display:block}.colorpicker-inline.colorpicker-visible{display:inline-block}.colorpicker-right:before{right:6px;left:auto}.colorpicker-right:after{right:7px;left:auto}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Loading…
Cancel
Save