-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathexample.html
526 lines (456 loc) · 14.5 KB
/
example.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
518
519
520
521
522
523
524
525
526
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Wheel Color Picker Plugin Example</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="author" content="Fajar Chandra" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('.snippet-output').each(function() {
var snippetId = $(this).data('id');
var snippet = $('#'+snippetId);
var html = $(
'<a href="#">Show code</a>' +
'<pre>' + snippet.get(0).innerHTML.replace(/</g, '<').replace(/\n\t\t/g, "\n") + '</pre>'
);
$(this).append(html);
$(this).children('a').on('click', function() {
var container = $(this).closest('.snippet-output');
if(container.hasClass('visible')) {
container.removeClass('visible');
}
else {
container.addClass('visible');
}
return false;
});
});
});
</script>
<style type="text/css">
body {
font-family: "Tahoma", "Arial", sans-serif;
font-size: 14px;
line-height: 1.5em;
margin: 20px auto;
padding: 0 20px;
max-width: 920px;
color: #000;
background: #fff;
}
a {
color: #008000;
text-decoration: none;
}
a:hover {
color: #800080;
}
p {
margin: 15px 0;
}
h1 {
font-weight: normal;
font-size: 36px;
line-height: 1.25em;
border-bottom: dotted 2px #888;
}
h2 {
font-weight: normal;
font-size: 24px;
}
hr {
border-top: dotted 2px #888;
}
code {
background: #eee;
border: dotted 1px #ccc;
}
select,
input[type=text],
input[type=button] {
background: #fff;
color: #000;
font-family: "Tahoma", "Arial", sans-serif;
font-size: 14px;
border: solid 1px #aaa;
border-radius: 4px;
box-shadow: inset 1px 1px 1px rgba(0,0,0,.3);
padding: 0 5px;
box-sizing: border-box;
height: 26px;
line-height: 26px;
}
input[type=button] {
background: #fff;
box-shadow: inset -1px -1px 1px rgba(0,0,0,.3);
}
input[type=button]:active {
box-shadow: inset 1px 1px 1px rgba(0,0,0,.3);
}
input[type=text][readonly] {
background: #ddd;
}
.row {
margin: 0 -10px;
}
.row:after {
content: '';
display: block;
clear: both;
}
.col-4 {
float: left;
width: 25%;
padding: 0 10px;
box-sizing: border-box;
}
.col-4 select,
.col-4 input {
width: 100%;
box-sizing: border-box;
}
@media (max-width: 760px) {
.col-4 {
width: 50%;
}
.col-sm-1 {
width: 100%;
}
}
@media (max-width: 380px) {
.col-4 {
width: 100%;
}
}
.snippet-output {
margin: 15px 0;
border: solid 1px #aaa;
border-radius: 4px;
}
.snippet-output a {
display: block;
padding: 5px;
background: #aaa;
color: #fff;
cursor: pointer;
text-decoration: none;
}
.snippet-output a:hover {
background: #008000;
}
.snippet-output pre {
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
margin: 0;
padding: 0 5px;
max-height: 0;
overflow: hidden;
opacity: 0;
font-size: 12px;
line-height: 18px;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAkCAIAAADHFsdbAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QIGETER/26APAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAGElEQVQI12P4/v07EwMDA8X4w4cP1DAHAHREBfzc+YN9AAAAAElFTkSuQmCC') top;
transition: opacity .5s, padding .5s ease-out, max-height .5s ease-out;
}
.snippet-output.visible pre {
max-height: 1500px;
opacity: 1;
overflow: auto;
transition: opacity .5s, max-height .5s ease-in;
}
</style>
</head>
<body>
<h1>Wheel Color Picker Plugin Example</h1>
<h2>Getting Started</h2>
<p>
To use jQuery Wheel Color Picker Plugin, first you must include <code>jquery.js</code> (obviously),
<code>jquery.wheelcolorpicker.js</code>, and <code>wheelcolorpicker.css</code>.
</p>
<div id="snippet-header" class="snippet">
<script type="text/javascript" src="jquery.wheelcolorpicker.js"></script>
<link type="text/css" rel="stylesheet" href="css/wheelcolorpicker.css" />
</div>
<div class="snippet-output" data-id="snippet-header"></div>
<p>
There are two ways to initialize color picker. One is by adding
<code>data-wheelcolorpicker</code> attribute to the input element. The other
way is by invoking <code>$(element).wheelColorPicker()</code> jQuery function.
</p>
<p>
When simply initializing wheel color picker with default options,
a color picker is displayed as a popup under the input element
containing a color wheel, value slider, and a preview
box. The value generated by the color picker is in hexadecimal
RGB format.
If you change the format to something with alpha, an alpha slider
will be added in addition to the color wheel and value component
slider.
</p>
<div id="snippet-basic" class="snippet">
<div class="row">
<!-- Initialization using HTML attributes -->
<div class="col-4">
Default: <br />
<input type="text" data-wheelcolorpicker />
</div>
<div class="col-4">
in RGBA format: <br />
<input type="text" data-wheelcolorpicker data-wcp-format="rgba" />
</div>
<!-- Initialization using JavaScript -->
<div class="col-4">
in HSV format: <br />
<input type="text" id="color-hsv" />
</div>
<script type="text/javascript">
$(function() {
$('#color-hsv').wheelColorPicker({ format: 'hsv' });
});
</script>
<!-- Initialization using JavaScript with options set via HTML attributes -->
<div class="col-4">
in CSS format: <br />
<input type="text" id="color-css" data-wcp-format="css" />
</div>
<script type="text/javascript">
$(function() {
$('#color-css').wheelColorPicker();
});
</script>
</div>
</div>
<div class="snippet-output" data-id="snippet-basic"></div>
<h2>Slider Customizations</h2>
<p>
Besides the default sliders, you may also display other
color component sliders and rearrange their positions.
</p>
<div id="snippet-slider" class="snippet">
<div class="row">
<div class="col-4">
RGB sliders: <br />
<input type="text" data-wheelcolorpicker data-wcp-sliders="wrgbp" />
</div>
<div class="col-4">
HSV sliders: <br />
<input type="text" data-wheelcolorpicker data-wcp-sliders="hwsvp" />
</div>
<div class="col-4">
Sliders only: <br />
<input type="text" data-wheelcolorpicker data-wcp-sliders="rgbhsvap" />
</div>
<div class="col-4">
Preview color on textbox: <br />
<input type="text" data-wheelcolorpicker data-wcp-sliders="wv" data-wcp-preview="true" />
</div>
</div>
</div>
<div class="snippet-output" data-id="snippet-slider"></div>
<h2>Color Picker Sizes</h2>
<p>
By default the color picker widget is automatically resizes to fit
the sliders. However, you may also set a custom size to it by
specifying width and height via CSS.
This feature only applies to desktop website. For mobile browser,
color picker will automatically adjusted to fit browser screen.
</p>
<div id="snippet-size" class="snippet">
<div class="row">
<div class="col-4">
Default autoresize: <br />
<input type="text" data-wheelcolorpicker />
</div>
<div class="col-4">
Custom size: <br />
<input type="text" data-wheelcolorpicker data-wcp-autoResize="false" data-wcp-cssClass="custom-size1" />
<style type="text/css">
.custom-size1 {
width: 400px;
height: 250px;
}
</style>
</div>
<div class="col-4">
Custom size (sliders only): <br />
<input type="text" data-wheelcolorpicker id="lala" data-wcp-autoResize="false" data-wcp-sliders="hsvrgbap" data-wcp-cssClass="custom-size2" />
<style type="text/css">
.custom-size2 {
width: 400px;
height: 250px;
}
</style>
</div>
<div class="col-4">
Preview color on textbox: <br />
<input type="text" data-wheelcolorpicker data-wcp-sliders="wv" data-wcp-preview="true" />
</div>
</div>
</div>
<div class="snippet-output" data-id="snippet-size"></div>
<h2>Embedded Color Picker</h2>
<p>
Color picker can also be embedded inline.
</p>
<div id="snippet-block" class="snippet">
<p>
<input
id="color-block"
type="text"
value="#ff8800"
data-wheelcolorpicker
data-wcp-format="css"
data-wcp-layout="block"
data-wcp-sliders="wsvap"
data-wcp-cssClass="color-block"
data-wcp-autoResize="false"
/>
</p>
<p>
Selected color:
<span class="color-preview-box"></span>
<span class="color-preview-text"></span>
<span class="color-preview-alpha"></span>
</p>
<style type="text/css">
.color-block {
max-width: 340px;
width: 100%;
box-sizing: border-box;
}
.color-preview-box {
display: inline-block;
width: .75em;
height: .75em;
vertical-align: middle;
padding: 2px;
background-clip: content-box;
border: solid 1px #888;
}
</style>
<script type="text/javascript">
$(function() {
$('#color-block').on('colorchange', function(e) {
var color = $(this).wheelColorPicker('value');
var alpha = $(this).wheelColorPicker('color').a;
$('.color-preview-box').css('background-color', color);
$('.color-preview-text').text(color);
$('.color-preview-alpha').text(Math.round(alpha * 100) + '%');
});
});
</script>
</div>
<div class="snippet-output" data-id="snippet-block"></div>
<h2>Color Manipulations</h2>
<p>
By accessing color components in RGB or HSV, it is possible to manipulate colors with ease.
</p>
<div id="snippet-manipulations" class="snippet">
<div class="row">
<div class="col-4">
Pick a color:
<input type="text" data-wheelcolorpicker data-wcp-preview="true" id="color" />
</div>
<div class="col-4">
Predefined colors:
<select id="color-palette">
<option value="#fce94f" style="background: #fce94f;">Butter</option>
<option value="#fcaf3e" style="background: #fcaf3e;">Orange</option>
<option value="#e9b96e" style="background: #e9b96e;">Chocolate</option>
<option value="#8ae234" style="background: #8ae234;">Chameleon</option>
<option value="#729fcf" style="background: #729fcf;">Sky blue</option>
<option value="#ad7fa8" style="background: #ad7fa8;">Plum</option>
<option value="#ef2929" style="background: #ef2929;">Scarlet red</option>
</select>
</div>
<div class="col-4">
<input type="button" id="color-invert" value="Inverse" />
</div>
<div class="col-4">
<input type="button" id="color-complement" value="Complement" />
</div>
</div>
<script type="text/javascript">
$(function() {
$('#color-palette').on('change', function() {
$('#color').wheelColorPicker('setValue', $(this).val());
});
$('#color-invert').on('click', function() {
var color = $('#color').wheelColorPicker('getColor');
color.r = 1 - color.r;
color.g = 1 - color.g;
color.b = 1 - color.b;
$('#color').wheelColorPicker('setRgb', color.r, color.g, color.b);
});
$('#color-complement').on('click', function() {
var color = $('#color').wheelColorPicker('getColor');
color.h = (0.5 + color.h) % 1;
$('#color').wheelColorPicker('setHsv', color.h, color.s, color.v);
});
});
</script>
</div>
<div class="snippet-output" data-id="snippet-manipulations"></div>
<h2>Events</h2>
<p>
Various events occurring on the color picker are passed to the respective input element.
</p>
<div id="snippet-events" class="snippet">
<div class="row">
<div class="col-4">
Pick a color:
<input type="text" data-wheelcolorpicker id="color-input" />
</div>
<div class="col-4">
Slider events
<input type="text" readonly id="event-slider" />
</div>
<div class="col-4">
Input events
<input type="text" readonly id="event-input" />
</div>
<div class="col-4">
Selected color in RGB
<input type="text" readonly id="event-color" />
</div>
</div>
<script type="text/javascript">
$(function() {
$('#color-input').on('sliderup', function() {
$('#event-slider').val('Released');
});
$('#color-input').on('sliderdown', function() {
$('#event-slider').val('Pressed');
});
$('#color-input').on('focus', function() {
$('#event-input').val('Focused');
});
$('#color-input').on('keypress', function() {
$('#event-input').val('Key Pressed');
});
$('#color-input').on('blur', function() {
$('#event-input').val('Blurred');
});
$('#color-input').on('change', function() {
$('#event-input').val('Changed');
});
$('#color-input').on('colorchange', function() {
$('#event-color').val($(this).wheelColorPicker('getValue', 'rgb'));
});
});
</script>
</div>
<div class="snippet-output" data-id="snippet-events"></div>
<hr />
<p>
<a href="https://raffer.one/projects/jquery-wheelcolorpicker" target="_blank">Project homepage</a><br />
<a href="https://github.com/fujaru/jquery-wheelcolorpicker/wiki" target="_blank">Project documentation</a><br />
<a href="https://github.com/fujaru/jquery-wheelcolorpicker" target="_blank">Source code repository at GitHub</a><br />
</p>
</body>
</html>