jquery-colorpicker-rails 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/lib/jquery-colorpicker-rails.rb +10 -0
- data/lib/jquery-colorpicker-rails/version.rb +7 -0
- data/vendor/assets/images/bar-alpha.png +0 -0
- data/vendor/assets/images/bar-opacity.png +0 -0
- data/vendor/assets/images/bar-pointer.png +0 -0
- data/vendor/assets/images/bar.png +0 -0
- data/vendor/assets/images/map-opacity.png +0 -0
- data/vendor/assets/images/map-pointer.png +0 -0
- data/vendor/assets/images/map.png +0 -0
- data/vendor/assets/images/preview-opacity.png +0 -0
- data/vendor/assets/images/ui-colorpicker.png +0 -0
- data/vendor/assets/javascripts/colorpicker.js +2684 -0
- data/vendor/assets/javascripts/i18n/jquery.ui.colorpicker-de.js +27 -0
- data/vendor/assets/javascripts/i18n/jquery.ui.colorpicker-en.js +27 -0
- data/vendor/assets/javascripts/i18n/jquery.ui.colorpicker-fr.js +27 -0
- data/vendor/assets/javascripts/i18n/jquery.ui.colorpicker-nl.js +27 -0
- data/vendor/assets/javascripts/i18n/jquery.ui.colorpicker-pt-br.js +27 -0
- data/vendor/assets/javascripts/jquery-colorpicker.js +8 -0
- data/vendor/assets/javascripts/parsers/jquery.ui.colorpicker-cmyk-parser.js +13 -0
- data/vendor/assets/javascripts/parsers/jquery.ui.colorpicker-cmyk-percentage-parser.js +13 -0
- data/vendor/assets/javascripts/parts/jquery.ui.colorpicker-memory.js +64 -0
- data/vendor/assets/javascripts/parts/jquery.ui.colorpicker-rgbslider.js +81 -0
- data/vendor/assets/javascripts/swatches/jquery.ui.colorpicker-crayola.js +124 -0
- data/vendor/assets/javascripts/swatches/jquery.ui.colorpicker-pantone.js +941 -0
- data/vendor/assets/javascripts/swatches/jquery.ui.colorpicker-ral-classic.js +217 -0
- data/vendor/assets/stylesheets/jquery.colorpicker.css +198 -0
- metadata +89 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bogdan Frankovskiy
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Jquery::Colorpicker::Rails
|
2
|
+
|
3
|
+
Gem for https://github.com/vanderlee/colorpicker/ for using into rails apps
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jquery-colorpicker-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jquery-colorpicker-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add
|
22
|
+
require jquery.ui.all
|
23
|
+
require jquery.colorpicke
|
24
|
+
to your application.js file
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,2684 @@
|
|
1
|
+
/*jslint devel: true, bitwise: true, regexp: true, browser: true, confusion: true, unparam: true, eqeq: true, white: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */
|
2
|
+
/*globals jQuery,Color */
|
3
|
+
|
4
|
+
/*
|
5
|
+
* ColorPicker
|
6
|
+
*
|
7
|
+
* Copyright (c) 2011-2013 Martijn W. van der Lee
|
8
|
+
* Licensed under the MIT.
|
9
|
+
*
|
10
|
+
* Full-featured colorpicker for jQueryUI with full theming support.
|
11
|
+
* Most images from jPicker by Christopher T. Tillman.
|
12
|
+
* Sourcecode created from scratch by Martijn W. van der Lee.
|
13
|
+
*/
|
14
|
+
|
15
|
+
;(function ($) {
|
16
|
+
"use strict";
|
17
|
+
|
18
|
+
var _colorpicker_index = 0,
|
19
|
+
|
20
|
+
_container_popup = '<div class="ui-colorpicker ui-colorpicker-dialog ui-dialog ui-widget ui-widget-content ui-corner-all" style="display: none;"></div>',
|
21
|
+
_container_inlineFrame = '<div class="ui-colorpicker ui-colorpicker-inline ui-dialog ui-widget ui-widget-content ui-corner-all"></div>',
|
22
|
+
_container_inline = '<div class="ui-colorpicker ui-colorpicker-inline"></div>',
|
23
|
+
|
24
|
+
_intToHex = function (dec) {
|
25
|
+
var result = Math.floor(dec).toString(16);
|
26
|
+
if (result.length === 1) {
|
27
|
+
result = ('0' + result);
|
28
|
+
}
|
29
|
+
return result.toLowerCase();
|
30
|
+
},
|
31
|
+
|
32
|
+
_parseHex = function(color) {
|
33
|
+
var c,
|
34
|
+
m;
|
35
|
+
|
36
|
+
// {#}rrggbb
|
37
|
+
m = /^#?([a-fA-F0-9]{1,6})$/.exec(color);
|
38
|
+
if (m) {
|
39
|
+
c = parseInt(m[1], 16);
|
40
|
+
return new $.colorpicker.Color(
|
41
|
+
((c >> 16) & 0xFF) / 255,
|
42
|
+
((c >> 8) & 0xFF) / 255,
|
43
|
+
(c & 0xFF) / 255
|
44
|
+
);
|
45
|
+
}
|
46
|
+
|
47
|
+
return new $.colorpicker.Color();
|
48
|
+
},
|
49
|
+
|
50
|
+
_layoutTable = function(layout, callback) {
|
51
|
+
var bitmap,
|
52
|
+
x,
|
53
|
+
y,
|
54
|
+
width, height,
|
55
|
+
columns, rows,
|
56
|
+
index,
|
57
|
+
cell,
|
58
|
+
html,
|
59
|
+
w,
|
60
|
+
h,
|
61
|
+
colspan,
|
62
|
+
walked;
|
63
|
+
|
64
|
+
layout.sort(function(a, b) {
|
65
|
+
if (a.pos[1] == b.pos[1]) {
|
66
|
+
return a.pos[0] - b.pos[0];
|
67
|
+
}
|
68
|
+
return a.pos[1] - b.pos[1];
|
69
|
+
});
|
70
|
+
|
71
|
+
// Determine dimensions of the table
|
72
|
+
width = 0;
|
73
|
+
height = 0;
|
74
|
+
$.each (layout, function(index, part) {
|
75
|
+
width = Math.max(width, part.pos[0] + part.pos[2]);
|
76
|
+
height = Math.max(height, part.pos[1] + part.pos[3]);
|
77
|
+
});
|
78
|
+
|
79
|
+
// Initialize bitmap
|
80
|
+
bitmap = [];
|
81
|
+
for (x = 0; x < width; ++x) {
|
82
|
+
bitmap.push([]);
|
83
|
+
}
|
84
|
+
|
85
|
+
// Mark rows and columns which have layout assigned
|
86
|
+
rows = [];
|
87
|
+
columns = [];
|
88
|
+
$.each(layout, function(index, part) {
|
89
|
+
// mark columns
|
90
|
+
for (x = 0; x < part.pos[2]; x += 1) {
|
91
|
+
columns[part.pos[0] + x] = true;
|
92
|
+
}
|
93
|
+
for (y = 0; y < part.pos[3]; y += 1) {
|
94
|
+
rows[part.pos[1] + y] = true;
|
95
|
+
}
|
96
|
+
});
|
97
|
+
|
98
|
+
// Generate the table
|
99
|
+
html = '';
|
100
|
+
cell = layout[index = 0];
|
101
|
+
for (y = 0; y < height; ++y) {
|
102
|
+
html += '<tr>';
|
103
|
+
x = 0;
|
104
|
+
while (x < width) {
|
105
|
+
if (typeof cell !== 'undefined' && x == cell.pos[0] && y == cell.pos[1]) {
|
106
|
+
// Create a "real" cell
|
107
|
+
html += callback(cell, x, y);
|
108
|
+
|
109
|
+
for (h = 0; h < cell.pos[3]; h +=1) {
|
110
|
+
for (w = 0; w < cell.pos[2]; w +=1) {
|
111
|
+
bitmap[x + w][y + h] = true;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
x += cell.pos[2];
|
116
|
+
cell = layout[++index];
|
117
|
+
} else {
|
118
|
+
// Fill in the gaps
|
119
|
+
colspan = 0;
|
120
|
+
walked = false;
|
121
|
+
|
122
|
+
while (x < width && bitmap[x][y] === undefined && (cell === undefined || y < cell.pos[1] || (y == cell.pos[1] && x < cell.pos[0]))) {
|
123
|
+
if (columns[x] === true) {
|
124
|
+
colspan += 1;
|
125
|
+
}
|
126
|
+
walked = true;
|
127
|
+
x += 1;
|
128
|
+
}
|
129
|
+
|
130
|
+
if (colspan > 0) {
|
131
|
+
html += '<td colspan="'+colspan+'"></td>';
|
132
|
+
} else if (!walked) {
|
133
|
+
x += 1;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
html += '</tr>';
|
138
|
+
}
|
139
|
+
|
140
|
+
return '<table cellspacing="0" cellpadding="0" border="0"><tbody>' + html + '</tbody></table>';
|
141
|
+
};
|
142
|
+
|
143
|
+
$.colorpicker = new function() {
|
144
|
+
this.regional = {
|
145
|
+
'': {
|
146
|
+
ok: 'OK',
|
147
|
+
cancel: 'Cancel',
|
148
|
+
none: 'None',
|
149
|
+
button: 'Color',
|
150
|
+
title: 'Pick a color',
|
151
|
+
transparent: 'Transparent',
|
152
|
+
hsvH: 'H',
|
153
|
+
hsvS: 'S',
|
154
|
+
hsvV: 'V',
|
155
|
+
rgbR: 'R',
|
156
|
+
rgbG: 'G',
|
157
|
+
rgbB: 'B',
|
158
|
+
labL: 'L',
|
159
|
+
labA: 'a',
|
160
|
+
labB: 'b',
|
161
|
+
hslH: 'H',
|
162
|
+
hslS: 'S',
|
163
|
+
hslL: 'L',
|
164
|
+
cmykC: 'C',
|
165
|
+
cmykM: 'M',
|
166
|
+
cmykY: 'Y',
|
167
|
+
cmykK: 'K',
|
168
|
+
alphaA: 'A'
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
this.swatches = {
|
173
|
+
'html': {
|
174
|
+
'black': {r: 0, g: 0, b: 0},
|
175
|
+
'dimgray': {r: 0.4117647058823529, g: 0.4117647058823529, b: 0.4117647058823529},
|
176
|
+
'gray': {r: 0.5019607843137255, g: 0.5019607843137255, b: 0.5019607843137255},
|
177
|
+
'darkgray': {r: 0.6627450980392157, g: 0.6627450980392157, b: 0.6627450980392157},
|
178
|
+
'silver': {r: 0.7529411764705882, g: 0.7529411764705882, b: 0.7529411764705882},
|
179
|
+
'lightgrey': {r: 0.8274509803921568, g: 0.8274509803921568, b: 0.8274509803921568},
|
180
|
+
'gainsboro': {r: 0.8627450980392157, g: 0.8627450980392157, b: 0.8627450980392157},
|
181
|
+
'whitesmoke': {r: 0.9607843137254902, g: 0.9607843137254902, b: 0.9607843137254902},
|
182
|
+
'white': {r: 1, g: 1, b: 1},
|
183
|
+
'rosybrown': {r: 0.7372549019607844, g: 0.5607843137254902, b: 0.5607843137254902},
|
184
|
+
'indianred': {r: 0.803921568627451, g: 0.3607843137254902, b: 0.3607843137254902},
|
185
|
+
'brown': {r: 0.6470588235294118, g: 0.16470588235294117, b: 0.16470588235294117},
|
186
|
+
'firebrick': {r: 0.6980392156862745, g: 0.13333333333333333, b: 0.13333333333333333},
|
187
|
+
'lightcoral': {r: 0.9411764705882353, g: 0.5019607843137255, b: 0.5019607843137255},
|
188
|
+
'maroon': {r: 0.5019607843137255, g: 0, b: 0},
|
189
|
+
'darkred': {r: 0.5450980392156862, g: 0, b: 0},
|
190
|
+
'red': {r: 1, g: 0, b: 0},
|
191
|
+
'snow': {r: 1, g: 0.9803921568627451, b: 0.9803921568627451},
|
192
|
+
'salmon': {r: 0.9803921568627451, g: 0.5019607843137255, b: 0.4470588235294118},
|
193
|
+
'mistyrose': {r: 1, g: 0.8941176470588236, b: 0.8823529411764706},
|
194
|
+
'tomato': {r: 1, g: 0.38823529411764707, b: 0.2784313725490196},
|
195
|
+
'darksalmon': {r: 0.9137254901960784, g: 0.5882352941176471, b: 0.47843137254901963},
|
196
|
+
'orangered': {r: 1, g: 0.27058823529411763, b: 0},
|
197
|
+
'coral': {r: 1, g: 0.4980392156862745, b: 0.3137254901960784},
|
198
|
+
'lightsalmon': {r: 1, g: 0.6274509803921569, b: 0.47843137254901963},
|
199
|
+
'sienna': {r: 0.6274509803921569, g: 0.3215686274509804, b: 0.17647058823529413},
|
200
|
+
'seashell': {r: 1, g: 0.9607843137254902, b: 0.9333333333333333},
|
201
|
+
'chocolate': {r: 0.8235294117647058, g: 0.4117647058823529, b: 0.11764705882352941},
|
202
|
+
'saddlebrown': {r: 0.5450980392156862, g: 0.27058823529411763, b: 0.07450980392156863},
|
203
|
+
'sandybrown': {r: 0.9568627450980393, g: 0.6431372549019608, b: 0.3764705882352941},
|
204
|
+
'peachpuff': {r: 1, g: 0.8549019607843137, b: 0.7254901960784313},
|
205
|
+
'peru': {r: 0.803921568627451, g: 0.5215686274509804, b: 0.24705882352941178},
|
206
|
+
'linen': {r: 0.9803921568627451, g: 0.9411764705882353, b: 0.9019607843137255},
|
207
|
+
'darkorange': {r: 1, g: 0.5490196078431373, b: 0},
|
208
|
+
'bisque': {r: 1, g: 0.8941176470588236, b: 0.7686274509803922},
|
209
|
+
'burlywood': {r: 0.8705882352941177, g: 0.7215686274509804, b: 0.5294117647058824},
|
210
|
+
'tan': {r: 0.8235294117647058, g: 0.7058823529411765, b: 0.5490196078431373},
|
211
|
+
'antiquewhite': {r: 0.9803921568627451, g: 0.9215686274509803, b: 0.8431372549019608},
|
212
|
+
'navajowhite': {r: 1, g: 0.8705882352941177, b: 0.6784313725490196},
|
213
|
+
'blanchedalmond': {r: 1, g: 0.9215686274509803, b: 0.803921568627451},
|
214
|
+
'papayawhip': {r: 1, g: 0.9372549019607843, b: 0.8352941176470589},
|
215
|
+
'orange': {r: 1, g: 0.6470588235294118, b: 0},
|
216
|
+
'moccasin': {r: 1, g: 0.8941176470588236, b: 0.7098039215686275},
|
217
|
+
'wheat': {r: 0.9607843137254902, g: 0.8705882352941177, b: 0.7019607843137254},
|
218
|
+
'oldlace': {r: 0.9921568627450981, g: 0.9607843137254902, b: 0.9019607843137255},
|
219
|
+
'floralwhite': {r: 1, g: 0.9803921568627451, b: 0.9411764705882353},
|
220
|
+
'goldenrod': {r: 0.8549019607843137, g: 0.6470588235294118, b: 0.12549019607843137},
|
221
|
+
'darkgoldenrod': {r: 0.7215686274509804, g: 0.5254901960784314, b: 0.043137254901960784},
|
222
|
+
'cornsilk': {r: 1, g: 0.9725490196078431, b: 0.8627450980392157},
|
223
|
+
'gold': {r: 1, g: 0.8431372549019608, b: 0},
|
224
|
+
'palegoldenrod': {r: 0.9333333333333333, g: 0.9098039215686274, b: 0.6666666666666666},
|
225
|
+
'khaki': {r: 0.9411764705882353, g: 0.9019607843137255, b: 0.5490196078431373},
|
226
|
+
'lemonchiffon': {r: 1, g: 0.9803921568627451, b: 0.803921568627451},
|
227
|
+
'darkkhaki': {r: 0.7411764705882353, g: 0.7176470588235294, b: 0.4196078431372549},
|
228
|
+
'beige': {r: 0.9607843137254902, g: 0.9607843137254902, b: 0.8627450980392157},
|
229
|
+
'lightgoldenrodyellow': {r: 0.9803921568627451, g: 0.9803921568627451, b: 0.8235294117647058},
|
230
|
+
'olive': {r: 0.5019607843137255, g: 0.5019607843137255, b: 0},
|
231
|
+
'yellow': {r: 1, g: 1, b: 0},
|
232
|
+
'lightyellow': {r: 1, g: 1, b: 0.8784313725490196},
|
233
|
+
'ivory': {r: 1, g: 1, b: 0.9411764705882353},
|
234
|
+
'olivedrab': {r: 0.4196078431372549, g: 0.5568627450980392, b: 0.13725490196078433},
|
235
|
+
'yellowgreen': {r: 0.6039215686274509, g: 0.803921568627451, b: 0.19607843137254902},
|
236
|
+
'darkolivegreen': {r: 0.3333333333333333, g: 0.4196078431372549, b: 0.1843137254901961},
|
237
|
+
'greenyellow': {r: 0.6784313725490196, g: 1, b: 0.1843137254901961},
|
238
|
+
'lawngreen': {r: 0.48627450980392156, g: 0.9882352941176471, b: 0},
|
239
|
+
'chartreuse': {r: 0.4980392156862745, g: 1, b: 0},
|
240
|
+
'darkseagreen': {r: 0.5607843137254902, g: 0.7372549019607844, b: 0.5607843137254902},
|
241
|
+
'forestgreen': {r: 0.13333333333333333, g: 0.5450980392156862, b: 0.13333333333333333},
|
242
|
+
'limegreen': {r: 0.19607843137254902, g: 0.803921568627451, b: 0.19607843137254902},
|
243
|
+
'lightgreen': {r: 0.5647058823529412, g: 0.9333333333333333, b: 0.5647058823529412},
|
244
|
+
'palegreen': {r: 0.596078431372549, g: 0.984313725490196, b: 0.596078431372549},
|
245
|
+
'darkgreen': {r: 0, g: 0.39215686274509803, b: 0},
|
246
|
+
'green': {r: 0, g: 0.5019607843137255, b: 0},
|
247
|
+
'lime': {r: 0, g: 1, b: 0},
|
248
|
+
'honeydew': {r: 0.9411764705882353, g: 1, b: 0.9411764705882353},
|
249
|
+
'mediumseagreen': {r: 0.23529411764705882, g: 0.7019607843137254, b: 0.44313725490196076},
|
250
|
+
'seagreen': {r: 0.1803921568627451, g: 0.5450980392156862, b: 0.3411764705882353},
|
251
|
+
'springgreen': {r: 0, g: 1, b: 0.4980392156862745},
|
252
|
+
'mintcream': {r: 0.9607843137254902, g: 1, b: 0.9803921568627451},
|
253
|
+
'mediumspringgreen': {r: 0, g: 0.9803921568627451, b: 0.6039215686274509},
|
254
|
+
'mediumaquamarine': {r: 0.4, g: 0.803921568627451, b: 0.6666666666666666},
|
255
|
+
'aquamarine': {r: 0.4980392156862745, g: 1, b: 0.8313725490196079},
|
256
|
+
'turquoise': {r: 0.25098039215686274, g: 0.8784313725490196, b: 0.8156862745098039},
|
257
|
+
'lightseagreen': {r: 0.12549019607843137, g: 0.6980392156862745, b: 0.6666666666666666},
|
258
|
+
'mediumturquoise': {r: 0.2823529411764706, g: 0.8196078431372549, b: 0.8},
|
259
|
+
'darkslategray': {r: 0.1843137254901961, g: 0.30980392156862746, b: 0.30980392156862746},
|
260
|
+
'paleturquoise': {r: 0.6862745098039216, g: 0.9333333333333333, b: 0.9333333333333333},
|
261
|
+
'teal': {r: 0, g: 0.5019607843137255, b: 0.5019607843137255},
|
262
|
+
'darkcyan': {r: 0, g: 0.5450980392156862, b: 0.5450980392156862},
|
263
|
+
'darkturquoise': {r: 0, g: 0.807843137254902, b: 0.8196078431372549},
|
264
|
+
'aqua': {r: 0, g: 1, b: 1},
|
265
|
+
'cyan': {r: 0, g: 1, b: 1},
|
266
|
+
'lightcyan': {r: 0.8784313725490196, g: 1, b: 1},
|
267
|
+
'azure': {r: 0.9411764705882353, g: 1, b: 1},
|
268
|
+
'cadetblue': {r: 0.37254901960784315, g: 0.6196078431372549, b: 0.6274509803921569},
|
269
|
+
'powderblue': {r: 0.6901960784313725, g: 0.8784313725490196, b: 0.9019607843137255},
|
270
|
+
'lightblue': {r: 0.6784313725490196, g: 0.8470588235294118, b: 0.9019607843137255},
|
271
|
+
'deepskyblue': {r: 0, g: 0.7490196078431373, b: 1},
|
272
|
+
'skyblue': {r: 0.5294117647058824, g: 0.807843137254902, b: 0.9215686274509803},
|
273
|
+
'lightskyblue': {r: 0.5294117647058824, g: 0.807843137254902, b: 0.9803921568627451},
|
274
|
+
'steelblue': {r: 0.27450980392156865, g: 0.5098039215686274, b: 0.7058823529411765},
|
275
|
+
'aliceblue': {r: 0.9411764705882353, g: 0.9725490196078431, b: 1},
|
276
|
+
'dodgerblue': {r: 0.11764705882352941, g: 0.5647058823529412, b: 1},
|
277
|
+
'slategray': {r: 0.4392156862745098, g: 0.5019607843137255, b: 0.5647058823529412},
|
278
|
+
'lightslategray': {r: 0.4666666666666667, g: 0.5333333333333333, b: 0.6},
|
279
|
+
'lightsteelblue': {r: 0.6901960784313725, g: 0.7686274509803922, b: 0.8705882352941177},
|
280
|
+
'cornflowerblue': {r: 0.39215686274509803, g: 0.5843137254901961, b: 0.9294117647058824},
|
281
|
+
'royalblue': {r: 0.2549019607843137, g: 0.4117647058823529, b: 0.8823529411764706},
|
282
|
+
'midnightblue': {r: 0.09803921568627451, g: 0.09803921568627451, b: 0.4392156862745098},
|
283
|
+
'lavender': {r: 0.9019607843137255, g: 0.9019607843137255, b: 0.9803921568627451},
|
284
|
+
'navy': {r: 0, g: 0, b: 0.5019607843137255},
|
285
|
+
'darkblue': {r: 0, g: 0, b: 0.5450980392156862},
|
286
|
+
'mediumblue': {r: 0, g: 0, b: 0.803921568627451},
|
287
|
+
'blue': {r: 0, g: 0, b: 1},
|
288
|
+
'ghostwhite': {r: 0.9725490196078431, g: 0.9725490196078431, b: 1},
|
289
|
+
'darkslateblue': {r: 0.2823529411764706, g: 0.23921568627450981, b: 0.5450980392156862},
|
290
|
+
'slateblue': {r: 0.41568627450980394, g: 0.35294117647058826, b: 0.803921568627451},
|
291
|
+
'mediumslateblue': {r: 0.4823529411764706, g: 0.40784313725490196, b: 0.9333333333333333},
|
292
|
+
'mediumpurple': {r: 0.5764705882352941, g: 0.4392156862745098, b: 0.8588235294117647},
|
293
|
+
'blueviolet': {r: 0.5411764705882353, g: 0.16862745098039217, b: 0.8862745098039215},
|
294
|
+
'indigo': {r: 0.29411764705882354, g: 0, b: 0.5098039215686274},
|
295
|
+
'darkorchid': {r: 0.6, g: 0.19607843137254902, b: 0.8},
|
296
|
+
'darkviolet': {r: 0.5803921568627451, g: 0, b: 0.8274509803921568},
|
297
|
+
'mediumorchid': {r: 0.7294117647058823, g: 0.3333333333333333, b: 0.8274509803921568},
|
298
|
+
'thistle': {r: 0.8470588235294118, g: 0.7490196078431373, b: 0.8470588235294118},
|
299
|
+
'plum': {r: 0.8666666666666667, g: 0.6274509803921569, b: 0.8666666666666667},
|
300
|
+
'violet': {r: 0.9333333333333333, g: 0.5098039215686274, b: 0.9333333333333333},
|
301
|
+
'purple': {r: 0.5019607843137255, g: 0, b: 0.5019607843137255},
|
302
|
+
'darkmagenta': {r: 0.5450980392156862, g: 0, b: 0.5450980392156862},
|
303
|
+
'magenta': {r: 1, g: 0, b: 1},
|
304
|
+
'fuchsia': {r: 1, g: 0, b: 1},
|
305
|
+
'orchid': {r: 0.8549019607843137, g: 0.4392156862745098, b: 0.8392156862745098},
|
306
|
+
'mediumvioletred': {r: 0.7803921568627451, g: 0.08235294117647059, b: 0.5215686274509804},
|
307
|
+
'deeppink': {r: 1, g: 0.0784313725490196, b: 0.5764705882352941},
|
308
|
+
'hotpink': {r: 1, g: 0.4117647058823529, b: 0.7058823529411765},
|
309
|
+
'palevioletred': {r: 0.8588235294117647, g: 0.4392156862745098, b: 0.5764705882352941},
|
310
|
+
'lavenderblush': {r: 1, g: 0.9411764705882353, b: 0.9607843137254902},
|
311
|
+
'crimson': {r: 0.8627450980392157, g: 0.0784313725490196, b: 0.23529411764705882},
|
312
|
+
'pink': {r: 1, g: 0.7529411764705882, b: 0.796078431372549},
|
313
|
+
'lightpink': {r: 1, g: 0.7137254901960784, b: 0.7568627450980392}
|
314
|
+
}
|
315
|
+
};
|
316
|
+
|
317
|
+
this.writers = {
|
318
|
+
'#HEX': function(color, that) {
|
319
|
+
return that._formatColor('#rxgxbx', color);
|
320
|
+
}
|
321
|
+
, '#HEX3': function(color, that) {
|
322
|
+
var hex3 = $.colorpicker.writers.HEX3(color);
|
323
|
+
return hex3 === false? false : '#'+hex3;
|
324
|
+
}
|
325
|
+
, 'HEX': function(color, that) {
|
326
|
+
return that._formatColor('rxgxbx', color);
|
327
|
+
}
|
328
|
+
, 'HEX3': function(color, that) {
|
329
|
+
var rgb = color.getRGB(),
|
330
|
+
r = Math.floor(rgb.r * 255),
|
331
|
+
g = Math.floor(rgb.g * 255),
|
332
|
+
b = Math.floor(rgb.b * 255);
|
333
|
+
|
334
|
+
if (((r >>> 4) == (r &= 0xf))
|
335
|
+
&& ((g >>> 4) == (g &= 0xf))
|
336
|
+
&& ((b >>> 4) == (b &= 0xf))) {
|
337
|
+
return r.toString(16)+g.toString(16)+b.toString(16);
|
338
|
+
}
|
339
|
+
return false;
|
340
|
+
}
|
341
|
+
, 'RGB': function(color, that) {
|
342
|
+
return color.getAlpha() >= 1
|
343
|
+
? that._formatColor('rgb(rd,gd,bd)', color)
|
344
|
+
: false;
|
345
|
+
}
|
346
|
+
, 'RGBA': function(color, that) {
|
347
|
+
return that._formatColor('rgba(rd,gd,bd,af)', color);
|
348
|
+
}
|
349
|
+
, 'RGB%': function(color, that) {
|
350
|
+
return color.getAlpha() >= 1
|
351
|
+
? that._formatColor('rgb(rp%,gp%,bp%)', color)
|
352
|
+
: false;
|
353
|
+
}
|
354
|
+
, 'RGBA%': function(color, that) {
|
355
|
+
return that._formatColor('rgba(rp%,gp%,bp%,af)', color);
|
356
|
+
}
|
357
|
+
, 'HSL': function(color, that) {
|
358
|
+
return color.getAlpha() >= 1
|
359
|
+
? that._formatColor('hsl(hd,sd,vd)', color)
|
360
|
+
: false;
|
361
|
+
}
|
362
|
+
, 'HSLA': function(color, that) {
|
363
|
+
return that._formatColor('hsla(hd,sd,vd,af)', color);
|
364
|
+
}
|
365
|
+
, 'HSL%': function(color, that) {
|
366
|
+
return color.getAlpha() >= 1
|
367
|
+
? that._formatColor('hsl(hp%,sp%,vp%)', color)
|
368
|
+
: false;
|
369
|
+
}
|
370
|
+
, 'HSLA%': function(color, that) {
|
371
|
+
return that._formatColor('hsla(hp%,sp%,vp%,af)', color);
|
372
|
+
}
|
373
|
+
, 'NAME': function(color, that) {
|
374
|
+
return that._closestName(color);
|
375
|
+
}
|
376
|
+
, 'EXACT': function(color, that) { //@todo experimental. Implement a good fallback list
|
377
|
+
return that._exactName(color);
|
378
|
+
}
|
379
|
+
};
|
380
|
+
|
381
|
+
this.parsers = {
|
382
|
+
'': function(color) {
|
383
|
+
if (color == '') {
|
384
|
+
return new $.colorpicker.Color();
|
385
|
+
}
|
386
|
+
}
|
387
|
+
, 'NAME': function(color, that) {
|
388
|
+
var c = that._getSwatch($.trim(color));
|
389
|
+
if (c) {
|
390
|
+
return new $.colorpicker.Color(c.r, c.g, c.b);
|
391
|
+
}
|
392
|
+
}
|
393
|
+
, 'RGBA': function(color) {
|
394
|
+
var m = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(color);
|
395
|
+
if (m) {
|
396
|
+
return new $.colorpicker.Color(
|
397
|
+
m[1] / 255,
|
398
|
+
m[2] / 255,
|
399
|
+
m[3] / 255,
|
400
|
+
parseFloat(m[4])
|
401
|
+
);
|
402
|
+
}
|
403
|
+
}
|
404
|
+
, 'RGBA%': function(color) {
|
405
|
+
var m = /^rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(color);
|
406
|
+
if (m) {
|
407
|
+
return new $.colorpicker.Color(
|
408
|
+
m[1] / 100,
|
409
|
+
m[2] / 100,
|
410
|
+
m[3] / 100,
|
411
|
+
m[4] / 100
|
412
|
+
);
|
413
|
+
}
|
414
|
+
}
|
415
|
+
, 'HSLA': function(color) {
|
416
|
+
var m = /^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(color);
|
417
|
+
if (m) {
|
418
|
+
return (new $.colorpicker.Color()).setHSL(
|
419
|
+
m[1] / 255,
|
420
|
+
m[2] / 255,
|
421
|
+
m[3] / 255).setAlpha(parseFloat(m[4]));
|
422
|
+
}
|
423
|
+
}
|
424
|
+
, 'HSLA%': function(color) {
|
425
|
+
var m = /^hsla?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(color);
|
426
|
+
if (m) {
|
427
|
+
return (new $.colorpicker.Color()).setHSL(
|
428
|
+
m[1] / 100,
|
429
|
+
m[2] / 100,
|
430
|
+
m[3] / 100).setAlpha(m[4] / 100);
|
431
|
+
}
|
432
|
+
}
|
433
|
+
, '#HEX': function(color) {
|
434
|
+
var m = /^#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/.exec(color);
|
435
|
+
if (m) {
|
436
|
+
return new $.colorpicker.Color(
|
437
|
+
parseInt(m[1], 16) / 255,
|
438
|
+
parseInt(m[2], 16) / 255,
|
439
|
+
parseInt(m[3], 16) / 255
|
440
|
+
);
|
441
|
+
}
|
442
|
+
}
|
443
|
+
, '#HEX3': function(color) {
|
444
|
+
var m = /^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/.exec(color);
|
445
|
+
if (m) {
|
446
|
+
return new $.colorpicker.Color(
|
447
|
+
parseInt(m[1] + m[1], 16) / 255,
|
448
|
+
parseInt(m[2] + m[2], 16) / 255,
|
449
|
+
parseInt(m[3] + m[3], 16) / 255
|
450
|
+
);
|
451
|
+
}
|
452
|
+
}
|
453
|
+
, 'HEX': function(color) {
|
454
|
+
var m = /^([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/.exec(color);
|
455
|
+
if (m) {
|
456
|
+
return new $.colorpicker.Color(
|
457
|
+
parseInt(m[1], 16) / 255,
|
458
|
+
parseInt(m[2], 16) / 255,
|
459
|
+
parseInt(m[3], 16) / 255
|
460
|
+
);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
, 'HEX3': function(color) {
|
464
|
+
var m = /^([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/.exec(color);
|
465
|
+
if (m) {
|
466
|
+
return new $.colorpicker.Color(
|
467
|
+
parseInt(m[1] + m[1], 16) / 255,
|
468
|
+
parseInt(m[2] + m[2], 16) / 255,
|
469
|
+
parseInt(m[3] + m[3], 16) / 255
|
470
|
+
);
|
471
|
+
}
|
472
|
+
}
|
473
|
+
};
|
474
|
+
|
475
|
+
this.partslists = {
|
476
|
+
'full': ['header', 'map', 'bar', 'hex', 'hsv', 'rgb', 'alpha', 'lab', 'cmyk', 'preview', 'swatches', 'footer'],
|
477
|
+
'popup': ['map', 'bar', 'hex', 'hsv', 'rgb', 'alpha', 'preview', 'footer'],
|
478
|
+
'draggable': ['header', 'map', 'bar', 'hex', 'hsv', 'rgb', 'alpha', 'preview', 'footer'],
|
479
|
+
'inline': ['map', 'bar', 'hex', 'hsv', 'rgb', 'alpha', 'preview']
|
480
|
+
},
|
481
|
+
|
482
|
+
this.limits = {
|
483
|
+
'websafe': function(color) {
|
484
|
+
color.limit(6);
|
485
|
+
},
|
486
|
+
'nibble': function(color) {
|
487
|
+
color.limit(16);
|
488
|
+
},
|
489
|
+
'binary': function(color) {
|
490
|
+
color.limit(2);
|
491
|
+
},
|
492
|
+
'name': function(color, that) {
|
493
|
+
var swatch = that._getSwatch(that._closestName(color));
|
494
|
+
color.setRGB(swatch.r, swatch.g, swatch.b);
|
495
|
+
}
|
496
|
+
},
|
497
|
+
|
498
|
+
this.parts = {
|
499
|
+
header: function (inst) {
|
500
|
+
var that = this,
|
501
|
+
e = null,
|
502
|
+
_html =function() {
|
503
|
+
var title = inst.options.title || inst._getRegional('title'),
|
504
|
+
html = '<span class="ui-dialog-title">' + title + '</span>';
|
505
|
+
|
506
|
+
if (!inst.inline && inst.options.showCloseButton) {
|
507
|
+
html += '<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button">'
|
508
|
+
+ '<span class="ui-icon ui-icon-closethick">close</span></a>';
|
509
|
+
}
|
510
|
+
|
511
|
+
return '<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">' + html + '</div>';
|
512
|
+
};
|
513
|
+
|
514
|
+
this.init = function() {
|
515
|
+
e = $(_html()).prependTo(inst.dialog);
|
516
|
+
|
517
|
+
var close = $('.ui-dialog-titlebar-close', e);
|
518
|
+
inst._hoverable(close);
|
519
|
+
inst._focusable(close);
|
520
|
+
close.click(function(event) {
|
521
|
+
event.preventDefault();
|
522
|
+
inst.close(inst.options.revert);
|
523
|
+
});
|
524
|
+
|
525
|
+
if (!inst.inline && inst.options.draggable) {
|
526
|
+
inst.dialog.draggable({
|
527
|
+
handle: e
|
528
|
+
});
|
529
|
+
}
|
530
|
+
};
|
531
|
+
},
|
532
|
+
|
533
|
+
map: function (inst) {
|
534
|
+
var that = this,
|
535
|
+
e = null,
|
536
|
+
mousemove_timeout = null,
|
537
|
+
_mousedown, _mouseup, _mousemove, _html;
|
538
|
+
|
539
|
+
_mousedown = function (event) {
|
540
|
+
if (!inst.opened) {
|
541
|
+
return;
|
542
|
+
}
|
543
|
+
|
544
|
+
var div = $('.ui-colorpicker-map-layer-pointer', e),
|
545
|
+
offset = div.offset(),
|
546
|
+
width = div.width(),
|
547
|
+
height = div.height(),
|
548
|
+
x = event.pageX - offset.left,
|
549
|
+
y = event.pageY - offset.top;
|
550
|
+
|
551
|
+
if (x >= 0 && x < width && y >= 0 && y < height) {
|
552
|
+
event.stopImmediatePropagation();
|
553
|
+
event.preventDefault();
|
554
|
+
e.unbind('mousedown', _mousedown);
|
555
|
+
$(document).bind('mouseup', _mouseup);
|
556
|
+
$(document).bind('mousemove', _mousemove);
|
557
|
+
_mousemove(event);
|
558
|
+
}
|
559
|
+
};
|
560
|
+
|
561
|
+
_mouseup = function (event) {
|
562
|
+
event.stopImmediatePropagation();
|
563
|
+
event.preventDefault();
|
564
|
+
$(document).unbind('mouseup', _mouseup);
|
565
|
+
$(document).unbind('mousemove', _mousemove);
|
566
|
+
e.bind('mousedown', _mousedown);
|
567
|
+
};
|
568
|
+
|
569
|
+
_mousemove = function (event) {
|
570
|
+
event.stopImmediatePropagation();
|
571
|
+
event.preventDefault();
|
572
|
+
|
573
|
+
if (event.pageX === that.x && event.pageY === that.y) {
|
574
|
+
return;
|
575
|
+
}
|
576
|
+
that.x = event.pageX;
|
577
|
+
that.y = event.pageY;
|
578
|
+
|
579
|
+
var div = $('.ui-colorpicker-map-layer-pointer', e),
|
580
|
+
offset = div.offset(),
|
581
|
+
width = div.width(),
|
582
|
+
height = div.height(),
|
583
|
+
x = event.pageX - offset.left,
|
584
|
+
y = event.pageY - offset.top;
|
585
|
+
|
586
|
+
x = Math.max(0, Math.min(x / width, 1));
|
587
|
+
y = Math.max(0, Math.min(y / height, 1));
|
588
|
+
|
589
|
+
// interpret values
|
590
|
+
switch (inst.mode) {
|
591
|
+
case 'h':
|
592
|
+
inst.color.setHSV(null, x, 1 - y);
|
593
|
+
break;
|
594
|
+
|
595
|
+
case 's':
|
596
|
+
case 'a':
|
597
|
+
inst.color.setHSV(x, null, 1 - y);
|
598
|
+
break;
|
599
|
+
|
600
|
+
case 'v':
|
601
|
+
inst.color.setHSV(x, 1 - y, null);
|
602
|
+
break;
|
603
|
+
|
604
|
+
case 'r':
|
605
|
+
inst.color.setRGB(null, 1 - y, x);
|
606
|
+
break;
|
607
|
+
|
608
|
+
case 'g':
|
609
|
+
inst.color.setRGB(1 - y, null, x);
|
610
|
+
break;
|
611
|
+
|
612
|
+
case 'b':
|
613
|
+
inst.color.setRGB(x, 1 - y, null);
|
614
|
+
break;
|
615
|
+
}
|
616
|
+
|
617
|
+
inst._change();
|
618
|
+
};
|
619
|
+
|
620
|
+
_html = function () {
|
621
|
+
var html = '<div class="ui-colorpicker-map ui-colorpicker-border">'
|
622
|
+
+ '<span class="ui-colorpicker-map-layer-1"> </span>'
|
623
|
+
+ '<span class="ui-colorpicker-map-layer-2"> </span>'
|
624
|
+
+ (inst.options.alpha ? '<span class="ui-colorpicker-map-layer-alpha"> </span>' : '')
|
625
|
+
+ '<span class="ui-colorpicker-map-layer-pointer"><span class="ui-colorpicker-map-pointer"></span></span></div>';
|
626
|
+
return html;
|
627
|
+
};
|
628
|
+
|
629
|
+
this.update = function () {
|
630
|
+
switch (inst.mode) {
|
631
|
+
case 'h':
|
632
|
+
$('.ui-colorpicker-map-layer-1', e).css({'background-position': '0 0', 'opacity': ''}).show();
|
633
|
+
$('.ui-colorpicker-map-layer-2', e).hide();
|
634
|
+
break;
|
635
|
+
|
636
|
+
case 's':
|
637
|
+
case 'a':
|
638
|
+
$('.ui-colorpicker-map-layer-1', e).css({'background-position': '0 -260px', 'opacity': ''}).show();
|
639
|
+
$('.ui-colorpicker-map-layer-2', e).css({'background-position': '0 -520px', 'opacity': ''}).show();
|
640
|
+
break;
|
641
|
+
|
642
|
+
case 'v':
|
643
|
+
$(e).css('background-color', 'black');
|
644
|
+
$('.ui-colorpicker-map-layer-1', e).css({'background-position': '0 -780px', 'opacity': ''}).show();
|
645
|
+
$('.ui-colorpicker-map-layer-2', e).hide();
|
646
|
+
break;
|
647
|
+
|
648
|
+
case 'r':
|
649
|
+
$('.ui-colorpicker-map-layer-1', e).css({'background-position': '0 -1040px', 'opacity': ''}).show();
|
650
|
+
$('.ui-colorpicker-map-layer-2', e).css({'background-position': '0 -1300px', 'opacity': ''}).show();
|
651
|
+
break;
|
652
|
+
|
653
|
+
case 'g':
|
654
|
+
$('.ui-colorpicker-map-layer-1', e).css({'background-position': '0 -1560px', 'opacity': ''}).show();
|
655
|
+
$('.ui-colorpicker-map-layer-2', e).css({'background-position': '0 -1820px', 'opacity': ''}).show();
|
656
|
+
break;
|
657
|
+
|
658
|
+
case 'b':
|
659
|
+
$('.ui-colorpicker-map-layer-1', e).css({'background-position': '0 -2080px', 'opacity': ''}).show();
|
660
|
+
$('.ui-colorpicker-map-layer-2', e).css({'background-position': '0 -2340px', 'opacity': ''}).show();
|
661
|
+
break;
|
662
|
+
}
|
663
|
+
that.repaint();
|
664
|
+
};
|
665
|
+
|
666
|
+
this.repaint = function () {
|
667
|
+
var div = $('.ui-colorpicker-map-layer-pointer', e),
|
668
|
+
x = 0,
|
669
|
+
y = 0;
|
670
|
+
|
671
|
+
switch (inst.mode) {
|
672
|
+
case 'h':
|
673
|
+
x = inst.color.getHSV().s * div.width();
|
674
|
+
y = (1 - inst.color.getHSV().v) * div.width();
|
675
|
+
$(e).css('background-color', inst.color.copy().normalize().toCSS());
|
676
|
+
break;
|
677
|
+
|
678
|
+
case 's':
|
679
|
+
case 'a':
|
680
|
+
x = inst.color.getHSV().h * div.width();
|
681
|
+
y = (1 - inst.color.getHSV().v) * div.width();
|
682
|
+
$('.ui-colorpicker-map-layer-2', e).css('opacity', 1 - inst.color.getHSV().s);
|
683
|
+
break;
|
684
|
+
|
685
|
+
case 'v':
|
686
|
+
x = inst.color.getHSV().h * div.width();
|
687
|
+
y = (1 - inst.color.getHSV().s) * div.width();
|
688
|
+
$('.ui-colorpicker-map-layer-1', e).css('opacity', inst.color.getHSV().v);
|
689
|
+
break;
|
690
|
+
|
691
|
+
case 'r':
|
692
|
+
x = inst.color.getRGB().b * div.width();
|
693
|
+
y = (1 - inst.color.getRGB().g) * div.width();
|
694
|
+
$('.ui-colorpicker-map-layer-2', e).css('opacity', inst.color.getRGB().r);
|
695
|
+
break;
|
696
|
+
|
697
|
+
case 'g':
|
698
|
+
x = inst.color.getRGB().b * div.width();
|
699
|
+
y = (1 - inst.color.getRGB().r) * div.width();
|
700
|
+
$('.ui-colorpicker-map-layer-2', e).css('opacity', inst.color.getRGB().g);
|
701
|
+
break;
|
702
|
+
|
703
|
+
case 'b':
|
704
|
+
x = inst.color.getRGB().r * div.width();
|
705
|
+
y = (1 - inst.color.getRGB().g) * div.width();
|
706
|
+
$('.ui-colorpicker-map-layer-2', e).css('opacity', inst.color.getRGB().b);
|
707
|
+
break;
|
708
|
+
}
|
709
|
+
|
710
|
+
if (inst.options.alpha) {
|
711
|
+
$('.ui-colorpicker-map-layer-alpha', e).css('opacity', 1 - inst.color.getAlpha());
|
712
|
+
}
|
713
|
+
|
714
|
+
$('.ui-colorpicker-map-pointer', e).css({
|
715
|
+
'left': x - 7,
|
716
|
+
'top': y - 7
|
717
|
+
});
|
718
|
+
};
|
719
|
+
|
720
|
+
this.init = function () {
|
721
|
+
e = $(_html()).appendTo($('.ui-colorpicker-map-container', inst.dialog));
|
722
|
+
|
723
|
+
e.bind('mousedown', _mousedown);
|
724
|
+
};
|
725
|
+
},
|
726
|
+
|
727
|
+
bar: function (inst) {
|
728
|
+
var that = this,
|
729
|
+
e = null,
|
730
|
+
_mousedown, _mouseup, _mousemove, _html;
|
731
|
+
|
732
|
+
_mousedown = function (event) {
|
733
|
+
if (!inst.opened) {
|
734
|
+
return;
|
735
|
+
}
|
736
|
+
|
737
|
+
var div = $('.ui-colorpicker-bar-layer-pointer', e),
|
738
|
+
offset = div.offset(),
|
739
|
+
width = div.width(),
|
740
|
+
height = div.height(),
|
741
|
+
x = event.pageX - offset.left,
|
742
|
+
y = event.pageY - offset.top;
|
743
|
+
|
744
|
+
if (x >= 0 && x < width && y >= 0 && y < height) {
|
745
|
+
event.stopImmediatePropagation();
|
746
|
+
event.preventDefault();
|
747
|
+
e.unbind('mousedown', _mousedown);
|
748
|
+
$(document).bind('mouseup', _mouseup);
|
749
|
+
$(document).bind('mousemove', _mousemove);
|
750
|
+
_mousemove(event);
|
751
|
+
}
|
752
|
+
};
|
753
|
+
|
754
|
+
_mouseup = function (event) {
|
755
|
+
event.stopImmediatePropagation();
|
756
|
+
event.preventDefault();
|
757
|
+
$(document).unbind('mouseup', _mouseup);
|
758
|
+
$(document).unbind('mousemove', _mousemove);
|
759
|
+
e.bind('mousedown', _mousedown);
|
760
|
+
};
|
761
|
+
|
762
|
+
_mousemove = function (event) {
|
763
|
+
event.stopImmediatePropagation();
|
764
|
+
event.preventDefault();
|
765
|
+
|
766
|
+
if (event.pageY === that.y) {
|
767
|
+
return;
|
768
|
+
}
|
769
|
+
that.y = event.pageY;
|
770
|
+
|
771
|
+
var div = $('.ui-colorpicker-bar-layer-pointer', e),
|
772
|
+
offset = div.offset(),
|
773
|
+
height = div.height(),
|
774
|
+
y = event.pageY - offset.top;
|
775
|
+
|
776
|
+
y = Math.max(0, Math.min(y / height, 1));
|
777
|
+
|
778
|
+
// interpret values
|
779
|
+
switch (inst.mode) {
|
780
|
+
case 'h':
|
781
|
+
inst.color.setHSV(1 - y, null, null);
|
782
|
+
break;
|
783
|
+
|
784
|
+
case 's':
|
785
|
+
inst.color.setHSV(null, 1 - y, null);
|
786
|
+
break;
|
787
|
+
|
788
|
+
case 'v':
|
789
|
+
inst.color.setHSV(null, null, 1 - y);
|
790
|
+
break;
|
791
|
+
|
792
|
+
case 'r':
|
793
|
+
inst.color.setRGB(1 - y, null, null);
|
794
|
+
break;
|
795
|
+
|
796
|
+
case 'g':
|
797
|
+
inst.color.setRGB(null, 1 - y, null);
|
798
|
+
break;
|
799
|
+
|
800
|
+
case 'b':
|
801
|
+
inst.color.setRGB(null, null, 1 - y);
|
802
|
+
break;
|
803
|
+
|
804
|
+
case 'a':
|
805
|
+
inst.color.setAlpha(1 - y);
|
806
|
+
break;
|
807
|
+
}
|
808
|
+
|
809
|
+
inst._change();
|
810
|
+
};
|
811
|
+
|
812
|
+
_html = function () {
|
813
|
+
var html = '<div class="ui-colorpicker-bar ui-colorpicker-border">'
|
814
|
+
+ '<span class="ui-colorpicker-bar-layer-1"> </span>'
|
815
|
+
+ '<span class="ui-colorpicker-bar-layer-2"> </span>'
|
816
|
+
+ '<span class="ui-colorpicker-bar-layer-3"> </span>'
|
817
|
+
+ '<span class="ui-colorpicker-bar-layer-4"> </span>';
|
818
|
+
|
819
|
+
if (inst.options.alpha) {
|
820
|
+
html += '<span class="ui-colorpicker-bar-layer-alpha"> </span>'
|
821
|
+
+ '<span class="ui-colorpicker-bar-layer-alphabar"> </span>';
|
822
|
+
}
|
823
|
+
|
824
|
+
html += '<span class="ui-colorpicker-bar-layer-pointer"><span class="ui-colorpicker-bar-pointer"></span></span></div>';
|
825
|
+
|
826
|
+
return html;
|
827
|
+
};
|
828
|
+
|
829
|
+
this.update = function () {
|
830
|
+
switch (inst.mode) {
|
831
|
+
case 'h':
|
832
|
+
case 's':
|
833
|
+
case 'v':
|
834
|
+
case 'r':
|
835
|
+
case 'g':
|
836
|
+
case 'b':
|
837
|
+
$('.ui-colorpicker-bar-layer-alpha', e).show();
|
838
|
+
$('.ui-colorpicker-bar-layer-alphabar', e).hide();
|
839
|
+
break;
|
840
|
+
|
841
|
+
case 'a':
|
842
|
+
$('.ui-colorpicker-bar-layer-alpha', e).hide();
|
843
|
+
$('.ui-colorpicker-bar-layer-alphabar', e).show();
|
844
|
+
break;
|
845
|
+
}
|
846
|
+
|
847
|
+
switch (inst.mode) {
|
848
|
+
case 'h':
|
849
|
+
$('.ui-colorpicker-bar-layer-1', e).css({'background-position': '0 0', 'opacity': ''}).show();
|
850
|
+
$('.ui-colorpicker-bar-layer-2', e).hide();
|
851
|
+
$('.ui-colorpicker-bar-layer-3', e).hide();
|
852
|
+
$('.ui-colorpicker-bar-layer-4', e).hide();
|
853
|
+
break;
|
854
|
+
|
855
|
+
case 's':
|
856
|
+
$('.ui-colorpicker-bar-layer-1', e).css({'background-position': '0 -260px', 'opacity': ''}).show();
|
857
|
+
$('.ui-colorpicker-bar-layer-2', e).css({'background-position': '0 -520px', 'opacity': ''}).show();
|
858
|
+
$('.ui-colorpicker-bar-layer-3', e).hide();
|
859
|
+
$('.ui-colorpicker-bar-layer-4', e).hide();
|
860
|
+
break;
|
861
|
+
|
862
|
+
case 'v':
|
863
|
+
$('.ui-colorpicker-bar-layer-1', e).css({'background-position': '0 -520px', 'opacity': ''}).show();
|
864
|
+
$('.ui-colorpicker-bar-layer-2', e).hide();
|
865
|
+
$('.ui-colorpicker-bar-layer-3', e).hide();
|
866
|
+
$('.ui-colorpicker-bar-layer-4', e).hide();
|
867
|
+
break;
|
868
|
+
|
869
|
+
case 'r':
|
870
|
+
$('.ui-colorpicker-bar-layer-1', e).css({'background-position': '0 -1560px', 'opacity': ''}).show();
|
871
|
+
$('.ui-colorpicker-bar-layer-2', e).css({'background-position': '0 -1300px', 'opacity': ''}).show();
|
872
|
+
$('.ui-colorpicker-bar-layer-3', e).css({'background-position': '0 -780px', 'opacity': ''}).show();
|
873
|
+
$('.ui-colorpicker-bar-layer-4', e).css({'background-position': '0 -1040px', 'opacity': ''}).show();
|
874
|
+
break;
|
875
|
+
|
876
|
+
case 'g':
|
877
|
+
$('.ui-colorpicker-bar-layer-1', e).css({'background-position': '0 -2600px', 'opacity': ''}).show();
|
878
|
+
$('.ui-colorpicker-bar-layer-2', e).css({'background-position': '0 -2340px', 'opacity': ''}).show();
|
879
|
+
$('.ui-colorpicker-bar-layer-3', e).css({'background-position': '0 -1820px', 'opacity': ''}).show();
|
880
|
+
$('.ui-colorpicker-bar-layer-4', e).css({'background-position': '0 -2080px', 'opacity': ''}).show();
|
881
|
+
break;
|
882
|
+
|
883
|
+
case 'b':
|
884
|
+
$('.ui-colorpicker-bar-layer-1', e).css({'background-position': '0 -3640px', 'opacity': ''}).show();
|
885
|
+
$('.ui-colorpicker-bar-layer-2', e).css({'background-position': '0 -3380px', 'opacity': ''}).show();
|
886
|
+
$('.ui-colorpicker-bar-layer-3', e).css({'background-position': '0 -2860px', 'opacity': ''}).show();
|
887
|
+
$('.ui-colorpicker-bar-layer-4', e).css({'background-position': '0 -3120px', 'opacity': ''}).show();
|
888
|
+
break;
|
889
|
+
|
890
|
+
case 'a':
|
891
|
+
$('.ui-colorpicker-bar-layer-1', e).hide();
|
892
|
+
$('.ui-colorpicker-bar-layer-2', e).hide();
|
893
|
+
$('.ui-colorpicker-bar-layer-3', e).hide();
|
894
|
+
$('.ui-colorpicker-bar-layer-4', e).hide();
|
895
|
+
break;
|
896
|
+
}
|
897
|
+
that.repaint();
|
898
|
+
};
|
899
|
+
|
900
|
+
this.repaint = function () {
|
901
|
+
var div = $('.ui-colorpicker-bar-layer-pointer', e),
|
902
|
+
y = 0;
|
903
|
+
|
904
|
+
switch (inst.mode) {
|
905
|
+
case 'h':
|
906
|
+
y = (1 - inst.color.getHSV().h) * div.height();
|
907
|
+
break;
|
908
|
+
|
909
|
+
case 's':
|
910
|
+
y = (1 - inst.color.getHSV().s) * div.height();
|
911
|
+
$('.ui-colorpicker-bar-layer-2', e).css('opacity', 1 - inst.color.getHSV().v);
|
912
|
+
$(e).css('background-color', inst.color.copy().normalize().toCSS());
|
913
|
+
break;
|
914
|
+
|
915
|
+
case 'v':
|
916
|
+
y = (1 - inst.color.getHSV().v) * div.height();
|
917
|
+
$(e).css('background-color', inst.color.copy().normalize().toCSS());
|
918
|
+
break;
|
919
|
+
|
920
|
+
case 'r':
|
921
|
+
y = (1 - inst.color.getRGB().r) * div.height();
|
922
|
+
$('.ui-colorpicker-bar-layer-2', e).css('opacity', Math.max(0, (inst.color.getRGB().b - inst.color.getRGB().g)));
|
923
|
+
$('.ui-colorpicker-bar-layer-3', e).css('opacity', Math.max(0, (inst.color.getRGB().g - inst.color.getRGB().b)));
|
924
|
+
$('.ui-colorpicker-bar-layer-4', e).css('opacity', Math.min(inst.color.getRGB().b, inst.color.getRGB().g));
|
925
|
+
break;
|
926
|
+
|
927
|
+
case 'g':
|
928
|
+
y = (1 - inst.color.getRGB().g) * div.height();
|
929
|
+
$('.ui-colorpicker-bar-layer-2', e).css('opacity', Math.max(0, (inst.color.getRGB().b - inst.color.getRGB().r)));
|
930
|
+
$('.ui-colorpicker-bar-layer-3', e).css('opacity', Math.max(0, (inst.color.getRGB().r - inst.color.getRGB().b)));
|
931
|
+
$('.ui-colorpicker-bar-layer-4', e).css('opacity', Math.min(inst.color.getRGB().r, inst.color.getRGB().b));
|
932
|
+
break;
|
933
|
+
|
934
|
+
case 'b':
|
935
|
+
y = (1 - inst.color.getRGB().b) * div.height();
|
936
|
+
$('.ui-colorpicker-bar-layer-2', e).css('opacity', Math.max(0, (inst.color.getRGB().r - inst.color.getRGB().g)));
|
937
|
+
$('.ui-colorpicker-bar-layer-3', e).css('opacity', Math.max(0, (inst.color.getRGB().g - inst.color.getRGB().r)));
|
938
|
+
$('.ui-colorpicker-bar-layer-4', e).css('opacity', Math.min(inst.color.getRGB().r, inst.color.getRGB().g));
|
939
|
+
break;
|
940
|
+
|
941
|
+
case 'a':
|
942
|
+
y = (1 - inst.color.getAlpha()) * div.height();
|
943
|
+
$(e).css('background-color', inst.color.copy().toCSS());
|
944
|
+
break;
|
945
|
+
}
|
946
|
+
|
947
|
+
if (inst.mode !== 'a') {
|
948
|
+
$('.ui-colorpicker-bar-layer-alpha', e).css('opacity', 1 - inst.color.getAlpha());
|
949
|
+
}
|
950
|
+
|
951
|
+
$('.ui-colorpicker-bar-pointer', e).css('top', y - 3);
|
952
|
+
};
|
953
|
+
|
954
|
+
this.init = function () {
|
955
|
+
e = $(_html()).appendTo($('.ui-colorpicker-bar-container', inst.dialog));
|
956
|
+
|
957
|
+
e.bind('mousedown', _mousedown);
|
958
|
+
};
|
959
|
+
},
|
960
|
+
|
961
|
+
preview: function (inst) {
|
962
|
+
var that = this,
|
963
|
+
e = null,
|
964
|
+
_html;
|
965
|
+
|
966
|
+
_html = function () {
|
967
|
+
return '<div class="ui-colorpicker-preview ui-colorpicker-border">'
|
968
|
+
+ '<div class="ui-colorpicker-preview-initial"><div class="ui-colorpicker-preview-initial-alpha"></div></div>'
|
969
|
+
+ '<div class="ui-colorpicker-preview-current"><div class="ui-colorpicker-preview-current-alpha"></div></div>'
|
970
|
+
+ '</div>';
|
971
|
+
};
|
972
|
+
|
973
|
+
this.init = function () {
|
974
|
+
e = $(_html()).appendTo($('.ui-colorpicker-preview-container', inst.dialog));
|
975
|
+
|
976
|
+
$('.ui-colorpicker-preview-initial', e).click(function () {
|
977
|
+
inst.color = inst.currentColor.copy();
|
978
|
+
inst._change(inst.color.set);
|
979
|
+
});
|
980
|
+
};
|
981
|
+
|
982
|
+
this.update = function () {
|
983
|
+
if (inst.options.alpha) {
|
984
|
+
$('.ui-colorpicker-preview-initial-alpha, .ui-colorpicker-preview-current-alpha', e).show();
|
985
|
+
} else {
|
986
|
+
$('.ui-colorpicker-preview-initial-alpha, .ui-colorpicker-preview-current-alpha', e).hide();
|
987
|
+
}
|
988
|
+
|
989
|
+
this.repaint();
|
990
|
+
};
|
991
|
+
|
992
|
+
this.repaint = function () {
|
993
|
+
$('.ui-colorpicker-preview-initial', e).css('background-color', inst.currentColor.set ? inst.currentColor.toCSS() : '').attr('title', inst.currentColor.set ? inst.currentColor.toCSS() : '');
|
994
|
+
$('.ui-colorpicker-preview-initial-alpha', e).css('opacity', 1 - inst.currentColor.getAlpha());
|
995
|
+
$('.ui-colorpicker-preview-current', e).css('background-color', inst.color.set ? inst.color.toCSS() : '').attr('title', inst.color.set ? inst.color.toCSS() : '');
|
996
|
+
$('.ui-colorpicker-preview-current-alpha', e).css('opacity', 1 - inst.color.getAlpha());
|
997
|
+
};
|
998
|
+
},
|
999
|
+
|
1000
|
+
hsv: function (inst) {
|
1001
|
+
var that = this,
|
1002
|
+
e = null,
|
1003
|
+
_html;
|
1004
|
+
|
1005
|
+
_html = function () {
|
1006
|
+
var html = '';
|
1007
|
+
|
1008
|
+
if (inst.options.hsv) {
|
1009
|
+
html += '<div class="ui-colorpicker-hsv-h"><input class="ui-colorpicker-mode" type="radio" value="h"/><label>' + inst._getRegional('hsvH') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="360" size="10"/><span class="ui-colorpicker-unit">°</span></div>'
|
1010
|
+
+ '<div class="ui-colorpicker-hsv-s"><input class="ui-colorpicker-mode" type="radio" value="s"/><label>' + inst._getRegional('hsvS') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100" size="10"/><span class="ui-colorpicker-unit">%</span></div>'
|
1011
|
+
+ '<div class="ui-colorpicker-hsv-v"><input class="ui-colorpicker-mode" type="radio" value="v"/><label>' + inst._getRegional('hsvV') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100" size="10"/><span class="ui-colorpicker-unit">%</span></div>';
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
return '<div class="ui-colorpicker-hsv">' + html + '</div>';
|
1015
|
+
};
|
1016
|
+
|
1017
|
+
this.init = function () {
|
1018
|
+
e = $(_html()).appendTo($('.ui-colorpicker-hsv-container', inst.dialog));
|
1019
|
+
|
1020
|
+
$('.ui-colorpicker-mode', e).click(function () {
|
1021
|
+
inst.mode = $(this).val();
|
1022
|
+
inst._updateAllParts();
|
1023
|
+
});
|
1024
|
+
|
1025
|
+
$('.ui-colorpicker-number', e).bind('change keyup', function () {
|
1026
|
+
inst.color.setHSV(
|
1027
|
+
$('.ui-colorpicker-hsv-h .ui-colorpicker-number', e).val() / 360,
|
1028
|
+
$('.ui-colorpicker-hsv-s .ui-colorpicker-number', e).val() / 100,
|
1029
|
+
$('.ui-colorpicker-hsv-v .ui-colorpicker-number', e).val() / 100
|
1030
|
+
);
|
1031
|
+
inst._change();
|
1032
|
+
});
|
1033
|
+
};
|
1034
|
+
|
1035
|
+
this.repaint = function () {
|
1036
|
+
var hsv = inst.color.getHSV();
|
1037
|
+
hsv.h *= 360;
|
1038
|
+
hsv.s *= 100;
|
1039
|
+
hsv.v *= 100;
|
1040
|
+
|
1041
|
+
$.each(hsv, function (index, value) {
|
1042
|
+
var input = $('.ui-colorpicker-hsv-' + index + ' .ui-colorpicker-number', e);
|
1043
|
+
value = Math.round(value);
|
1044
|
+
if (parseInt(input.val()) !== value) {
|
1045
|
+
input.val(value);
|
1046
|
+
}
|
1047
|
+
});
|
1048
|
+
};
|
1049
|
+
|
1050
|
+
this.update = function () {
|
1051
|
+
$('.ui-colorpicker-mode', e).each(function () {
|
1052
|
+
$(this).attr('checked', $(this).val() === inst.mode);
|
1053
|
+
});
|
1054
|
+
this.repaint();
|
1055
|
+
};
|
1056
|
+
},
|
1057
|
+
|
1058
|
+
rgb: function (inst) {
|
1059
|
+
var that = this,
|
1060
|
+
e = null,
|
1061
|
+
_html;
|
1062
|
+
|
1063
|
+
_html = function () {
|
1064
|
+
var html = '';
|
1065
|
+
|
1066
|
+
if (inst.options.rgb) {
|
1067
|
+
html += '<div class="ui-colorpicker-rgb-r"><input class="ui-colorpicker-mode" type="radio" value="r"/><label>' + inst._getRegional('rgbR') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="255"/></div>'
|
1068
|
+
+ '<div class="ui-colorpicker-rgb-g"><input class="ui-colorpicker-mode" type="radio" value="g"/><label>' + inst._getRegional('rgbG') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="255"/></div>'
|
1069
|
+
+ '<div class="ui-colorpicker-rgb-b"><input class="ui-colorpicker-mode" type="radio" value="b"/><label>' + inst._getRegional('rgbB') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="255"/></div>';
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
return '<div class="ui-colorpicker-rgb">' + html + '</div>';
|
1073
|
+
};
|
1074
|
+
|
1075
|
+
this.init = function () {
|
1076
|
+
e = $(_html()).appendTo($('.ui-colorpicker-rgb-container', inst.dialog));
|
1077
|
+
|
1078
|
+
$('.ui-colorpicker-mode', e).click(function () {
|
1079
|
+
inst.mode = $(this).val();
|
1080
|
+
inst._updateAllParts();
|
1081
|
+
});
|
1082
|
+
|
1083
|
+
$('.ui-colorpicker-number', e).bind('change keyup', function () {
|
1084
|
+
var r = $('.ui-colorpicker-rgb-r .ui-colorpicker-number', e).val();
|
1085
|
+
inst.color.setRGB(
|
1086
|
+
$('.ui-colorpicker-rgb-r .ui-colorpicker-number', e).val() / 255,
|
1087
|
+
$('.ui-colorpicker-rgb-g .ui-colorpicker-number', e).val() / 255,
|
1088
|
+
$('.ui-colorpicker-rgb-b .ui-colorpicker-number', e).val() / 255
|
1089
|
+
);
|
1090
|
+
|
1091
|
+
inst._change();
|
1092
|
+
});
|
1093
|
+
};
|
1094
|
+
|
1095
|
+
this.repaint = function () {
|
1096
|
+
$.each(inst.color.getRGB(), function (index, value) {
|
1097
|
+
var input = $('.ui-colorpicker-rgb-' + index + ' .ui-colorpicker-number', e);
|
1098
|
+
value = Math.floor(value * 255);
|
1099
|
+
if (parseInt(input.val()) !== value) {
|
1100
|
+
input.val(value);
|
1101
|
+
}
|
1102
|
+
});
|
1103
|
+
};
|
1104
|
+
|
1105
|
+
this.update = function () {
|
1106
|
+
$('.ui-colorpicker-mode', e).each(function () {
|
1107
|
+
$(this).attr('checked', $(this).val() === inst.mode);
|
1108
|
+
});
|
1109
|
+
this.repaint();
|
1110
|
+
};
|
1111
|
+
},
|
1112
|
+
|
1113
|
+
lab: function (inst) {
|
1114
|
+
var that = this,
|
1115
|
+
part = null,
|
1116
|
+
html = function () {
|
1117
|
+
var html = '';
|
1118
|
+
|
1119
|
+
if (inst.options.hsv) {
|
1120
|
+
html += '<div class="ui-colorpicker-lab-l"><label>' + inst._getRegional('labL') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100"/></div>'
|
1121
|
+
+ '<div class="ui-colorpicker-lab-a"><label>' + inst._getRegional('labA') + '</label><input class="ui-colorpicker-number" type="number" min="-128" max="127"/></div>'
|
1122
|
+
+ '<div class="ui-colorpicker-lab-b"><label>' + inst._getRegional('labB') + '</label><input class="ui-colorpicker-number" type="number" min="-128" max="127"/></div>';
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
return '<div class="ui-colorpicker-lab">' + html + '</div>';
|
1126
|
+
};
|
1127
|
+
|
1128
|
+
this.init = function () {
|
1129
|
+
var data = 0;
|
1130
|
+
|
1131
|
+
part = $(html()).appendTo($('.ui-colorpicker-lab-container', inst.dialog));
|
1132
|
+
|
1133
|
+
$('.ui-colorpicker-number', part).bind('change keyup', function (event) {
|
1134
|
+
inst.color.setLAB(
|
1135
|
+
parseInt($('.ui-colorpicker-lab-l .ui-colorpicker-number', part).val(), 10) / 100,
|
1136
|
+
(parseInt($('.ui-colorpicker-lab-a .ui-colorpicker-number', part).val(), 10) + 128) / 255,
|
1137
|
+
(parseInt($('.ui-colorpicker-lab-b .ui-colorpicker-number', part).val(), 10) + 128) / 255
|
1138
|
+
);
|
1139
|
+
inst._change();
|
1140
|
+
});
|
1141
|
+
};
|
1142
|
+
|
1143
|
+
this.repaint = function () {
|
1144
|
+
var lab = inst.color.getLAB();
|
1145
|
+
lab.l *= 100;
|
1146
|
+
lab.a = (lab.a * 255) - 128;
|
1147
|
+
lab.b = (lab.b * 255) - 128;
|
1148
|
+
|
1149
|
+
$.each(lab, function (index, value) {
|
1150
|
+
var input = $('.ui-colorpicker-lab-' + index + ' .ui-colorpicker-number', part);
|
1151
|
+
value = Math.round(value);
|
1152
|
+
if (parseInt(input.val()) !== value) {
|
1153
|
+
input.val(value);
|
1154
|
+
}
|
1155
|
+
});
|
1156
|
+
};
|
1157
|
+
|
1158
|
+
this.update = function () {
|
1159
|
+
this.repaint();
|
1160
|
+
};
|
1161
|
+
},
|
1162
|
+
|
1163
|
+
cmyk: function (inst) {
|
1164
|
+
var that = this,
|
1165
|
+
part = null,
|
1166
|
+
html = function () {
|
1167
|
+
var html = '';
|
1168
|
+
|
1169
|
+
if (inst.options.hsv) {
|
1170
|
+
html += '<div class="ui-colorpicker-cmyk-c"><label>' + inst._getRegional('cmykC') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%</span></div>'
|
1171
|
+
+ '<div class="ui-colorpicker-cmyk-m"><label>' + inst._getRegional('cmykM') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%</span></div>'
|
1172
|
+
+ '<div class="ui-colorpicker-cmyk-y"><label>' + inst._getRegional('cmykY') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%</span></div>'
|
1173
|
+
+ '<div class="ui-colorpicker-cmyk-k"><label>' + inst._getRegional('cmykK') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%</span></div>';
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
return '<div class="ui-colorpicker-cmyk">' + html + '</div>';
|
1177
|
+
};
|
1178
|
+
|
1179
|
+
this.init = function () {
|
1180
|
+
part = $(html()).appendTo($('.ui-colorpicker-cmyk-container', inst.dialog));
|
1181
|
+
|
1182
|
+
$('.ui-colorpicker-number', part).bind('change keyup', function (event) {
|
1183
|
+
inst.color.setCMYK(
|
1184
|
+
parseInt($('.ui-colorpicker-cmyk-c .ui-colorpicker-number', part).val(), 10) / 100,
|
1185
|
+
parseInt($('.ui-colorpicker-cmyk-m .ui-colorpicker-number', part).val(), 10) / 100,
|
1186
|
+
parseInt($('.ui-colorpicker-cmyk-y .ui-colorpicker-number', part).val(), 10) / 100,
|
1187
|
+
parseInt($('.ui-colorpicker-cmyk-k .ui-colorpicker-number', part).val(), 10) / 100
|
1188
|
+
);
|
1189
|
+
inst._change();
|
1190
|
+
});
|
1191
|
+
};
|
1192
|
+
|
1193
|
+
this.repaint = function () {
|
1194
|
+
$.each(inst.color.getCMYK(), function (index, value) {
|
1195
|
+
var input = $('.ui-colorpicker-cmyk-' + index + ' .ui-colorpicker-number', part);
|
1196
|
+
value = Math.round(value * 100);
|
1197
|
+
if (parseInt(input.val()) !== value) {
|
1198
|
+
input.val(value);
|
1199
|
+
}
|
1200
|
+
});
|
1201
|
+
};
|
1202
|
+
|
1203
|
+
this.update = function () {
|
1204
|
+
this.repaint();
|
1205
|
+
};
|
1206
|
+
},
|
1207
|
+
|
1208
|
+
alpha: function (inst) {
|
1209
|
+
var that = this,
|
1210
|
+
e = null,
|
1211
|
+
_html;
|
1212
|
+
|
1213
|
+
_html = function () {
|
1214
|
+
var html = '';
|
1215
|
+
|
1216
|
+
if (inst.options.alpha) {
|
1217
|
+
html += '<div class="ui-colorpicker-a"><input class="ui-colorpicker-mode" name="mode" type="radio" value="a"/><label>' + inst._getRegional('alphaA') + '</label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%</span></div>';
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
return '<div class="ui-colorpicker-alpha">' + html + '</div>';
|
1221
|
+
};
|
1222
|
+
|
1223
|
+
this.init = function () {
|
1224
|
+
e = $(_html()).appendTo($('.ui-colorpicker-alpha-container', inst.dialog));
|
1225
|
+
|
1226
|
+
$('.ui-colorpicker-mode', e).click(function () {
|
1227
|
+
inst.mode = $(this).val();
|
1228
|
+
inst._updateAllParts();
|
1229
|
+
});
|
1230
|
+
|
1231
|
+
$('.ui-colorpicker-number', e).bind('change keyup', function () {
|
1232
|
+
inst.color.setAlpha($('.ui-colorpicker-a .ui-colorpicker-number', e).val() / 100);
|
1233
|
+
inst._change();
|
1234
|
+
});
|
1235
|
+
};
|
1236
|
+
|
1237
|
+
this.update = function () {
|
1238
|
+
$('.ui-colorpicker-mode', e).each(function () {
|
1239
|
+
$(this).attr('checked', $(this).val() === inst.mode);
|
1240
|
+
});
|
1241
|
+
this.repaint();
|
1242
|
+
};
|
1243
|
+
|
1244
|
+
this.repaint = function () {
|
1245
|
+
var input = $('.ui-colorpicker-a .ui-colorpicker-number', e),
|
1246
|
+
value = Math.round(inst.color.getAlpha() * 100);
|
1247
|
+
if (parseInt(input.val()) !== value) {
|
1248
|
+
input.val(value);
|
1249
|
+
}
|
1250
|
+
};
|
1251
|
+
},
|
1252
|
+
|
1253
|
+
hex: function (inst) {
|
1254
|
+
var that = this,
|
1255
|
+
e = null,
|
1256
|
+
_html;
|
1257
|
+
|
1258
|
+
_html = function () {
|
1259
|
+
var html = '';
|
1260
|
+
|
1261
|
+
if (inst.options.alpha) {
|
1262
|
+
html += '<input class="ui-colorpicker-hex-alpha" type="text" maxlength="2" size="2"/>';
|
1263
|
+
}
|
1264
|
+
|
1265
|
+
html += '<input class="ui-colorpicker-hex-input" type="text" maxlength="6" size="6"/>';
|
1266
|
+
|
1267
|
+
return '<div class="ui-colorpicker-hex"><label>#</label>' + html + '</div>';
|
1268
|
+
};
|
1269
|
+
|
1270
|
+
this.init = function () {
|
1271
|
+
e = $(_html()).appendTo($('.ui-colorpicker-hex-container', inst.dialog));
|
1272
|
+
|
1273
|
+
// repeat here makes the invalid input disappear faster
|
1274
|
+
$('.ui-colorpicker-hex-input', e).bind('change keydown keyup', function (a, b, c) {
|
1275
|
+
if (/[^a-fA-F0-9]/.test($(this).val())) {
|
1276
|
+
$(this).val($(this).val().replace(/[^a-fA-F0-9]/, ''));
|
1277
|
+
}
|
1278
|
+
});
|
1279
|
+
|
1280
|
+
$('.ui-colorpicker-hex-input', e).bind('change keyup', function () {
|
1281
|
+
// repeat here makes sure that the invalid input doesn't get parsed
|
1282
|
+
inst.color = _parseHex($(this).val()).setAlpha(inst.color.getAlpha());
|
1283
|
+
inst._change();
|
1284
|
+
});
|
1285
|
+
|
1286
|
+
$('.ui-colorpicker-hex-alpha', e).bind('change keydown keyup', function () {
|
1287
|
+
if (/[^a-fA-F0-9]/.test($(this).val())) {
|
1288
|
+
$(this).val($(this).val().replace(/[^a-fA-F0-9]/, ''));
|
1289
|
+
}
|
1290
|
+
});
|
1291
|
+
|
1292
|
+
$('.ui-colorpicker-hex-alpha', e).bind('change keyup', function () {
|
1293
|
+
inst.color.setAlpha(parseInt($('.ui-colorpicker-hex-alpha', e).val(), 16) / 255);
|
1294
|
+
inst._change();
|
1295
|
+
});
|
1296
|
+
};
|
1297
|
+
|
1298
|
+
this.update = function () {
|
1299
|
+
this.repaint();
|
1300
|
+
};
|
1301
|
+
|
1302
|
+
this.repaint = function () {
|
1303
|
+
if (!$('.ui-colorpicker-hex-input', e).is(':focus')) {
|
1304
|
+
$('.ui-colorpicker-hex-input', e).val(inst.color.toHex(true));
|
1305
|
+
}
|
1306
|
+
|
1307
|
+
if (!$('.ui-colorpicker-hex-alpha', e).is(':focus')) {
|
1308
|
+
$('.ui-colorpicker-hex-alpha', e).val(_intToHex(inst.color.getAlpha() * 255));
|
1309
|
+
}
|
1310
|
+
};
|
1311
|
+
},
|
1312
|
+
|
1313
|
+
swatches: function (inst) {
|
1314
|
+
var that = this,
|
1315
|
+
part = null,
|
1316
|
+
html = function () {
|
1317
|
+
var html = '';
|
1318
|
+
|
1319
|
+
$.each(inst._getSwatches(), function (name, color) {
|
1320
|
+
var c = new $.colorpicker.Color(color.r, color.g, color.b),
|
1321
|
+
css = c.toCSS();
|
1322
|
+
html += '<div class="ui-colorpicker-swatch" style="background-color:' + css + '" title="' + name + '"></div>';
|
1323
|
+
});
|
1324
|
+
|
1325
|
+
return '<div class="ui-colorpicker-swatches ui-colorpicker-border" style="width:' + inst.options.swatchesWidth + 'px">' + html + '</div>';
|
1326
|
+
};
|
1327
|
+
|
1328
|
+
this.init = function () {
|
1329
|
+
part = $(html()).appendTo($('.ui-colorpicker-swatches-container', inst.dialog));
|
1330
|
+
|
1331
|
+
$('.ui-colorpicker-swatch', part).click(function () {
|
1332
|
+
inst.color = inst._parseColor($(this).css('background-color'));
|
1333
|
+
inst._change();
|
1334
|
+
});
|
1335
|
+
};
|
1336
|
+
},
|
1337
|
+
|
1338
|
+
footer: function (inst) {
|
1339
|
+
var that = this,
|
1340
|
+
part = null,
|
1341
|
+
id_transparent = 'ui-colorpicker-special-transparent-'+_colorpicker_index,
|
1342
|
+
id_none = 'ui-colorpicker-special-none-'+_colorpicker_index,
|
1343
|
+
html = function () {
|
1344
|
+
var html = '';
|
1345
|
+
|
1346
|
+
if (inst.options.alpha || (!inst.inline && inst.options.showNoneButton)) {
|
1347
|
+
html += '<div class="ui-colorpicker-buttonset">';
|
1348
|
+
|
1349
|
+
if (inst.options.alpha) {
|
1350
|
+
html += '<input type="radio" name="ui-colorpicker-special" id="'+id_transparent+'" class="ui-colorpicker-special-transparent"/><label for="'+id_transparent+'">' + inst._getRegional('transparent') + '</label>';
|
1351
|
+
}
|
1352
|
+
if (!inst.inline && inst.options.showNoneButton) {
|
1353
|
+
html += '<input type="radio" name="ui-colorpicker-special" id="'+id_none+'" class="ui-colorpicker-special-none"><label for="'+id_none+'">' + inst._getRegional('none') + '</label>';
|
1354
|
+
}
|
1355
|
+
html += '</div>';
|
1356
|
+
}
|
1357
|
+
|
1358
|
+
if (!inst.inline) {
|
1359
|
+
html += '<div class="ui-dialog-buttonset">';
|
1360
|
+
if (inst.options.showCancelButton) {
|
1361
|
+
html += '<button class="ui-colorpicker-cancel">' + inst._getRegional('cancel') + '</button>';
|
1362
|
+
}
|
1363
|
+
html += '<button class="ui-colorpicker-ok">' + inst._getRegional('ok') + '</button>';
|
1364
|
+
html += '</div>';
|
1365
|
+
}
|
1366
|
+
|
1367
|
+
return '<div class="ui-dialog-buttonpane ui-widget-content">' + html + '</div>';
|
1368
|
+
};
|
1369
|
+
|
1370
|
+
this.init = function () {
|
1371
|
+
part = $(html()).appendTo(inst.dialog);
|
1372
|
+
|
1373
|
+
$('.ui-colorpicker-ok', part).button().click(function () {
|
1374
|
+
inst.close();
|
1375
|
+
});
|
1376
|
+
|
1377
|
+
$('.ui-colorpicker-cancel', part).button().click(function () {
|
1378
|
+
inst.close(true); //cancel
|
1379
|
+
});
|
1380
|
+
|
1381
|
+
//inst._getRegional('transparent')
|
1382
|
+
$('.ui-colorpicker-buttonset', part).buttonset();
|
1383
|
+
|
1384
|
+
$('.ui-colorpicker-special-color', part).click(function () {
|
1385
|
+
inst._change();
|
1386
|
+
});
|
1387
|
+
|
1388
|
+
$('#'+id_none, part).click(function () {
|
1389
|
+
inst._change(false);
|
1390
|
+
});
|
1391
|
+
|
1392
|
+
$('#'+id_transparent, part).click(function () {
|
1393
|
+
inst.color.setAlpha(0);
|
1394
|
+
inst._change();
|
1395
|
+
});
|
1396
|
+
};
|
1397
|
+
|
1398
|
+
this.repaint = function () {
|
1399
|
+
if (!inst.color.set) {
|
1400
|
+
$('.ui-colorpicker-special-none', part).attr('checked', true).button( "refresh" );
|
1401
|
+
} else if (inst.color.getAlpha() == 0) {
|
1402
|
+
$('.ui-colorpicker-special-transparent', part).attr('checked', true).button( "refresh" );
|
1403
|
+
} else {
|
1404
|
+
$('input', part).attr('checked', false).button( "refresh" );
|
1405
|
+
}
|
1406
|
+
|
1407
|
+
$('.ui-colorpicker-cancel', part).button(inst.changed ? 'enable' : 'disable');
|
1408
|
+
};
|
1409
|
+
|
1410
|
+
this.update = function () {};
|
1411
|
+
}
|
1412
|
+
};
|
1413
|
+
|
1414
|
+
this.Color = function () {
|
1415
|
+
var spaces = { rgb: {r: 0, g: 0, b: 0},
|
1416
|
+
hsv: {h: 0, s: 0, v: 0},
|
1417
|
+
hsl: {h: 0, s: 0, l: 0},
|
1418
|
+
lab: {l: 0, a: 0, b: 0},
|
1419
|
+
cmyk: {c: 0, m: 0, y: 0, k: 1}
|
1420
|
+
},
|
1421
|
+
a = 1,
|
1422
|
+
illuminant = [0.9504285, 1, 1.0889], // CIE-L*ab D65/2' 1931
|
1423
|
+
args = arguments,
|
1424
|
+
_clip = function(v) {
|
1425
|
+
if (isNaN(v) || v === null) {
|
1426
|
+
return 0;
|
1427
|
+
}
|
1428
|
+
if (typeof v == 'string') {
|
1429
|
+
v = parseInt(v, 10);
|
1430
|
+
}
|
1431
|
+
return Math.max(0, Math.min(v, 1));
|
1432
|
+
},
|
1433
|
+
_hexify = function (number) {
|
1434
|
+
var digits = '0123456789abcdef',
|
1435
|
+
lsd = number % 16,
|
1436
|
+
msd = (number - lsd) / 16,
|
1437
|
+
hexified = digits.charAt(msd) + digits.charAt(lsd);
|
1438
|
+
return hexified;
|
1439
|
+
},
|
1440
|
+
_rgb_to_xyz = function(rgb) {
|
1441
|
+
var r = (rgb.r > 0.04045) ? Math.pow((rgb.r + 0.055) / 1.055, 2.4) : rgb.r / 12.92,
|
1442
|
+
g = (rgb.g > 0.04045) ? Math.pow((rgb.g + 0.055) / 1.055, 2.4) : rgb.g / 12.92,
|
1443
|
+
b = (rgb.b > 0.04045) ? Math.pow((rgb.b + 0.055) / 1.055, 2.4) : rgb.b / 12.92;
|
1444
|
+
|
1445
|
+
return {
|
1446
|
+
x: r * 0.4124 + g * 0.3576 + b * 0.1805,
|
1447
|
+
y: r * 0.2126 + g * 0.7152 + b * 0.0722,
|
1448
|
+
z: r * 0.0193 + g * 0.1192 + b * 0.9505
|
1449
|
+
};
|
1450
|
+
},
|
1451
|
+
_xyz_to_rgb = function(xyz) {
|
1452
|
+
var rgb = {
|
1453
|
+
r: xyz.x * 3.2406 + xyz.y * -1.5372 + xyz.z * -0.4986,
|
1454
|
+
g: xyz.x * -0.9689 + xyz.y * 1.8758 + xyz.z * 0.0415,
|
1455
|
+
b: xyz.x * 0.0557 + xyz.y * -0.2040 + xyz.z * 1.0570
|
1456
|
+
};
|
1457
|
+
|
1458
|
+
rgb.r = (rgb.r > 0.0031308) ? 1.055 * Math.pow(rgb.r, (1 / 2.4)) - 0.055 : 12.92 * rgb.r;
|
1459
|
+
rgb.g = (rgb.g > 0.0031308) ? 1.055 * Math.pow(rgb.g, (1 / 2.4)) - 0.055 : 12.92 * rgb.g;
|
1460
|
+
rgb.b = (rgb.b > 0.0031308) ? 1.055 * Math.pow(rgb.b, (1 / 2.4)) - 0.055 : 12.92 * rgb.b;
|
1461
|
+
|
1462
|
+
return rgb;
|
1463
|
+
},
|
1464
|
+
_rgb_to_hsv = function(rgb) {
|
1465
|
+
var minVal = Math.min(rgb.r, rgb.g, rgb.b),
|
1466
|
+
maxVal = Math.max(rgb.r, rgb.g, rgb.b),
|
1467
|
+
delta = maxVal - minVal,
|
1468
|
+
del_R, del_G, del_B,
|
1469
|
+
hsv = {
|
1470
|
+
h: 0,
|
1471
|
+
s: 0,
|
1472
|
+
v: maxVal
|
1473
|
+
};
|
1474
|
+
|
1475
|
+
if (delta === 0) {
|
1476
|
+
hsv.h = 0;
|
1477
|
+
hsv.s = 0;
|
1478
|
+
} else {
|
1479
|
+
hsv.s = delta / maxVal;
|
1480
|
+
|
1481
|
+
del_R = (((maxVal - rgb.r) / 6) + (delta / 2)) / delta;
|
1482
|
+
del_G = (((maxVal - rgb.g) / 6) + (delta / 2)) / delta;
|
1483
|
+
del_B = (((maxVal - rgb.b) / 6) + (delta / 2)) / delta;
|
1484
|
+
|
1485
|
+
if (rgb.r === maxVal) {
|
1486
|
+
hsv.h = del_B - del_G;
|
1487
|
+
} else if (rgb.g === maxVal) {
|
1488
|
+
hsv.h = (1 / 3) + del_R - del_B;
|
1489
|
+
} else if (rgb.b === maxVal) {
|
1490
|
+
hsv.h = (2 / 3) + del_G - del_R;
|
1491
|
+
}
|
1492
|
+
|
1493
|
+
if (hsv.h < 0) {
|
1494
|
+
hsv.h += 1;
|
1495
|
+
} else if (hsv.h > 1) {
|
1496
|
+
hsv.h -= 1;
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
return hsv;
|
1501
|
+
},
|
1502
|
+
_hsv_to_rgb = function(hsv) {
|
1503
|
+
var rgb = {
|
1504
|
+
r: 0,
|
1505
|
+
g: 0,
|
1506
|
+
b: 0
|
1507
|
+
},
|
1508
|
+
var_h,
|
1509
|
+
var_i,
|
1510
|
+
var_1,
|
1511
|
+
var_2,
|
1512
|
+
var_3;
|
1513
|
+
|
1514
|
+
if (hsv.s === 0) {
|
1515
|
+
rgb.r = rgb.g = rgb.b = hsv.v;
|
1516
|
+
} else {
|
1517
|
+
var_h = hsv.h === 1 ? 0 : hsv.h * 6;
|
1518
|
+
var_i = Math.floor(var_h);
|
1519
|
+
var_1 = hsv.v * (1 - hsv.s);
|
1520
|
+
var_2 = hsv.v * (1 - hsv.s * (var_h - var_i));
|
1521
|
+
var_3 = hsv.v * (1 - hsv.s * (1 - (var_h - var_i)));
|
1522
|
+
|
1523
|
+
if (var_i === 0) {
|
1524
|
+
rgb.r = hsv.v;
|
1525
|
+
rgb.g = var_3;
|
1526
|
+
rgb.b = var_1;
|
1527
|
+
} else if (var_i === 1) {
|
1528
|
+
rgb.r = var_2;
|
1529
|
+
rgb.g = hsv.v;
|
1530
|
+
rgb.b = var_1;
|
1531
|
+
} else if (var_i === 2) {
|
1532
|
+
rgb.r = var_1;
|
1533
|
+
rgb.g = hsv.v;
|
1534
|
+
rgb.b = var_3;
|
1535
|
+
} else if (var_i === 3) {
|
1536
|
+
rgb.r = var_1;
|
1537
|
+
rgb.g = var_2;
|
1538
|
+
rgb.b = hsv.v;
|
1539
|
+
} else if (var_i === 4) {
|
1540
|
+
rgb.r = var_3;
|
1541
|
+
rgb.g = var_1;
|
1542
|
+
rgb.b = hsv.v;
|
1543
|
+
} else {
|
1544
|
+
rgb.r = hsv.v;
|
1545
|
+
rgb.g = var_1;
|
1546
|
+
rgb.b = var_2;
|
1547
|
+
}
|
1548
|
+
}
|
1549
|
+
|
1550
|
+
return rgb;
|
1551
|
+
},
|
1552
|
+
_rgb_to_hsl = function(rgb) {
|
1553
|
+
var minVal = Math.min(rgb.r, rgb.g, rgb.b),
|
1554
|
+
maxVal = Math.max(rgb.r, rgb.g, rgb.b),
|
1555
|
+
delta = maxVal - minVal,
|
1556
|
+
del_R, del_G, del_B,
|
1557
|
+
hsl = {
|
1558
|
+
h: 0,
|
1559
|
+
s: 0,
|
1560
|
+
l: (maxVal + minVal) / 2
|
1561
|
+
};
|
1562
|
+
|
1563
|
+
if (delta === 0) {
|
1564
|
+
hsl.h = 0;
|
1565
|
+
hsl.s = 0;
|
1566
|
+
} else {
|
1567
|
+
hsl.s = hsl.l < 0.5 ? delta / (maxVal + minVal) : delta / (2 - maxVal - minVal);
|
1568
|
+
|
1569
|
+
del_R = (((maxVal - rgb.r) / 6) + (delta / 2)) / delta;
|
1570
|
+
del_G = (((maxVal - rgb.g) / 6) + (delta / 2)) / delta;
|
1571
|
+
del_B = (((maxVal - rgb.b) / 6) + (delta / 2)) / delta;
|
1572
|
+
|
1573
|
+
if (rgb.r === maxVal) {
|
1574
|
+
hsl.h = del_B - del_G;
|
1575
|
+
} else if (rgb.g === maxVal) {
|
1576
|
+
hsl.h = (1 / 3) + del_R - del_B;
|
1577
|
+
} else if (rgb.b === maxVal) {
|
1578
|
+
hsl.h = (2 / 3) + del_G - del_R;
|
1579
|
+
}
|
1580
|
+
|
1581
|
+
if (hsl.h < 0) {
|
1582
|
+
hsl.h += 1;
|
1583
|
+
} else if (hsl.h > 1) {
|
1584
|
+
hsl.h -= 1;
|
1585
|
+
}
|
1586
|
+
}
|
1587
|
+
|
1588
|
+
return hsl;
|
1589
|
+
},
|
1590
|
+
_hsl_to_rgb = function(hsl) {
|
1591
|
+
var var_1,
|
1592
|
+
var_2,
|
1593
|
+
hue_to_rgb = function(v1, v2, vH) {
|
1594
|
+
if (vH < 0) {
|
1595
|
+
vH += 1;
|
1596
|
+
}
|
1597
|
+
if (vH > 1) {
|
1598
|
+
vH -= 1;
|
1599
|
+
}
|
1600
|
+
if ((6 * vH) < 1) {
|
1601
|
+
return v1 + (v2 - v1) * 6 * vH;
|
1602
|
+
}
|
1603
|
+
if ((2 * vH) < 1) {
|
1604
|
+
return v2;
|
1605
|
+
}
|
1606
|
+
if ((3 * vH) < 2) {
|
1607
|
+
return v1 + (v2 - v1) * ((2 / 3) - vH) * 6;
|
1608
|
+
}
|
1609
|
+
return v1;
|
1610
|
+
};
|
1611
|
+
|
1612
|
+
if (hsl.s === 0) {
|
1613
|
+
return {
|
1614
|
+
r: hsl.l,
|
1615
|
+
g: hsl.l,
|
1616
|
+
b: hsl.l
|
1617
|
+
};
|
1618
|
+
}
|
1619
|
+
|
1620
|
+
var_2 = (hsl.l < 0.5) ? hsl.l * (1 + hsl.s) : (hsl.l + hsl.s) - (hsl.s * hsl.l);
|
1621
|
+
var_1 = 2 * hsl.l - var_2;
|
1622
|
+
|
1623
|
+
return {
|
1624
|
+
r: hue_to_rgb(var_1, var_2, hsl.h + (1 / 3)),
|
1625
|
+
g: hue_to_rgb(var_1, var_2, hsl.h),
|
1626
|
+
b: hue_to_rgb(var_1, var_2, hsl.h - (1 / 3))
|
1627
|
+
};
|
1628
|
+
},
|
1629
|
+
_xyz_to_lab = function(xyz) {
|
1630
|
+
var x = xyz.x / illuminant[0],
|
1631
|
+
y = xyz.y / illuminant[1],
|
1632
|
+
z = xyz.z / illuminant[2];
|
1633
|
+
|
1634
|
+
x = (x > 0.008856) ? Math.pow(x, (1/3)) : (7.787 * x) + (16/116);
|
1635
|
+
y = (y > 0.008856) ? Math.pow(y, (1/3)) : (7.787 * y) + (16/116);
|
1636
|
+
z = (z > 0.008856) ? Math.pow(z, (1/3)) : (7.787 * z) + (16/116);
|
1637
|
+
|
1638
|
+
return {
|
1639
|
+
l: ((116 * y) - 16) / 100, // [0,100]
|
1640
|
+
a: ((500 * (x - y)) + 128) / 255, // [-128,127]
|
1641
|
+
b: ((200 * (y - z)) + 128) / 255 // [-128,127]
|
1642
|
+
};
|
1643
|
+
},
|
1644
|
+
_lab_to_xyz = function(lab) {
|
1645
|
+
var lab2 = {
|
1646
|
+
l: lab.l * 100,
|
1647
|
+
a: (lab.a * 255) - 128,
|
1648
|
+
b: (lab.b * 255) - 128
|
1649
|
+
},
|
1650
|
+
xyz = {
|
1651
|
+
x: 0,
|
1652
|
+
y: (lab2.l + 16) / 116,
|
1653
|
+
z: 0
|
1654
|
+
};
|
1655
|
+
|
1656
|
+
xyz.x = lab2.a / 500 + xyz.y;
|
1657
|
+
xyz.z = xyz.y - lab2.b / 200;
|
1658
|
+
|
1659
|
+
xyz.x = (Math.pow(xyz.x, 3) > 0.008856) ? Math.pow(xyz.x, 3) : (xyz.x - 16 / 116) / 7.787;
|
1660
|
+
xyz.y = (Math.pow(xyz.y, 3) > 0.008856) ? Math.pow(xyz.y, 3) : (xyz.y - 16 / 116) / 7.787;
|
1661
|
+
xyz.z = (Math.pow(xyz.z, 3) > 0.008856) ? Math.pow(xyz.z, 3) : (xyz.z - 16 / 116) / 7.787;
|
1662
|
+
|
1663
|
+
xyz.x *= illuminant[0];
|
1664
|
+
xyz.y *= illuminant[1];
|
1665
|
+
xyz.z *= illuminant[2];
|
1666
|
+
|
1667
|
+
return xyz;
|
1668
|
+
},
|
1669
|
+
_rgb_to_cmy = function(rgb) {
|
1670
|
+
return {
|
1671
|
+
c: 1 - (rgb.r),
|
1672
|
+
m: 1 - (rgb.g),
|
1673
|
+
y: 1 - (rgb.b)
|
1674
|
+
};
|
1675
|
+
},
|
1676
|
+
_cmy_to_rgb = function(cmy) {
|
1677
|
+
return {
|
1678
|
+
r: 1 - (cmy.c),
|
1679
|
+
g: 1 - (cmy.m),
|
1680
|
+
b: 1 - (cmy.y)
|
1681
|
+
};
|
1682
|
+
},
|
1683
|
+
_cmy_to_cmyk = function(cmy) {
|
1684
|
+
var K = 1;
|
1685
|
+
|
1686
|
+
if (cmy.c < K) {
|
1687
|
+
K = cmy.c;
|
1688
|
+
}
|
1689
|
+
if (cmy.m < K) {
|
1690
|
+
K = cmy.m;
|
1691
|
+
}
|
1692
|
+
if (cmy.y < K) {
|
1693
|
+
K = cmy.y;
|
1694
|
+
}
|
1695
|
+
|
1696
|
+
if (K == 1) {
|
1697
|
+
return {
|
1698
|
+
c: 0,
|
1699
|
+
m: 0,
|
1700
|
+
y: 0,
|
1701
|
+
k: 1
|
1702
|
+
};
|
1703
|
+
}
|
1704
|
+
|
1705
|
+
return {
|
1706
|
+
c: (cmy.c - K) / (1 - K),
|
1707
|
+
m: (cmy.m - K) / (1 - K),
|
1708
|
+
y: (cmy.y - K) / (1 - K),
|
1709
|
+
k: K
|
1710
|
+
};
|
1711
|
+
},
|
1712
|
+
_cmyk_to_cmy = function(cmyk) {
|
1713
|
+
return {
|
1714
|
+
c: cmyk.c * (1 - cmyk.k) + cmyk.k,
|
1715
|
+
m: cmyk.m * (1 - cmyk.k) + cmyk.k,
|
1716
|
+
y: cmyk.y * (1 - cmyk.k) + cmyk.k
|
1717
|
+
};
|
1718
|
+
};
|
1719
|
+
|
1720
|
+
this.set = false;
|
1721
|
+
|
1722
|
+
this.setAlpha = function(_a) {
|
1723
|
+
if (_a !== null) {
|
1724
|
+
a = _clip(_a);
|
1725
|
+
}
|
1726
|
+
|
1727
|
+
return this;
|
1728
|
+
};
|
1729
|
+
|
1730
|
+
this.getAlpha = function() {
|
1731
|
+
return a;
|
1732
|
+
};
|
1733
|
+
|
1734
|
+
this.setRGB = function(r, g, b) {
|
1735
|
+
spaces = { rgb: this.getRGB() };
|
1736
|
+
if (r !== null) {
|
1737
|
+
spaces.rgb.r = _clip(r);
|
1738
|
+
}
|
1739
|
+
if (g !== null) {
|
1740
|
+
spaces.rgb.g = _clip(g);
|
1741
|
+
}
|
1742
|
+
if (b !== null) {
|
1743
|
+
spaces.rgb.b = _clip(b);
|
1744
|
+
}
|
1745
|
+
|
1746
|
+
return this;
|
1747
|
+
};
|
1748
|
+
|
1749
|
+
this.setHSV = function(h, s, v) {
|
1750
|
+
spaces = {hsv: this.getHSV()};
|
1751
|
+
if (h !== null) {
|
1752
|
+
spaces.hsv.h = _clip(h);
|
1753
|
+
}
|
1754
|
+
if (s !== null) {
|
1755
|
+
spaces.hsv.s = _clip(s);
|
1756
|
+
}
|
1757
|
+
if (v !== null) {
|
1758
|
+
spaces.hsv.v = _clip(v);
|
1759
|
+
}
|
1760
|
+
|
1761
|
+
return this;
|
1762
|
+
};
|
1763
|
+
|
1764
|
+
this.setHSL = function(h, s, l) {
|
1765
|
+
spaces = {hsl: this.getHSL()};
|
1766
|
+
if (h !== null) {
|
1767
|
+
spaces.hsl.h = _clip(h);
|
1768
|
+
}
|
1769
|
+
if (s !== null) {
|
1770
|
+
spaces.hsl.s = _clip(s);
|
1771
|
+
}
|
1772
|
+
if (l !== null) {
|
1773
|
+
spaces.hsl.l = _clip(l);
|
1774
|
+
}
|
1775
|
+
|
1776
|
+
return this;
|
1777
|
+
};
|
1778
|
+
|
1779
|
+
this.setLAB = function(l, a, b) {
|
1780
|
+
spaces = {lab: this.getLAB()};
|
1781
|
+
if (l !== null) {
|
1782
|
+
spaces.lab.l = _clip(l);
|
1783
|
+
}
|
1784
|
+
if (a !== null) {
|
1785
|
+
spaces.lab.a = _clip(a);
|
1786
|
+
}
|
1787
|
+
if (b !== null) {
|
1788
|
+
spaces.lab.b = _clip(b);
|
1789
|
+
}
|
1790
|
+
|
1791
|
+
return this;
|
1792
|
+
};
|
1793
|
+
|
1794
|
+
this.setCMYK = function(c, m, y, k) {
|
1795
|
+
spaces = {cmyk: this.getCMYK()};
|
1796
|
+
if (c !== null) {
|
1797
|
+
spaces.cmyk.c = _clip(c);
|
1798
|
+
}
|
1799
|
+
if (m !== null) {
|
1800
|
+
spaces.cmyk.m = _clip(m);
|
1801
|
+
}
|
1802
|
+
if (y !== null) {
|
1803
|
+
spaces.cmyk.y = _clip(y);
|
1804
|
+
}
|
1805
|
+
if (k !== null) {
|
1806
|
+
spaces.cmyk.k = _clip(k);
|
1807
|
+
}
|
1808
|
+
|
1809
|
+
return this;
|
1810
|
+
};
|
1811
|
+
|
1812
|
+
this.getRGB = function() {
|
1813
|
+
if (!spaces.rgb) {
|
1814
|
+
spaces.rgb = spaces.lab ? _xyz_to_rgb(_lab_to_xyz(spaces.lab))
|
1815
|
+
: spaces.hsv ? _hsv_to_rgb(spaces.hsv)
|
1816
|
+
: spaces.hsl ? _hsl_to_rgb(spaces.hsl)
|
1817
|
+
: spaces.cmyk ? _cmy_to_rgb(_cmyk_to_cmy(spaces.cmyk))
|
1818
|
+
: {r: 0, g: 0, b: 0};
|
1819
|
+
spaces.rgb.r = _clip(spaces.rgb.r);
|
1820
|
+
spaces.rgb.g = _clip(spaces.rgb.g);
|
1821
|
+
spaces.rgb.b = _clip(spaces.rgb.b);
|
1822
|
+
}
|
1823
|
+
return $.extend({}, spaces.rgb);
|
1824
|
+
};
|
1825
|
+
|
1826
|
+
this.getHSV = function() {
|
1827
|
+
if (!spaces.hsv) {
|
1828
|
+
spaces.hsv = spaces.lab ? _rgb_to_hsv(this.getRGB())
|
1829
|
+
: spaces.rgb ? _rgb_to_hsv(spaces.rgb)
|
1830
|
+
: spaces.hsl ? _rgb_to_hsv(this.getRGB())
|
1831
|
+
: spaces.cmyk ? _rgb_to_hsv(this.getRGB())
|
1832
|
+
: {h: 0, s: 0, v: 0};
|
1833
|
+
spaces.hsv.h = _clip(spaces.hsv.h);
|
1834
|
+
spaces.hsv.s = _clip(spaces.hsv.s);
|
1835
|
+
spaces.hsv.v = _clip(spaces.hsv.v);
|
1836
|
+
}
|
1837
|
+
return $.extend({}, spaces.hsv);
|
1838
|
+
};
|
1839
|
+
|
1840
|
+
this.getHSL = function() {
|
1841
|
+
if (!spaces.hsl) {
|
1842
|
+
spaces.hsl = spaces.rgb ? _rgb_to_hsl(spaces.rgb)
|
1843
|
+
: spaces.hsv ? _rgb_to_hsl(this.getRGB())
|
1844
|
+
: spaces.cmyk ? _rgb_to_hsl(this.getRGB())
|
1845
|
+
: spaces.hsv ? _rgb_to_hsl(this.getRGB())
|
1846
|
+
: {h: 0, s: 0, l: 0};
|
1847
|
+
spaces.hsl.h = _clip(spaces.hsl.h);
|
1848
|
+
spaces.hsl.s = _clip(spaces.hsl.s);
|
1849
|
+
spaces.hsl.l = _clip(spaces.hsl.l);
|
1850
|
+
}
|
1851
|
+
return $.extend({}, spaces.hsl);
|
1852
|
+
};
|
1853
|
+
|
1854
|
+
this.getCMYK = function() {
|
1855
|
+
if (!spaces.cmyk) {
|
1856
|
+
spaces.cmyk = spaces.rgb ? _cmy_to_cmyk(_rgb_to_cmy(spaces.rgb))
|
1857
|
+
: spaces.hsv ? _cmy_to_cmyk(_rgb_to_cmy(this.getRGB()))
|
1858
|
+
: spaces.hsl ? _cmy_to_cmyk(_rgb_to_cmy(this.getRGB()))
|
1859
|
+
: spaces.lab ? _cmy_to_cmyk(_rgb_to_cmy(this.getRGB()))
|
1860
|
+
: {c: 0, m: 0, y: 0, k: 1};
|
1861
|
+
spaces.cmyk.c = _clip(spaces.cmyk.c);
|
1862
|
+
spaces.cmyk.m = _clip(spaces.cmyk.m);
|
1863
|
+
spaces.cmyk.y = _clip(spaces.cmyk.y);
|
1864
|
+
spaces.cmyk.k = _clip(spaces.cmyk.k);
|
1865
|
+
}
|
1866
|
+
return $.extend({}, spaces.cmyk);
|
1867
|
+
};
|
1868
|
+
|
1869
|
+
this.getLAB = function() {
|
1870
|
+
if (!spaces.lab) {
|
1871
|
+
spaces.lab = spaces.rgb ? _xyz_to_lab(_rgb_to_xyz(spaces.rgb))
|
1872
|
+
: spaces.hsv ? _xyz_to_lab(_rgb_to_xyz(this.getRGB()))
|
1873
|
+
: spaces.hsl ? _xyz_to_lab(_rgb_to_xyz(this.getRGB()))
|
1874
|
+
: spaces.cmyk ? _xyz_to_lab(_rgb_to_xyz(this.getRGB()))
|
1875
|
+
: {l: 0, a: 0, b: 0};
|
1876
|
+
spaces.lab.l = _clip(spaces.lab.l);
|
1877
|
+
spaces.lab.a = _clip(spaces.lab.a);
|
1878
|
+
spaces.lab.b = _clip(spaces.lab.b);
|
1879
|
+
}
|
1880
|
+
return $.extend({}, spaces.lab);
|
1881
|
+
};
|
1882
|
+
|
1883
|
+
this.getChannels = function() {
|
1884
|
+
return {
|
1885
|
+
r: this.getRGB().r,
|
1886
|
+
g: this.getRGB().g,
|
1887
|
+
b: this.getRGB().b,
|
1888
|
+
a: this.getAlpha(),
|
1889
|
+
h: this.getHSV().h,
|
1890
|
+
s: this.getHSV().s,
|
1891
|
+
v: this.getHSV().v,
|
1892
|
+
c: this.getCMYK().c,
|
1893
|
+
m: this.getCMYK().m,
|
1894
|
+
y: this.getCMYK().y,
|
1895
|
+
k: this.getCMYK().k,
|
1896
|
+
L: this.getLAB().l,
|
1897
|
+
A: this.getLAB().a,
|
1898
|
+
B: this.getLAB().b
|
1899
|
+
};
|
1900
|
+
};
|
1901
|
+
|
1902
|
+
this.getSpaces = function() {
|
1903
|
+
return $.extend(true, {}, spaces);
|
1904
|
+
};
|
1905
|
+
|
1906
|
+
this.setSpaces = function(new_spaces) {
|
1907
|
+
spaces = new_spaces;
|
1908
|
+
return this;
|
1909
|
+
};
|
1910
|
+
|
1911
|
+
this.distance = function(color) {
|
1912
|
+
var space = 'lab',
|
1913
|
+
getter = 'get'+space.toUpperCase(),
|
1914
|
+
a = this[getter](),
|
1915
|
+
b = color[getter](),
|
1916
|
+
distance = 0,
|
1917
|
+
channel;
|
1918
|
+
|
1919
|
+
for (channel in a) {
|
1920
|
+
distance += Math.pow(a[channel] - b[channel], 2);
|
1921
|
+
}
|
1922
|
+
|
1923
|
+
return distance;
|
1924
|
+
};
|
1925
|
+
|
1926
|
+
this.equals = function(color) {
|
1927
|
+
var a = this.getRGB(),
|
1928
|
+
b = color.getRGB();
|
1929
|
+
|
1930
|
+
return this.getAlpha() === color.getAlpha()
|
1931
|
+
&& a.r === b.r
|
1932
|
+
&& a.g === b.g
|
1933
|
+
&& a.b === b.b;
|
1934
|
+
};
|
1935
|
+
|
1936
|
+
this.limit = function(steps) {
|
1937
|
+
steps -= 1;
|
1938
|
+
var rgb = this.getRGB();
|
1939
|
+
this.setRGB(
|
1940
|
+
Math.round(rgb.r * steps) / steps,
|
1941
|
+
Math.round(rgb.g * steps) / steps,
|
1942
|
+
Math.round(rgb.b * steps) / steps
|
1943
|
+
);
|
1944
|
+
};
|
1945
|
+
|
1946
|
+
this.toHex = function() {
|
1947
|
+
var rgb = this.getRGB();
|
1948
|
+
return _hexify(rgb.r * 255) + _hexify(rgb.g * 255) + _hexify(rgb.b * 255);
|
1949
|
+
};
|
1950
|
+
|
1951
|
+
this.toCSS = function() {
|
1952
|
+
return '#' + this.toHex();
|
1953
|
+
};
|
1954
|
+
|
1955
|
+
this.normalize = function() {
|
1956
|
+
this.setHSV(null, 1, 1);
|
1957
|
+
return this;
|
1958
|
+
};
|
1959
|
+
|
1960
|
+
this.copy = function() {
|
1961
|
+
var color = new $.colorpicker.Color(this.getSpaces(), this.getAlpha());
|
1962
|
+
color.set = this.set;
|
1963
|
+
return color;
|
1964
|
+
};
|
1965
|
+
|
1966
|
+
// Construct
|
1967
|
+
if (args.length === 2) {
|
1968
|
+
this.setSpaces(args[0]);
|
1969
|
+
this.setAlpha(args[1] === 0 ? 0 : args[1] || 1);
|
1970
|
+
this.set = true;
|
1971
|
+
}
|
1972
|
+
if (args.length > 2) {
|
1973
|
+
this.setRGB(args[0], args[1], args[2]);
|
1974
|
+
this.setAlpha(args[3] === 0 ? 0 : args[3] || 1);
|
1975
|
+
this.set = true;
|
1976
|
+
}
|
1977
|
+
};
|
1978
|
+
};
|
1979
|
+
|
1980
|
+
$.widget("vanderlee.colorpicker", {
|
1981
|
+
options: {
|
1982
|
+
alpha: false, // Show alpha controls and mode
|
1983
|
+
altAlpha: true, // change opacity of altField as well?
|
1984
|
+
altField: '', // selector for DOM elements which change background color on change.
|
1985
|
+
altOnChange: true, // true to update on each change, false to update only on close.
|
1986
|
+
altProperties: 'background-color', // comma separated list of any of 'background-color', 'color', 'border-color', 'outline-color'
|
1987
|
+
autoOpen: false, // Open dialog automatically upon creation
|
1988
|
+
buttonClass: null, // If set, the button will get this/these classname(s).
|
1989
|
+
buttonColorize: false,
|
1990
|
+
buttonImage: 'images/ui-colorpicker.png',
|
1991
|
+
buttonImageOnly: false,
|
1992
|
+
buttonText: null, // Text on the button and/or title of button image.
|
1993
|
+
closeOnEscape: true, // Close the dialog when the escape key is pressed.
|
1994
|
+
closeOnOutside: true, // Close the dialog when clicking outside the dialog (not for inline)
|
1995
|
+
color: '#00FF00', // Initial color (for inline only)
|
1996
|
+
colorFormat: 'HEX', // Format string for output color format
|
1997
|
+
draggable: true, // Make popup dialog draggable if header is visible.
|
1998
|
+
duration: 'fast',
|
1999
|
+
hsv: true, // Show HSV controls and modes
|
2000
|
+
inline: true, // Show any divs as inline by default
|
2001
|
+
inlineFrame: true, // Show a border and background when inline.
|
2002
|
+
layout: {
|
2003
|
+
map: [0, 0, 1, 5], // Left, Top, Width, Height (in table cells).
|
2004
|
+
bar: [1, 0, 1, 5],
|
2005
|
+
preview: [2, 0, 1, 1],
|
2006
|
+
hsv: [2, 1, 1, 1],
|
2007
|
+
rgb: [2, 2, 1, 1],
|
2008
|
+
alpha: [2, 3, 1, 1],
|
2009
|
+
hex: [2, 4, 1, 1],
|
2010
|
+
lab: [3, 1, 1, 1],
|
2011
|
+
cmyk: [3, 2, 1, 2],
|
2012
|
+
swatches: [4, 0, 1, 5]
|
2013
|
+
},
|
2014
|
+
limit: '', // Limit color "resolution": '', 'websafe', 'nibble', 'binary', 'name'
|
2015
|
+
modal: false, // Modal dialog?
|
2016
|
+
mode: 'h', // Initial editing mode, h, s, v, r, g, b or a
|
2017
|
+
parts: '', // leave empty for automatic selection
|
2018
|
+
regional: '',
|
2019
|
+
revert: false, // Revert color upon non
|
2020
|
+
rgb: true, // Show RGB controls and modes
|
2021
|
+
showAnim: 'fadeIn',
|
2022
|
+
showCancelButton: true,
|
2023
|
+
showNoneButton: false,
|
2024
|
+
showCloseButton: true,
|
2025
|
+
showOn: 'focus click alt', // 'focus', 'click', 'button', 'alt', 'both'
|
2026
|
+
showOptions: {},
|
2027
|
+
swatches: null, // null for default or kv-object or names swatches set
|
2028
|
+
swatchesWidth: 84, // width (in number of pixels) of swatches box.
|
2029
|
+
title: null,
|
2030
|
+
|
2031
|
+
cancel: null,
|
2032
|
+
close: null,
|
2033
|
+
init: null,
|
2034
|
+
select: null,
|
2035
|
+
ok: null,
|
2036
|
+
open: null
|
2037
|
+
},
|
2038
|
+
|
2039
|
+
_create: function () {
|
2040
|
+
var that = this,
|
2041
|
+
text;
|
2042
|
+
|
2043
|
+
++_colorpicker_index;
|
2044
|
+
|
2045
|
+
that.widgetEventPrefix = 'colorpicker';
|
2046
|
+
|
2047
|
+
that.opened = false;
|
2048
|
+
that.generated = false;
|
2049
|
+
that.inline = false;
|
2050
|
+
that.changed = false;
|
2051
|
+
|
2052
|
+
that.dialog = null;
|
2053
|
+
that.button = null;
|
2054
|
+
that.image = null;
|
2055
|
+
that.overlay = null;
|
2056
|
+
|
2057
|
+
that.mode = that.options.mode;
|
2058
|
+
if (that.element.is('input') || that.options.inline === false) {
|
2059
|
+
that._setColor(that.element.is('input') ? that.element.val() : that.options.color);
|
2060
|
+
|
2061
|
+
this._callback('init');
|
2062
|
+
|
2063
|
+
$('body').append(_container_popup);
|
2064
|
+
that.dialog = $('.ui-colorpicker:last');
|
2065
|
+
|
2066
|
+
// Close on clicking outside window and controls
|
2067
|
+
$(document).delegate('html', 'touchstart click', function (event) {
|
2068
|
+
if (!that.opened || event.target === that.element[0] || that.overlay) {
|
2069
|
+
return;
|
2070
|
+
}
|
2071
|
+
|
2072
|
+
// Check if clicked on any part of dialog
|
2073
|
+
if (that.dialog.is(event.target) || that.dialog.has(event.target).length > 0) {
|
2074
|
+
that.element.blur(); // inside window!
|
2075
|
+
return;
|
2076
|
+
}
|
2077
|
+
|
2078
|
+
// Check if clicked on known external elements
|
2079
|
+
var p,
|
2080
|
+
parents = $(event.target).parents();
|
2081
|
+
// add the event.target in case of buttonImageOnly and closeOnOutside both are set to true
|
2082
|
+
parents.push(event.target);
|
2083
|
+
for (p = 0; p <= parents.length; ++p) {
|
2084
|
+
// button
|
2085
|
+
if (that.button !== null && parents[p] === that.button[0]) {
|
2086
|
+
return;
|
2087
|
+
}
|
2088
|
+
// showOn alt
|
2089
|
+
if (/\balt|both\b/.test(that.options.showOn) && $(that.options.altField).is(parents[p])) {
|
2090
|
+
return;
|
2091
|
+
}
|
2092
|
+
}
|
2093
|
+
|
2094
|
+
// no closeOnOutside
|
2095
|
+
if (!that.options.closeOnOutside) {
|
2096
|
+
return;
|
2097
|
+
}
|
2098
|
+
|
2099
|
+
that.close(that.options.revert);
|
2100
|
+
});
|
2101
|
+
|
2102
|
+
// close on ESC key
|
2103
|
+
$(document).keydown(function (event) {
|
2104
|
+
if (event.keyCode == 27 && that.opened && that.options.closeOnEscape) {
|
2105
|
+
that.close(that.options.revert);
|
2106
|
+
}
|
2107
|
+
});
|
2108
|
+
|
2109
|
+
// showOn focus
|
2110
|
+
if (/\bfocus|both\b/.test(that.options.showOn)) {
|
2111
|
+
that.element.bind('focus', function () {
|
2112
|
+
that.open();
|
2113
|
+
});
|
2114
|
+
}
|
2115
|
+
|
2116
|
+
// showOn click
|
2117
|
+
if (/\bclick|both\b/.test(that.options.showOn)) {
|
2118
|
+
that.element.bind('click', function () {
|
2119
|
+
that.open();
|
2120
|
+
});
|
2121
|
+
}
|
2122
|
+
|
2123
|
+
// showOn button
|
2124
|
+
if (/\bbutton|both\b/.test(that.options.showOn)) {
|
2125
|
+
if (that.options.buttonImage !== '') {
|
2126
|
+
text = that.options.buttonText || that._getRegional('button');
|
2127
|
+
|
2128
|
+
that.image = $('<img/>').attr({
|
2129
|
+
'src': that.options.buttonImage,
|
2130
|
+
'alt': text,
|
2131
|
+
'title': text
|
2132
|
+
});
|
2133
|
+
if (that.options.buttonClass) {
|
2134
|
+
that.image.attr('class', that.options.buttonClass);
|
2135
|
+
}
|
2136
|
+
|
2137
|
+
that._setImageBackground();
|
2138
|
+
}
|
2139
|
+
|
2140
|
+
if (that.options.buttonImageOnly && that.image) {
|
2141
|
+
that.button = that.image;
|
2142
|
+
} else {
|
2143
|
+
that.button = $('<button type="button"></button>').html(that.image || that.options.buttonText).button();
|
2144
|
+
that.image = that.image ? $('img', that.button).first() : null;
|
2145
|
+
}
|
2146
|
+
that.button.insertAfter(that.element).click(function () {
|
2147
|
+
that[that.opened ? 'close' : 'open']();
|
2148
|
+
});
|
2149
|
+
}
|
2150
|
+
|
2151
|
+
// showOn alt
|
2152
|
+
if (/\balt|both\b/.test(that.options.showOn)) {
|
2153
|
+
$(that.options.altField).bind('click', function () {
|
2154
|
+
that.open();
|
2155
|
+
});
|
2156
|
+
}
|
2157
|
+
|
2158
|
+
if (that.options.autoOpen) {
|
2159
|
+
that.open();
|
2160
|
+
}
|
2161
|
+
|
2162
|
+
that.element.keydown(function (event) {
|
2163
|
+
if (event.keyCode === 9) {
|
2164
|
+
that.close();
|
2165
|
+
}
|
2166
|
+
}).keyup(function (event) {
|
2167
|
+
var color = that._parseColor(that.element.val());
|
2168
|
+
if (!that.color.equals(color)) {
|
2169
|
+
that.color = color;
|
2170
|
+
that._change();
|
2171
|
+
}
|
2172
|
+
});
|
2173
|
+
} else {
|
2174
|
+
that.inline = true;
|
2175
|
+
|
2176
|
+
$(this.element).html(that.options.inlineFrame ? _container_inlineFrame : _container_inline);
|
2177
|
+
that.dialog = $('.ui-colorpicker', this.element);
|
2178
|
+
|
2179
|
+
that._generate();
|
2180
|
+
|
2181
|
+
that.opened = true;
|
2182
|
+
}
|
2183
|
+
|
2184
|
+
return this;
|
2185
|
+
},
|
2186
|
+
|
2187
|
+
_setOption: function(key, value){
|
2188
|
+
var that = this;
|
2189
|
+
|
2190
|
+
switch (key) {
|
2191
|
+
case "disabled":
|
2192
|
+
if (value) {
|
2193
|
+
that.dialog.addClass('ui-colorpicker-disabled');
|
2194
|
+
} else {
|
2195
|
+
that.dialog.removeClass('ui-colorpicker-disabled');
|
2196
|
+
}
|
2197
|
+
break;
|
2198
|
+
}
|
2199
|
+
|
2200
|
+
$.Widget.prototype._setOption.apply(that, arguments);
|
2201
|
+
},
|
2202
|
+
|
2203
|
+
_setImageBackground: function() {
|
2204
|
+
if (this.image && this.options.buttonColorize) {
|
2205
|
+
this.image.css('background-color', this.color.set? this._formatColor('RGBA', this.color) : '');
|
2206
|
+
}
|
2207
|
+
},
|
2208
|
+
|
2209
|
+
/**
|
2210
|
+
* If an alternate field is specified, set it according to the current color.
|
2211
|
+
*/
|
2212
|
+
_setAltField: function () {
|
2213
|
+
if (this.options.altOnChange && this.options.altField && this.options.altProperties) {
|
2214
|
+
var index,
|
2215
|
+
property,
|
2216
|
+
properties = this.options.altProperties.split(',');
|
2217
|
+
|
2218
|
+
for (index = 0; index <= properties.length; ++index) {
|
2219
|
+
property = $.trim(properties[index]);
|
2220
|
+
switch (property) {
|
2221
|
+
case 'color':
|
2222
|
+
case 'background-color':
|
2223
|
+
case 'backgroundColor':
|
2224
|
+
case 'outline-color':
|
2225
|
+
case 'border-color':
|
2226
|
+
$(this.options.altField).css(property, this.color.set? this.color.toCSS() : '');
|
2227
|
+
break;
|
2228
|
+
}
|
2229
|
+
}
|
2230
|
+
|
2231
|
+
if (this.options.altAlpha) {
|
2232
|
+
$(this.options.altField).css('opacity', this.color.set? this.color.getAlpha() : '');
|
2233
|
+
}
|
2234
|
+
}
|
2235
|
+
},
|
2236
|
+
|
2237
|
+
_setColor: function(text) {
|
2238
|
+
this.color = this._parseColor(text);
|
2239
|
+
this.currentColor = this.color.copy();
|
2240
|
+
|
2241
|
+
this._setImageBackground();
|
2242
|
+
this._setAltField();
|
2243
|
+
},
|
2244
|
+
|
2245
|
+
setColor: function(text) {
|
2246
|
+
this._setColor(text);
|
2247
|
+
this._change(this.color.set);
|
2248
|
+
},
|
2249
|
+
|
2250
|
+
_generate: function () {
|
2251
|
+
var that = this,
|
2252
|
+
index,
|
2253
|
+
part,
|
2254
|
+
parts_list,
|
2255
|
+
layout_parts;
|
2256
|
+
|
2257
|
+
that._setColor(that.inline || !that.element.is('input') ? that.options.color : that.element.val());
|
2258
|
+
|
2259
|
+
// Determine the parts to include in this colorpicker
|
2260
|
+
if (typeof that.options.parts === 'string') {
|
2261
|
+
if ($.colorpicker.partslists[that.options.parts]) {
|
2262
|
+
parts_list = $.colorpicker.partslists[that.options.parts];
|
2263
|
+
} else {
|
2264
|
+
// automatic
|
2265
|
+
parts_list = $.colorpicker.partslists[that.inline ? 'inline' : 'popup'];
|
2266
|
+
}
|
2267
|
+
} else {
|
2268
|
+
parts_list = that.options.parts;
|
2269
|
+
}
|
2270
|
+
|
2271
|
+
// Add any parts to the internal parts list
|
2272
|
+
that.parts = {};
|
2273
|
+
$.each(parts_list, function(index, part) {
|
2274
|
+
if ($.colorpicker.parts[part]) {
|
2275
|
+
that.parts[part] = new $.colorpicker.parts[part](that);
|
2276
|
+
}
|
2277
|
+
});
|
2278
|
+
|
2279
|
+
if (!that.generated) {
|
2280
|
+
layout_parts = [];
|
2281
|
+
|
2282
|
+
$.each(that.options.layout, function(part, pos) {
|
2283
|
+
if (that.parts[part]) {
|
2284
|
+
layout_parts.push({
|
2285
|
+
'part': part,
|
2286
|
+
'pos': pos
|
2287
|
+
});
|
2288
|
+
}
|
2289
|
+
});
|
2290
|
+
|
2291
|
+
var table = $(_layoutTable(layout_parts, function(cell, x, y) {
|
2292
|
+
var classes = ['ui-colorpicker-' + cell.part + '-container'];
|
2293
|
+
|
2294
|
+
if (x > 0) {
|
2295
|
+
classes.push('ui-colorpicker-padding-left');
|
2296
|
+
}
|
2297
|
+
|
2298
|
+
if (y > 0) {
|
2299
|
+
classes.push('ui-colorpicker-padding-top');
|
2300
|
+
}
|
2301
|
+
|
2302
|
+
return '<td class="' + classes.join(' ') + '"'
|
2303
|
+
+ (cell.pos[2] > 1 ? ' colspan="' + cell.pos[2] + '"' : '')
|
2304
|
+
+ (cell.pos[3] > 1 ? ' rowspan="' + cell.pos[3] + '"' : '')
|
2305
|
+
+ ' valign="top"></td>';
|
2306
|
+
})).appendTo(that.dialog);
|
2307
|
+
if (that.options.inlineFrame) {
|
2308
|
+
table.addClass('ui-dialog-content ui-widget-content');
|
2309
|
+
}
|
2310
|
+
|
2311
|
+
that._initAllParts();
|
2312
|
+
that._updateAllParts();
|
2313
|
+
that.generated = true;
|
2314
|
+
}
|
2315
|
+
},
|
2316
|
+
|
2317
|
+
_effectGeneric: function (element, show, slide, fade, callback) {
|
2318
|
+
var that = this;
|
2319
|
+
|
2320
|
+
if ($.effects && $.effects[that.options.showAnim]) {
|
2321
|
+
element[show](that.options.showAnim, that.options.showOptions, that.options.duration, callback);
|
2322
|
+
} else {
|
2323
|
+
element[(that.options.showAnim === 'slideDown' ?
|
2324
|
+
slide
|
2325
|
+
: (that.options.showAnim === 'fadeIn' ?
|
2326
|
+
fade
|
2327
|
+
: show))]((that.options.showAnim ? that.options.duration : null), callback);
|
2328
|
+
if (!that.options.showAnim || !that.options.duration) {
|
2329
|
+
callback();
|
2330
|
+
}
|
2331
|
+
}
|
2332
|
+
},
|
2333
|
+
|
2334
|
+
_effectShow: function(element, callback) {
|
2335
|
+
this._effectGeneric(element, 'show', 'slideDown', 'fadeIn', callback);
|
2336
|
+
},
|
2337
|
+
|
2338
|
+
_effectHide: function(element, callback) {
|
2339
|
+
this._effectGeneric(element, 'hide', 'slideUp', 'fadeOut', callback);
|
2340
|
+
},
|
2341
|
+
|
2342
|
+
open: function() {
|
2343
|
+
var that = this,
|
2344
|
+
offset,
|
2345
|
+
bottom,
|
2346
|
+
right,
|
2347
|
+
height,
|
2348
|
+
width,
|
2349
|
+
x,
|
2350
|
+
y,
|
2351
|
+
zIndex;
|
2352
|
+
|
2353
|
+
if (!that.opened) {
|
2354
|
+
that._generate();
|
2355
|
+
|
2356
|
+
if (that.element.is(':hidden')) {
|
2357
|
+
var hiddenPlaceholder = $('<div/>').insertBefore(that.element);
|
2358
|
+
offset = hiddenPlaceholder.offset();
|
2359
|
+
hiddenPlaceholder.remove();
|
2360
|
+
} else {
|
2361
|
+
offset = that.element.offset();
|
2362
|
+
}
|
2363
|
+
bottom = $(window).height() + $(window).scrollTop();
|
2364
|
+
right = $(window).width() + $(window).scrollLeft();
|
2365
|
+
height = that.dialog.outerHeight();
|
2366
|
+
width = that.dialog.outerWidth();
|
2367
|
+
x = offset.left;
|
2368
|
+
y = offset.top + that.element.outerHeight();
|
2369
|
+
|
2370
|
+
if (x + width > right) {
|
2371
|
+
x = Math.max(0, right - width);
|
2372
|
+
}
|
2373
|
+
|
2374
|
+
if (y + height > bottom) {
|
2375
|
+
if (offset.top - height >= $(window).scrollTop()) {
|
2376
|
+
y = offset.top - height;
|
2377
|
+
} else {
|
2378
|
+
y = Math.max(0, bottom - height);
|
2379
|
+
}
|
2380
|
+
}
|
2381
|
+
|
2382
|
+
that.dialog.css({'left': x, 'top': y});
|
2383
|
+
|
2384
|
+
// Automatically find highest z-index.
|
2385
|
+
zIndex = 0;
|
2386
|
+
$(that.element[0]).parents().each(function() {
|
2387
|
+
var z = $(this).css('z-index');
|
2388
|
+
if ((typeof(z) === 'number' || typeof(z) === 'string') && z !== '' && !isNaN(z)) {
|
2389
|
+
zIndex = parseInt(z);
|
2390
|
+
return false;
|
2391
|
+
}
|
2392
|
+
});
|
2393
|
+
|
2394
|
+
//@todo zIndexOffset option, to raise above other elements?
|
2395
|
+
that.dialog.css('z-index', zIndex += 2);
|
2396
|
+
|
2397
|
+
that.overlay = that.options.modal ? new $.ui.dialog.overlay(that) : null;
|
2398
|
+
|
2399
|
+
that._effectShow(this.dialog);
|
2400
|
+
that.opened = true;
|
2401
|
+
that._callback('open', true);
|
2402
|
+
|
2403
|
+
// Without waiting for domready the width of the map is 0 and we
|
2404
|
+
// wind up with the cursor stuck in the upper left corner
|
2405
|
+
$(function() {
|
2406
|
+
that._repaintAllParts();
|
2407
|
+
});
|
2408
|
+
}
|
2409
|
+
},
|
2410
|
+
|
2411
|
+
close: function (cancel) {
|
2412
|
+
var that = this;
|
2413
|
+
|
2414
|
+
if (cancel) {
|
2415
|
+
that.color = that.currentColor.copy();
|
2416
|
+
that._change(that.color.set);
|
2417
|
+
that._callback('cancel', true);
|
2418
|
+
} else {
|
2419
|
+
that.currentColor = that.color.copy();
|
2420
|
+
that._callback('ok', true);
|
2421
|
+
}
|
2422
|
+
that.changed = false;
|
2423
|
+
|
2424
|
+
// tear down the interface
|
2425
|
+
that._effectHide(that.dialog, function () {
|
2426
|
+
that.dialog.empty();
|
2427
|
+
that.generated = false;
|
2428
|
+
|
2429
|
+
that.opened = false;
|
2430
|
+
that._callback('close', true);
|
2431
|
+
});
|
2432
|
+
|
2433
|
+
if (that.overlay) {
|
2434
|
+
that.overlay.destroy();
|
2435
|
+
}
|
2436
|
+
},
|
2437
|
+
|
2438
|
+
destroy: function() {
|
2439
|
+
this.element.unbind();
|
2440
|
+
|
2441
|
+
if (this.image !== null) {
|
2442
|
+
this.image.remove();
|
2443
|
+
}
|
2444
|
+
|
2445
|
+
if (this.button !== null) {
|
2446
|
+
this.button.remove();
|
2447
|
+
}
|
2448
|
+
|
2449
|
+
if (this.dialog !== null) {
|
2450
|
+
this.dialog.remove();
|
2451
|
+
}
|
2452
|
+
|
2453
|
+
if (this.overlay) {
|
2454
|
+
this.overlay.destroy();
|
2455
|
+
}
|
2456
|
+
},
|
2457
|
+
|
2458
|
+
_callback: function (callback, spaces) {
|
2459
|
+
var that = this,
|
2460
|
+
data,
|
2461
|
+
lab;
|
2462
|
+
|
2463
|
+
if (that.color.set) {
|
2464
|
+
data = {
|
2465
|
+
formatted: that._formatColor(that.options.colorFormat, that.color)
|
2466
|
+
};
|
2467
|
+
|
2468
|
+
lab = that.color.getLAB();
|
2469
|
+
lab.a = (lab.a * 2) - 1;
|
2470
|
+
lab.b = (lab.b * 2) - 1;
|
2471
|
+
|
2472
|
+
if (spaces === true) {
|
2473
|
+
data.a = that.color.getAlpha();
|
2474
|
+
data.rgb = that.color.getRGB();
|
2475
|
+
data.hsv = that.color.getHSV();
|
2476
|
+
data.cmyk = that.color.getCMYK();
|
2477
|
+
data.hsl = that.color.getHSL();
|
2478
|
+
data.lab = lab;
|
2479
|
+
}
|
2480
|
+
|
2481
|
+
return that._trigger(callback, null, data);
|
2482
|
+
} else {
|
2483
|
+
return that._trigger(callback, null, {
|
2484
|
+
formatted: ''
|
2485
|
+
});
|
2486
|
+
}
|
2487
|
+
},
|
2488
|
+
|
2489
|
+
_initAllParts: function () {
|
2490
|
+
$.each(this.parts, function (index, part) {
|
2491
|
+
if (part.init) {
|
2492
|
+
part.init();
|
2493
|
+
}
|
2494
|
+
});
|
2495
|
+
},
|
2496
|
+
|
2497
|
+
_updateAllParts: function () {
|
2498
|
+
$.each(this.parts, function (index, part) {
|
2499
|
+
if (part.update) {
|
2500
|
+
part.update();
|
2501
|
+
}
|
2502
|
+
});
|
2503
|
+
},
|
2504
|
+
|
2505
|
+
_repaintAllParts: function () {
|
2506
|
+
$.each(this.parts, function (index, part) {
|
2507
|
+
if (part.repaint) {
|
2508
|
+
part.repaint();
|
2509
|
+
}
|
2510
|
+
});
|
2511
|
+
},
|
2512
|
+
|
2513
|
+
_change: function (set /* = true */) {
|
2514
|
+
this.color.set = (set !== false);
|
2515
|
+
|
2516
|
+
this.changed = true;
|
2517
|
+
|
2518
|
+
// Limit color palette
|
2519
|
+
if (this.options.limit && $.colorpicker.limits[this.options.limit]) {
|
2520
|
+
$.colorpicker.limits[this.options.limit](this.color, this);
|
2521
|
+
}
|
2522
|
+
|
2523
|
+
// update input element content
|
2524
|
+
if (!this.inline) {
|
2525
|
+
if (!this.color.set) {
|
2526
|
+
this.element.val('');
|
2527
|
+
} else if (!this.color.equals(this._parseColor(this.element.val()))) {
|
2528
|
+
this.element.val(this._formatColor(this.options.colorFormat, this.color));
|
2529
|
+
}
|
2530
|
+
|
2531
|
+
this._setImageBackground();
|
2532
|
+
this._setAltField();
|
2533
|
+
}
|
2534
|
+
|
2535
|
+
// update color option
|
2536
|
+
this.options.color = this.color.set ? this.color.toCSS() : '';
|
2537
|
+
|
2538
|
+
if (this.opened) {
|
2539
|
+
this._repaintAllParts();
|
2540
|
+
}
|
2541
|
+
|
2542
|
+
// callback
|
2543
|
+
this._callback('select');
|
2544
|
+
},
|
2545
|
+
|
2546
|
+
// This will be deprecated by jQueryUI 1.9 widget
|
2547
|
+
_hoverable: function (e) {
|
2548
|
+
e.hover(function () {
|
2549
|
+
e.addClass("ui-state-hover");
|
2550
|
+
}, function () {
|
2551
|
+
e.removeClass("ui-state-hover");
|
2552
|
+
});
|
2553
|
+
},
|
2554
|
+
|
2555
|
+
// This will be deprecated by jQueryUI 1.9 widget
|
2556
|
+
_focusable: function (e) {
|
2557
|
+
e.focus(function () {
|
2558
|
+
e.addClass("ui-state-focus");
|
2559
|
+
}).blur(function () {
|
2560
|
+
e.removeClass("ui-state-focus");
|
2561
|
+
});
|
2562
|
+
},
|
2563
|
+
|
2564
|
+
_getRegional: function(name) {
|
2565
|
+
return $.colorpicker.regional[this.options.regional][name] !== undefined ?
|
2566
|
+
$.colorpicker.regional[this.options.regional][name] : $.colorpicker.regional[''][name];
|
2567
|
+
},
|
2568
|
+
|
2569
|
+
_getSwatches: function() {
|
2570
|
+
if (typeof(this.options.swatches) === 'string') {
|
2571
|
+
return $.colorpicker.swatches[this.options.swatches];
|
2572
|
+
}
|
2573
|
+
|
2574
|
+
if ($.isPlainObject(this.options.swatches)) {
|
2575
|
+
return $.colorpicker.swatches;
|
2576
|
+
}
|
2577
|
+
|
2578
|
+
return $.colorpicker.swatches.html;
|
2579
|
+
},
|
2580
|
+
|
2581
|
+
_getSwatch: function(name) {
|
2582
|
+
var swatches = this._getSwatches(),
|
2583
|
+
swatch = false;
|
2584
|
+
|
2585
|
+
if (swatches[name] !== undefined) {
|
2586
|
+
return swatches[name];
|
2587
|
+
}
|
2588
|
+
|
2589
|
+
$.each(swatches, function(swatchName, current) {
|
2590
|
+
if (swatchName.toLowerCase() == name.toLowerCase()) {
|
2591
|
+
swatch = current;
|
2592
|
+
return false;
|
2593
|
+
}
|
2594
|
+
return true;
|
2595
|
+
});
|
2596
|
+
|
2597
|
+
return swatch;
|
2598
|
+
},
|
2599
|
+
|
2600
|
+
_parseColor: function(color) {
|
2601
|
+
var that = this,
|
2602
|
+
c;
|
2603
|
+
|
2604
|
+
$.each($.colorpicker.parsers, function(name, parser) {
|
2605
|
+
if (c = parser(color, that)) {
|
2606
|
+
return false;
|
2607
|
+
}
|
2608
|
+
});
|
2609
|
+
|
2610
|
+
if (c) {
|
2611
|
+
return c;
|
2612
|
+
}
|
2613
|
+
|
2614
|
+
return new $.colorpicker.Color();
|
2615
|
+
},
|
2616
|
+
|
2617
|
+
_exactName: function(color) {
|
2618
|
+
var name = false;
|
2619
|
+
|
2620
|
+
$.each(this._getSwatches(), function(n, swatch) {
|
2621
|
+
if (color.equals(new $.colorpicker.Color(swatch.r, swatch.g, swatch.b))) {
|
2622
|
+
name = n;
|
2623
|
+
return false;
|
2624
|
+
}
|
2625
|
+
return true;
|
2626
|
+
});
|
2627
|
+
|
2628
|
+
return name;
|
2629
|
+
},
|
2630
|
+
|
2631
|
+
_closestName: function(color) {
|
2632
|
+
var rgb = color.getRGB(),
|
2633
|
+
distance = null,
|
2634
|
+
name = false,
|
2635
|
+
d;
|
2636
|
+
|
2637
|
+
$.each(this._getSwatches(), function(n, swatch) {
|
2638
|
+
d = color.distance(new $.colorpicker.Color(swatch.r, swatch.g, swatch.b));
|
2639
|
+
if (d < distance || distance === null) {
|
2640
|
+
name = n;
|
2641
|
+
if (d == 0) {
|
2642
|
+
return false; // can't get much closer than 0
|
2643
|
+
}
|
2644
|
+
distance = d;
|
2645
|
+
}
|
2646
|
+
return true;
|
2647
|
+
});
|
2648
|
+
|
2649
|
+
return name;
|
2650
|
+
},
|
2651
|
+
|
2652
|
+
_formatColor: function (formats, color) {
|
2653
|
+
var that = this,
|
2654
|
+
text = null,
|
2655
|
+
types = { 'x': function(v) {return _intToHex(v * 255);}
|
2656
|
+
, 'd': function(v) {return Math.floor(v * 255);}
|
2657
|
+
, 'f': function(v) {return v;}
|
2658
|
+
, 'p': function(v) {return v * 100;}
|
2659
|
+
},
|
2660
|
+
channels = color.getChannels();
|
2661
|
+
|
2662
|
+
if (!$.isArray(formats)) {
|
2663
|
+
formats = [formats];
|
2664
|
+
}
|
2665
|
+
|
2666
|
+
$.each(formats, function(index, format) {
|
2667
|
+
if ($.colorpicker.writers[format]) {
|
2668
|
+
text = $.colorpicker.writers[format](color, that);
|
2669
|
+
return (text === false);
|
2670
|
+
} else {
|
2671
|
+
text = format.replace(/\\?[argbhsvcmykLAB][xdfp]/g, function(m) {
|
2672
|
+
if (m.match(/^\\/)) {
|
2673
|
+
return m.slice(1);
|
2674
|
+
}
|
2675
|
+
return types[m.charAt(1)](channels[m.charAt(0)]);
|
2676
|
+
});
|
2677
|
+
return false;
|
2678
|
+
}
|
2679
|
+
});
|
2680
|
+
|
2681
|
+
return text;
|
2682
|
+
}
|
2683
|
+
});
|
2684
|
+
}(jQuery));
|