-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
517 lines (469 loc) · 25.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Color Picker Sliders</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="An advanced responsive color selector with color swatches and support for human perceived lightness. Works in all modern browsers and on touch devices.">
<meta name="author" content="István Ujj-Mészáros">
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" media="all">
<link href="libraries/prettify/prettify.css" rel="stylesheet" type="text/css" media="all">
<link href="demo.css" rel="stylesheet" type="text/css" media="all">
<link href="jquery-colorpickersliders/jquery.colorpickersliders.css" rel="stylesheet" type="text/css" media="all">
<script src="libraries/jquery-1.9.0.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="libraries/prettify/prettify.js"></script>
<script src="libraries/tinycolor.js"></script>
<script src="jquery-colorpickersliders/jquery.colorpickersliders.js"></script>
</head>
<body>
<div class="container">
<div class="hero-unit">
<h1>jQuery Color Picker Sliders<small> with human color perception</small></h1>
<a id="link-ghp" class="btn btn-primary" href="https://github.com/istvan-ujjmeszaros/jquery-colorpickersliders" target="_blank"><span class="glyphicon glyphicon-link"></span> Github project page</a>
<a id="link-ghdl" href="https://github.com/istvan-ujjmeszaros/jquery-colorpickersliders/archive/master.zip" class="btn btn-primary" title="download"><span class="glyphicon glyphicon-download"></span> Download</a>
</div>
<blockquote>A jQuery plugin that overhauls the classic color pickers and provides users with a whole new way of selecting desired color codes. <small>Softpedia.com</small></blockquote>
<p>
Do you know the difference between the usual HSL and the human perceived (CIE Lch) sliders?
</p>
<h2>See the difference</h2>
<p>
Use the HSL hue slider, and the human perceived lightness will change a lot between the different hue angles (blue seems to be darker than yellow). Use the CIE hue slider, and the perceived lightness remains much more constant.
</p>
<span class="demo1"></span>
<script>
$(".demo1").ColorPickerSliders({
flat: true,
color: 'orange',
order: {
cie: 1,
hsl: 2,
opacity: 3,
preview: 4
},
labels: {
cielightness: 'Human perceived lightness',
ciechroma: 'CIE Chroma',
ciehue: 'CIE Hue'
}
});
</script>
<p>
Update color from code: <a class="btn btn-default updatecolor" data-updatecolor="hsl(0,100%,50%)">hsl(0,100%,50%)</a> <a class="btn btn-default updatecolor" data-updatecolor="rgba(0,255,0,0.5)">rgba(0,255,0,0.5)</a> <a class="btn btn-default updatecolor" data-updatecolor="blue">blue</a> <a class="btn btn-default updatecolor" data-updatecolor="#ffff00">#ffff00</a> <a class="btn btn-default updatecolor" data-updatecolor="transparent">transparent</a>
<p>
<script>
$('.updatecolor').on('click', function(e) {
$(".demo1").trigger('colorpickersliders.updateColor', $(this).data("updatecolor"));
});
</script>
<h2>Color picker in a popup</h2>
<p>
<input type="text" class="a-popup" data-color-format="hex" value="GreenYellow"> <small>Hint: you can type in any CSS color (even named ones, like yellow).</small>
</p>
<script>
$(".a-popup").ColorPickerSliders({
order: {
hsl: 1
}
});
</script>
<h2>Let's see some different color pickers in action</h2>
<h3>HSL Color Picker</h3>
<p>
The following demo uses the HSL sliders with preview.
</p>
<div class="row">
<div class="col-md-6">
<pre class="prettyprint">
<span class="hsl-demo"></span>
$(".hsl-demo").ColorPickerSliders({
flat: true,
previewformat: 'hsl',
order: {
hsl: 1,
preview: 2
}
});</pre>
</div>
<div class="col-md-6">
<span class="hsl-demo"></span>
<script>
$(".hsl-demo").ColorPickerSliders({
flat: true,
previewformat: 'hsl',
order: {
hsl: 1,
preview: 2
}
});
</script>
</div>
</div>
<h3>CIE Lch Color Picker <small>with human perceived lightness</small></h3>
<p>
The following demo uses the CIE Lch sliders with human perceived lightness. It uses a different <code>customswatches</code> name and different default <code>swatches</code>, so the swatches are independent from the other color pickers on this page.
</p>
<div class="row">
<div class="col-md-6">
<pre class="prettyprint">
<span class="cielch-demo"></span>
$(".cielch-demo").ColorPickerSliders({
flat: true,
customswatches: "different-swatches-groupname",
swatches: ["rgb(174, 156, 227)","rgb(29, 179, 229)","rgb(54, 185, 163)","rgb(144, 176, 105)","rgb(224, 148, 110)","rgb(233, 137, 168)"],
order: {
cie: 1,
preview: 2
}
});</pre>
</div>
<div class="col-md-6">
<span class="cielch-demo"></span>
<script>
$(".cielch-demo").ColorPickerSliders({
flat: true,
customswatches: "different-swatches-groupname",
swatches: ["rgb(174, 156, 227)", "rgb(29, 179, 229)", "rgb(54, 185, 163)", "rgb(144, 176, 105)", "rgb(224, 148, 110)", "rgb(233, 137, 168)"],
order: {
cie: 1,
preview: 2
}
});
</script>
</div>
</div>
<h3>RGB Color Picker</h3>
<p>
The following demo uses the RGB and opacity sliders. The swatches are disabled for this color picker.
</p>
<div class="row">
<div class="col-md-6">
<pre class="prettyprint">
<span class="rgb-demo"></span>
$(".rgb-demo").ColorPickerSliders({
flat: true,
swatches: false,
order: {
rgb: 1,
opacity: 2
},
labels: {
rgbred: 'Red',
rgbgreen: 'Green',
rgbblue: 'Blue'
}
});</pre>
</div>
<div class="col-md-6">
<span class="rgb-demo"></span>
<script>
$(".rgb-demo").ColorPickerSliders({
flat: true,
swatches: false,
order: {
rgb: 1,
opacity: 2
},
labels: {
rgbred: 'Red',
rgbgreen: 'Green',
rgbblue: 'Blue'
}
});
</script>
</div>
</div>
<h3>Popup on any element</h3>
<p>
The following example is linked to different elements and rendered in popups. Only the cutom swatches are disabled for this demo, so you can use the predefined swatches.
</p>
<pre class="prettyprint">
<input id="color" type="text" class="demo-popup" value="#56B29A" data-color-format="hex">
<button type="button" class="demo-popup">button</button>
<span class="demo-popup">span</span>
<a class="demo-popup">link</a>
$('.demo-popup').ColorPickerSliders({
previewontriggerelement: true,
flat: false,
color: '#cf966f',
customswatches: false,
swatches: ['red', 'green', 'blue'],
order: {
rgb: 1,
preview: 2
}
});</pre>
<form class="form-horizontal" action="#">
<div class="control-group">
<label class="control-label" for="color">Color: </label>
<div class="controls controls-row">
<input id="color" type="text" class="demo-popup" value="#56B29A" data-color-format="hex">
<button type="button" class="demo-popup">button</button>
<span class="demo-popup">span</span>
<a class="demo-popup">link</a>
</div>
</div>
</form>
<script>
$('.demo-popup').ColorPickerSliders({
previewontriggerelement: true,
flat: false,
color: '#cf966f',
customswatches: false,
swatches: ['red', 'green', 'blue'],
order: {
rgb: 1,
preview: 2
}
});
</script>
<h3>Example for using the <code>onchange()</code> setting</h3>
<p>
<input type="text" class="onchange-example" data-color-format="hex" value="GreenYellow"> <span class="onchange-example" style="padding:3px;border:1px solid #ccc;">this span is updated on change</span>
</p>
<script>
$("input.onchange-example").ColorPickerSliders({
order: {
hsl: 1
},
onchange: function(container, color) {
var span = $("span.onchange-example");
span.css("background-color", color.tiny.toRgbString());
if (color.cielch.l < 60) {
span.css("color", "white");
}
else {
span.css("color", "black");
}
}
});
</script>
<pre class="prettyprint">
<input type="text" class="onchange-example" data-color-format="hex" value="GreenYellow"> <span class="onchange-example" style="padding:3px;border:1px solid #ccc;">this span is updated on change</span>
<script>
$("input.onchange-example").ColorPickerSliders({
order: {
hsl: 1
},
onchange: function(container, color) {
var span = $("span.onchange-example");
span.css("background-color", color.tiny.toRgbString());
if (color.cielch.l < 60) {
span.css("color", "white");
}
else {
span.css("color", "black");
}
}
});
</script></pre>
<h3>A full-blown example showing all the sliders in action</h3>
<p>
The following demo uses all the sliders, and connects to a bunch of inputs to show the actual color values in different formats. The color format can be set on the inputs <code>data-color-format</code> property.
</p>
<p>
The color can be updated via any of the connected inputs. The plugin uses the excellent <a href="https://github.com/bgrins/TinyColor" target="_blank">Tiny Color</a> plugin, so it handles all valid CSS color formats (CSS color names as well!).
</p>
<pre class="prettyprint">
<input type="text" class="full-demo-input" data-color-format="hsl">
<input type="text" class="full-demo-input" data-color-format="hex">
<input type="text" class="full-demo full-demo-input" data-color-format="rgb">
$(".full-demo").ColorPickerSliders({
flat: true,
invalidcolorsopacity: 0,
connectedinput: '.full-demo-input'
});</pre>
<div class="control-group">
<div class="controls controls-row">
<input type="text" class="full-demo-input" data-color-format="hsl">
<input type="text" class="full-demo-input" data-color-format="hex">
<input type="text" class="full-demo full-demo-input" data-color-format="rgb">
</div>
</div>
<span class="full-demo"></span>
<script>
$("span.full-demo").ColorPickerSliders({
flat: true,
invalidcolorsopacity: 0,
previewontriggerelement: false,
connectedinput: '.full-demo-input'
});
</script>
<h2>How perceived lightness work?</h2>
<p>
This color picker can work internally in the CIE Lab color space, represented with the CIE Lch color model. The benefit is the consistent lightness and chroma values between the different colors, so it can represent yellow and blue with the same human perceived lightness. This is not the case with the more known RGB or HSL color models, where yellow is much brighter than blue. Altough, this color picker supports them as well, so you can decide which way to go.
</p>
<h2>What is the drawback of using CIE Lch?</h2>
<p>
In CIE Lch model, there are colors that can not be converted to RGB values (for example there is no dark yellow color with high chroma value). When there is an Lch variation that can not be represented in the RGB color space, then the color picker searches for the highest possible chroma value for that particular color (for example the only valid chroma value for black or white colors is 0), and uses the lowered chroma value for conversion. This way the color's hue and the lightness will not distorted.
</p>
<h3>CIE Lch color picker with hidden invalid color ranges</h3>
<p>
The position markers on the sliders are always shows an exclamation mark when the actual Lch setting can not be converted to an RGB value, but there is more to it! You can make the invalid colors invisible or semi-transparent using the <code>invalidcolorsopacity</code> setting. This way it is easier to find different hues or lightness with the same chroma.<br>
You can notice that if the chroma is set to too high, then the preview shows the actual color with the highest possible chroma value. See it in action:
</p>
<div class="row">
<div class="col-md-6">
<pre class="prettyprint">
<span class="cielch-demo2"></span>
$(".cielch-demo2").ColorPickerSliders({
flat: true,
invalidcolorsopacity: 0.2,
order: {
cie: 1,
preview: 2
}
});</pre>
</div>
<div class="col-md-6">
<span class="cielch-demo2"></span>
<script>
$(".cielch-demo2").ColorPickerSliders({
flat: true,
invalidcolorsopacity: 0.2,
order: {
cie: 1,
preview: 2
}
});
</script>
</div>
</div>
<h2>Settings</h2>
<table class="table table-striped table-bordered docs">
<thead>
<tr>
<th>Option</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>color</code></td>
<td>This is the initial color if there is no valid (any CSS formatted) color value on the connected input element. Can be in any format that <a href="https://github.com/bgrins/TinyColor" target="_blank">Tiny Color supports</a>.</td>
</tr>
<tr>
<td><code>previewformat</code></td>
<td>This is the color format on the preview slider (if visible). Can be <strong><code>rgb</code></strong>, <code>hsl</code> or <code>hex</code>. Note that hex format can not represent the opacity value.</td>
</tr>
<tr>
<td><code>preventtouchkeyboardonshow</code></td>
<td><code><strong>true</strong></code>: Makes the input readonly to prevent touch keyboard to show up on focus, needs a second click to become editable.</td>
</tr>
<tr>
<td><code>swatches</code></td>
<td><code>array</code>: Array of CSS colors (can be CSS color names as well).<br>
<code>false</code>: The swatches are disabled.</td>
</tr>
<tr>
<td><code>customswatches</code></td>
<td><code>string</code>: Name of the custom swatches group. Color pickers with the same <code>customswatches</code> name share the same swatch colors, so if you add a new color to one of the color pickers, then all the color pickers swatches will be updated on the page which has the same <code>customswatches</code> name.<br>
<code>false</code>: The custom swatches are disabled, so only the predefined swatches can be used.</td>
</tr>
<tr>
<td><code>connectedinput</code></td>
<td><code><strong>selector or jQuery object</strong></code>: The connected input elements value will be automatically updated in sync with the color picker. The color format which the color is represented i the input can be set via the <code>data-color-format</code> property. It can be any of <code>hex</code>, <code>hsl</code> or <code>rgb</code>. If it is hex, then the opacity will be discarded.</td>
</tr>
<tr>
<td><code>flat</code></td>
<td><code><strong>false</strong></code>: The color picker is rendered in a popup, which is shown on focus of the connected element.<br>
<code>true</code>: The color picker is rendered right after the connected element, and is always visible.</td>
</tr>
<tr>
<td><code>disableautopopup</code></td>
<td><code>false</code>: The popup will be visible on blu or on click.<br>
<code>true</code>: No popup shown on blur or on click. Must trigger <code>colorpickersliders.showPopup</code> and <code>colorpickersliders.hidePopup</code> events to show/hide the popup.</td>
</tr>
<tr>
<td><code>updateinterval</code></td>
<td>Update interval of the sliders while dragging (ms). The default is 30.</td>
</tr>
<tr>
<td><code>previewontriggerelement</code></td>
<td><code><strong>true</strong></code>: Preview of the color on the connected element's background.<br>
<code>false</code>: No preview on the connected element.</td>
</tr>
<tr>
<td><code>previewcontrasttreshold</code></td>
<td><code><strong>30</strong></code>: If <code>previewontriggerelement</code> is enabled, then if the lightness is below of this value, the element's text color will be white. Otherwise the text is black.</td>
</tr>
<tr>
<td><code>erroneousciecolormarkers</code></td>
<td><code><strong>true</strong></code>: Unconvertable CIE colors are marked with an exclamation mark on the CIE sliders level marker.<br>
<code>false</code>: No exclamation mark on the markers.</td>
</tr>
<tr>
<td><code>invalidcolorsopacity</code></td>
<td><code><strong>1</strong></code>: Opacity of the invalid (unconvertable) area of the CIE sliders.</td>
</tr>
<tr>
<td><code>finercierangeedges</code></td>
<td><code><strong>true</strong></code>: Sharper, more accurate edges of the valid CIE ranges on the sliders.<br>
<code><strong>false</strong></code>: Smoother edges of the valid CIE ranges on the sliders.</td>
</tr>
<tr>
<td><code>order</code></td>
<td>An object which defines which sliders appear and in which order.<br>
Possible properties: <code>opacity</code>, <code>hsl</code>, <code>rgb</code>, <code>cie</code>, <code>preview</code>.</td>
</tr>
<tr>
<td><code>labels</code></td>
<td>An object which defines the labels of the sliders.<br>
Possible properties: <code>hslhue</code>, <code>hslsaturation</code>, <code>hsllightness</code>, <code>rgbred</code>, <code>rgbgreen</code>, <code>rgbblue</code>, <code>cielightness</code>, <code>ciechroma</code>, <code>ciehue</code>, <code>opacity</code>, <code>preview</code>.</td>
</tr>
<tr>
<td><code>onchange</code></td>
<td><code>function(container, color)</code>: This function is triggered when the color is changed with the sliders or via a connected input. The <code>color</code> parameter holds the actual color object in the following formats: rgb object, hsl object, cie lch object, <a href="https://github.com/bgrins/TinyColor" target="_blank">Tiny Color</a> object.</td>
</tr>
<tr>
<td><code>titleswatchesadd</code></td>
<td><code>string</code>: Title of the add color to swatches button.</td>
</tr>
<tr>
<td><code>titleswatchesreset</code></td>
<td><code>string</code>: Title of the reset swatches button.</td>
</tr>
</tbody>
</table>
<h2>Events</h2>
<p>
Example usage: <code>$("#colorpicker").trigger("colorpickersliders.updateColor", "red");</code>
</p>
<p>
The following events can be triggered on the element which the color picker is initialized on.
</p>
<table class="table table-striped table-bordered docs">
<thead>
<tr>
<th>Event</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>colorpickersliders.destroy</code></td>
<td><code>function()</code>: Destroys the color picker.</td>
</tr>
<tr>
<td><code>colorpickersliders.reset</code></td>
<td><code>function()</code>: Reinitializes the color picker.</td>
</tr>
<tr>
<td><code>colorpickersliders.updateColor</code></td>
<td><code>function(newcolor)</code>: Sets a new color for the color picker.</td>
</tr>
<tr>
<td><code>colorpickersliders.showPopup</code></td>
<td><code>function()</code>: Shows the popup if the color picker uses it (it's not flat).</td>
</tr>
<tr>
<td><code>colorpickersliders.hidePopup</code></td>
<td><code>function()</code>: Hides the popup if the color picker uses it (it's not flat).</td>
</tr>
</tbody>
</table>
</div>
<script>
prettyPrint();
</script>