forked from itsjavi/bootstrap-colorpicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
551 lines (465 loc) · 18 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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Colorpicker for Twitter Bootstrap</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="dist/css/bootstrap-colorpicker.min.css" rel="stylesheet">
<link href="src/css/docs.css" rel="stylesheet">
</head>
<body>
<div class="container">
<section id="typeahead">
<div class="page-header">
<h1><i class="glyphicon glyphicon-tint"></i> Bootstrap Colorpicker 2.3
<small>for Twitter Bootstrap</small>
</h1>
</div>
<div class="row">
<article class="col-md-12">
<p>
Colorpicker plugin for the Twitter Bootstrap toolkit. Originally written by <a
href="https://twitter.com/stefanpetre/" target="_blank">@eyecon</a> and maintained in Github by
<a href="http://twitter.com/mjolnic/" target="_blank">@mjolnic</a> and the community
<br>
<br> It basically adds a color picker to a field or any other element.
</p>
<ul>
<li>can be used as a component</li>
<li>alpha picker</li>
<li>multiple formats: hex, rgb, rgba, hsl, hsla</li>
</ul>
<hr>
<div class="social">
<a href="https://github.com/mjolnic/bootstrap-colorpicker/" target="_blank"
class="btn btn-default btn-md"><i class="glyphicon glyphicon-random"></i> Fork me on Github</a>
<a href="https://github.com/mjolnic/bootstrap-colorpicker/archive/master.zip" target="_blank"
class="btn btn-success btn-md"><i class="glyphicon glyphicon-download-alt"></i> Download</a>
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-size="medium"></div>
<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
(function () {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
<a href="https://twitter.com/share" class="twitter-share-button" data-via="mjolnic"
data-related="mjolnic" data-hashtags="bootstrap">Tweet</a>
<script>
!function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
p = /^http:/.test(d.location) ? 'http' : 'https';
if (!d.getElementById(id)) {
js = d.createElement(s);
js.id = id;
js.src = p + '://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js, fjs);
}
}(document, 'script', 'twitter-wjs');
</script>
</div>
<br>
</article>
</div>
<div class="row">
<div class="col-md-6">
<h2>Examples</h2>
<p> Attached to a field with hex format specified via options:</p>
<div class="well">
<input type="text" class="form-control demo demo-1 demo-auto" value="#5367ce"/>
<pre class="markup">
<input type="text" class="demo1" value="#5367ce" />
<script>
$(function(){
$('.demo1').colorpicker();
});
</script>
</pre>
</div>
<p>As a component:</p>
<div class="well">
<div class="input-group colorpicker-component demo demo-auto">
<input type="text" value="#00AABB" class="form-control"/>
<span class="input-group-addon"><i></i></span>
</div>
<pre class="markup">
<div class="input-group demo2">
<input type="text" value="" class="form-control" />
<span class="input-group-addon"><i></i></span>
</div>
<script>
$(function(){
$('.demo2').colorpicker();
});
</script>
</pre>
</div>
<p>As a component with options given:</p>
<div class="well">
<div class="input-group colorpicker-component demo-with-options">
<input type="text" value="" class="form-control"/>
<span class="input-group-addon"><i></i></span>
</div>
<pre class="markup">
<div class="input-group demo-with-options">
<input type="text" value="" class="form-control" />
<span class="input-group-addon"><i></i></span>
</div>
<script>
$(function(){
$('.demo-with-options').colorpicker({
color: '#00AABB',
format: 'hex'
});
});
</script>
</pre>
</div>
<p>Using events to work with the color:</p>
<div class="well">
<a href="#" class="btn small demo" id="demo_apidemo" data-color="rgb(255, 255, 255)">Change
background color</a>
</div>
<p>Transparent color support:</p>
<div class="well">
<input type="text" data-format="hex" class="form-control demo demo-auto" id="demo_transparent"
value="transparent"/>
</div>
<p>Horizonal mode:</p>
<div class="well">
<input type="text" class="form-control demo" data-horizontal="true" id="demo_forceformat"
value="#8fff00"/>
</div>
<p>Inline mode:</p>
<div class="well">
<div id="demo_cont" class="demo demo-auto inl-bl" data-container="#demo_cont"
data-color="rgba(150,216,62,0.55)" data-inline="true"></div>
<div class="demo demo-auto inl-bl" data-container="true" data-color="rgb(50,216,62)"
data-inline="true"></div>
</div>
<p>Bootstrap colors:</p>
<div class="well">
<input type="text" data-format="hex" class="form-control demo" id="demo_selectors"
value="success"/>
</div>
<p>Custom widget size:</p>
<div class="well">
<style>
.colorpicker-2x .colorpicker-saturation {
width: 200px;
height: 200px;
}
.colorpicker-2x .colorpicker-hue,
.colorpicker-2x .colorpicker-alpha {
width: 30px;
height: 200px;
}
.colorpicker-2x .colorpicker-color,
.colorpicker-2x .colorpicker-color div {
height: 30px;
}
</style>
<input type="text" class="form-control demo" id="demo_size" value="#ffaa00"/>
<pre class="markup">
<input type="text" id="demo_size" value="#ffaa00" />
<style>
.colorpicker-2x .colorpicker-saturation {
width: 200px;
height: 200px;
}
.colorpicker-2x .colorpicker-hue,
.colorpicker-2x .colorpicker-alpha {
width: 30px;
height: 200px;
}
.colorpicker-2x .colorpicker-color,
.colorpicker-2x .colorpicker-color div{
height: 30px;
}
</style>
<script>
$(function(){
$('#demo_size').colorpicker({
customClass: 'colorpicker-2x',
sliders: {
saturation: {
maxLeft: 200,
maxTop: 200
},
hue: {
maxTop: 200
},
alpha: {
maxTop: 200
}
}
});
});
</script>
</pre>
</div>
<p>Enabled / disabled</p>
<div class="well">
<div id="demo_endis" class="input-group demo demo-auto colorpicker-component">
<input disabled type="text" value="" class="form-control"/>
<span class="input-group-addon"><i></i></span>
</div>
<br>
<a class="btn btn-sm btn-default enable-button" href="#">Enable</a>
<a class="btn btn-sm btn-default disable-button" href="#">Disable</a>
</div>
<p>Bootstrap Modal</p>
<div class="well">
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Show
</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">In a Modal</h4>
</div>
<div class="modal-body">
<div class="input-group colorpicker-component demo demo-auto">
<input type="text" value="" class="form-control"/>
<span class="input-group-addon"><i></i></span>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<a class="btn btn-default demo-destroy" href="#"><i class="glyphicon glyphicon-remove"></i> Destroy
plugin instances</a>
<a class="btn btn-default demo-create" href="#"><i class="glyphicon glyphicon-plus"></i> Create
instances again</a>
</div>
<article class="col-md-6">
<h2>Documentation</h2>
<p>Call the colopicker via javascript:</p>
<pre class="well">$('.sample-selector').colorpicker({ /*options...*/ });</pre>
<h3>Options</h3>
<p>
You can set colorpicker options either as a plugin parameter or data-* attributes
</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 100px;">Name</th>
<th style="width: 50px;">Type</th>
<th style="width: 100px;">Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>format</td>
<td>string</td>
<td>false</td>
<td>If not false, forces the color format to be hex, rgb or rgba, otherwise the format is
automatically detected.
</td>
</tr>
<tr>
<td>color</td>
<td>string</td>
<td>false</td>
<td>If not false, sets the color to this value.</td>
</tr>
<tr>
<td>container</td>
<td>string or jQuery Element</td>
<td>false</td>
<td>If not false, the picker will be contained inside this element, otherwise it will be
appended to the document body.
</td>
</tr>
<tr>
<td>component</td>
<td>string or jQuery Element</td>
<td>'.add-on, .input-group-addon'</td>
<td>Children selector for the component or element that trigger the colorpicker and which
background color will change (needs an inner <i> element).
</td>
</tr>
<tr>
<td>input</td>
<td>string or jQuery Element</td>
<td>'input'</td>
<td>Children selector for the input that will store the picker selected value.</td>
</tr>
<tr>
<td>horizontal</td>
<td>boolean</td>
<td>false</td>
<td>If true, the hue and alpha channel bars will be rendered horizontally, above the saturation
selector.
</td>
</tr>
<tr>
<td>inline</td>
<td>boolean</td>
<td>false</td>
<td>If true, forces to show the colorpicker as an inline element.</td>
</tr>
<tr>
<td>sliders</td>
<td>object</td>
<td><abbr title='please, read the source code to see this value'>[...]</abbr></td>
<td>Vertical sliders configuration (read source code if you really need to tweak this).</td>
</tr>
<tr>
<td>slidersHorz</td>
<td>object</td>
<td><abbr title='please, read the source code to see this value'>[...]</abbr></td>
<td>Horizontal sliders configuration (read source code if you really need to tweak this).</td>
</tr>
<tr>
<td>template</td>
<td>string</td>
<td><abbr title='please, read the source code to see this value'>[...]</abbr></td>
<td>Customizes the default colorpicker HTML template.</td>
</tr>
<tr>
<td>align</td>
<td>string</td>
<td>'right'</td>
<td>By default, the colorpicker is aligned to the right of the input. If you need to switch it
to the left, set align to 'left'.
</td>
</tr>
<tr>
<td>customClass</td>
<td>string</td>
<td>null</td>
<td>Adds this class to the colorpicker widget.</td>
</tr>
<tr>
<td>colorSelectors</td>
<td>object</td>
<td>null</td>
<td>List of pre selected colors (hex format). If you choose one of these colors, the alias is returned instead of the hex code.</td>
</tr>
</tbody>
</table>
<h3>jQuery API Methods</h3>
<p>General usage methods</p>
<h4>.colorpicker(options)</h4>
<p>Initializes an colorpicker.</p>
<h4>.colorpicker('getValue', defaultValue)</h4>
<p>Gets the value from the input or the data attribute (if has no input), otherwise returns the default
value, which defaults to #000000 if not specified.</p>
<h4>.colorpicker('setValue', value)</h4>
<p>Set a new value for the color picker (also updates everything). Triggers 'changeColor' event.</p>
<h4>.colorpicker('show')</h4>
<p>Show the color picker</p>
<h4>.colorpicker('hide')</h4>
<p>Hide the color picker</p>
<h4>.colorpicker('reposition')</h4>
<p>Updates the color picker's position relative to the element</p>
<h4>.colorpicker('update')</h4>
<p>Refreshes the widget colors (this is done automatically)</p>
<h4>.colorpicker('enable')</h4>
<p>Enable the color picker.</p>
<h4>.colorpicker('disable')</h4>
<p>Disable the color picker.</p>
<h4>.colorpicker('destroy')</h4>
<p>Destroys the colorpicker widget and unbind all .colorpicker events from the element and component</p>
<h4>.data('colorpicker')</h4>
<p>Access to the colorpicker API directly</p>
<h4>.data('colorpicker').color</h4>
<p>Access to the colorpicker Color object information</p>
<hr>
<h3>Color object methods</h3>
<p>Each triggered events have a color object (avaliable through event.color, see the example at the
bottom) used internally by the picker. This object has several useful methods. These are the more
commonly used:</p>
<h4>.setColor(value)</h4>
<p>Set a new color. The value is parsed and tries to do a quess on the format.</p>
<h4>.setHue(value)</h4>
<p>Set the HUE with a value between 0 and 1.</p>
<h4>.setSaturation(value)</h4>
<p>Set the saturation with a value between 0 and 1.</p>
<h4>.setBrightness(value)</h4>
<p>Set the brightness with a value between 0 and 1.</p>
<h4>.setAlpha(value)</h4>
<p>Set the transparency with a value between 0 and 1.</p>
<h4>.toRGB()</h4>
<p>Returns a hash with red, green, blue and alpha.</p>
<h4>.toHex()</h4>
<p>Returns a string with HEX format for the current color.</p>
<h4>.toHSL()</h4>
<p>Returns a hash with HSLA values.</p>
<hr>
<h3>Events</h3>
<p>The colorpicker plugin exposes some events</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 150px;">Event</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>create</td>
<td>This event fires immediately when the color picker is created.</td>
</tr>
<tr>
<td>showPicker</td>
<td>This event fires immediately when the color picker is displayed.</td>
</tr>
<tr>
<td>hidePicker</td>
<td>This event is fired immediately when the color picker is hidden.</td>
</tr>
<tr>
<td>changeColor</td>
<td>This event is fired when the color is changed.</td>
</tr>
<tr>
<td>disable</td>
<td>This event is fired immediately when the color picker is disabled, except if it was
initialized as disabled.
</td>
</tr>
<tr>
<td>enable</td>
<td>This event is fired immediately when the color picker is enabled, except upon
initialization.
</td>
</tr>
<tr>
<td>destroy</td>
<td>This event fires immediately when the color picker is destroyed.</td>
</tr>
</tbody>
</table>
<pre class="well">
$('.my-colorpicker').colorpicker().on('changeColor.colorpicker', function(event){
bodyStyle.backgroundColor = event.color.toHex();
});
</pre>
</article>
</div>
</section>
</div>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="dist/js/bootstrap-colorpicker.js"></script>
<script src="src/js/docs.js"></script>
</body>
</html>