forked from claviska/jquery-minicolors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
422 lines (362 loc) · 12.6 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
<!DOCTYPE html>
<html>
<head>
<title>jQuery MiniColors</title>
<meta name="description" content="A tiny color picker built on jQuery" />
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0" />
<link rel="stylesheet" href="jquery.minicolors.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="jquery.minicolors.js"></script>
<style>
HTML,
BODY {
padding: 0;
margin: 0;
}
BODY {
font: 14px sans-serif;
color: #666;
line-height: 1.7;
background: #F8F8F8;
padding: 0 20px;
padding-bottom: 32px;
}
H1, H2, H3 {
font-family: Georgia, serif;
font-weight: normal;
color: black;
overflow: hidden;
text-overflow: ellipsis;
}
H1, H2, H3, P {
margin: 20px 0;
}
A {
color: #08C;
}
A:hover {
color: #0BE;
}
PRE,
CODE {
background: #F8F8F8;
padding: 2px;
}
PRE {
overflow: hidden;
text-overflow: ellipsis;
padding: 10px;
margin: 30px 0;
}
.alert {
background: #FFFCCC;
color: black;
padding: 1px 10px;
margin: 30px 0;
}
#main {
max-width: 800px;
background: white;
border: solid 1px #DDD;
box-shadow: 0 0 30px rgba(0, 0, 0, .05);
padding: 30px;
margin: 20px auto;
}
.example {
background: #F8F8F8;
padding: 10px;
margin: 20px 0;
}
#console {
position: fixed;
left: 0;
right: 0;
bottom: 0;
height: 32px;
font-family: monospace;
line-height: 32px;
text-align: center;
background: black;
color: white;
z-index: 100;
-moz-transition: all .5s;
-ms-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
opacity: 0;
}
#console.busy {
opacity: .85;
}
</style>
<script>
$(document).ready( function() {
var consoleTimeout;
// Display the results of the change callback on any minicolors input
$('INPUT[type=minicolors]').on('change', function() {
var input = $(this),
hex = input.val(),
opacity = input.attr('data-opacity'),
text;
// Generate text to show in console
text = hex ? hex : 'transparent';
if( opacity ) text += ', ' + opacity;
text += ' / ' + $.minicolors.rgbString(input)
// Show text in console; disappear after a few seconds
$('#console').text(text).addClass('busy');
clearTimeout(consoleTimeout);
consoleTimeout = setTimeout( function() {
$('#console').removeClass('busy');
}, 3000);
});
// Adding controls dynamically
$('#add-one').on('click', function() {
// Just add an <input type="minicolors" /> control anywhere in your page
$('#add-one-result').append('<input type="minicolors" data-slider="' + $('#add-one-slider').val() + '" value="#ff6600" /><br /><br />');
// ...then call $.minicolors.init() to activate the control
$.minicolors.init();
});
});
</script>
</head>
<body>
<div id="main">
<h1>jQuery MiniColors 2.0 beta</h1>
<p>
A project by Cory LaViska of <a href="http://www.abeautifulsite.net/">A Beautiful Site</a>.
</p>
<p>
MiniColors is a tiny color picker built on jQuery. It's easy to use and works
well on touch-enabled devices. Completely re-written for 2.0.
</p>
<div class="alert">
<p>
The MiniColors API was completely overhauled in 2.0. You will need to change your
code if you are upgrading from a previous version!
</p>
</div>
<!-- Download -->
<h2 id="download">Download</h2>
<p>
You can <a href="https://github.com/claviska/jquery-miniColors">download the source</a>
on GitHub. Help contribute to this project by posting bug reports, feature requests, and
code improvements!
</p>
<h2 id="usage">Usage</h2>
<p>
The plugin will automatically initialize all inputs of type <code>minicolors</code>:
</p>
<pre><input type="minicolors" /></pre>
<p>
This results in the default color picker:
<input type="minicolors" />
</p>
<p>
To set an initial value, use the <code>value</code> attribute:
</p>
<pre><input type="minicolors" value="#00cc00" /></pre>
<p>
This results in the default color picker with a preset value:
<input type="minicolors" value="#00cc00" />
</p>
<p>
You can obtain the selected value any time by grabbing the original <code>input</code>
element's <code>value</code>.
</p>
<!-- Options -->
<h2 id="options">Options</h2>
<p>
Options are set for each control using one or more of the HTML5 <code>data-</code>
attributes mentioned below.
</p>
<h3>Slider Variations</h3>
<p>
MiniColors has four slider variations. Set the <code>data-slider</code> attribute
to use them. Valid options are <code>hue</code> (default), <code>saturation</code>,
<code>brightness</code>, and <code>wheel</code>.
</p>
<pre><input type="minicolors" data-slider="saturation" /></pre>
<p>
<input type="minicolors" value="#d7e036" data-slider="hue" />
<input type="minicolors" value="#00a9bf" data-slider="saturation" />
<input type="minicolors" value="#b340ff" data-slider="brightness" />
<input type="minicolors" value="#e87262" data-slider="wheel" />
</p>
<h3>Default Values</h3>
<p>
Use the <code>data-default</code> attribute to force a default hex value. Try clearing
the box—it will revert to its default value. Note that the default value does not have
to be the same as the initial value (set with the <code>value</code> attribute).
</p>
<pre><input type="minicolors" data-default="#ffffff" /></pre>
<p>
<input type="minicolors" data-default="#ffffff" />
</p>
<h3>No Text Field</h3>
<p>
Turn the color picker into a stand-alone color swatch by setting <code>data-textfield</code>
to <code>false</code>:
</p>
<pre><input type="minicolors" data-textfield="false" /></pre>
<p>
<input type="minicolors" value="#ff6600" data-textfield="false" data-slider="hue" />
<input type="minicolors" value="#29cf37" data-textfield="false" data-slider="saturation" />
<input type="minicolors" value="#b437c7" data-textfield="false" data-slider="brightness" />
<input type="minicolors" value="#00a4d1" data-textfield="false" data-slider="wheel" />
</p>
<h3>Opacity Slider</h3>
<p>
Enable the opacity slider by adding the <code>data-opacity</code> attribute:
</p>
<pre><input type="minicolors" data-opacity=".75" /></pre>
<p>
<input type="minicolors" value="#4471a3" data-opacity=".75" />
</p>
<p>
To obtain the opacity value, grab the <code>data-opacity</code> attribute of your input
element. Keep in mind that this value will not submit along with other form data, so it's
best to use the <code>change</code> callback to update a hidden element in your form if
you need it to be submitted.
</p>
<h3>Inline Controls</h3>
<p>
Force the color picker to appear inline by setting <code>data-control</code> to <code>inline</code>:
</p>
<pre><input type="minicolors" data-control="inline" /></pre>
<p>
<input type="minicolors" value="#3c9641" data-control="inline" data-slider="hue" data-style="margin: 10px;" />
<input type="minicolors" value="#d49f00" data-control="inline" data-slider="saturation" data-style="margin: 10px;" />
<input type="minicolors" value="#5cb8ff" data-control="inline" data-slider="brightness" data-style="margin: 10px;" />
<input type="minicolors" value="#5bbf4c" data-control="inline" data-slider="wheel" data-style="margin: 10px;" />
</p>
<h3>Dropdown Position</h3>
<p>
Change the position of the dropdown panel by setting the <code>data-position</code>
attribute. Valid options are <code>top</code>, <code>left</code>, and <code>top left</code>.
</p>
<pre><input type="minicolors" data-position="top" /></pre>
<p>
<input type="minicolors" data-position="top" data-opacity=".5" />
</p>
<h3>Swatch Position</h3>
<p>
Force the color swatch to appear on the left by setting <code>data-swatch-position</code>
to <code>left</code>:
</p>
<pre><input type="minicolors" data-swatch-position="left" /></pre>
<p>
<input type="minicolors" data-swatch-position="left" />
</p>
<h3>Classes & Styles</h3>
<p>
Use <code>data-class</code> and <code>data-style</code> to apply classes and styles
to the parent element of the resulting control:
</p>
<pre><input type="minicolors" data-class="my-class" data-style="margin: 20px;" /></pre>
<!-- Utility Functions -->
<h2 id="utility-functions">Utility Functions</h2>
<h3><code>$.minicolors.init()</code></h3>
<p>
Call this function to initialize controls that are created dynamically. You do not
need to specify a selector when calling this function. Example:
</p>
<div class="example">
<p>
<select id="add-one-slider">
<option value="hue">Hue Picker</option>
<option value="saturation">Saturation Picker</option>
<option value="brightness">Brightness Picker</option>
<option value="wheel">Wheel Picker</option>
</select>
<button id="add-one">Add it!</button>
</p>
<div id="add-one-result"></div>
</div>
<h3><code>$.minicolors.remove(<em>input</em>)</code></h3>
<p>
Call this function to remove a control from the DOM. (You can also remove any of the
control's parent elements with the same effect.)
</p>
<h3><code>$.minicolors.refresh()</code></h3>
<p>
Call this function if you programmatically change the value of one or more controls.
</p>
<h3><code>$.minicolors.show(<em>input</em>)</code></h3>
<p>
Show the control attached to the specified <code>input</code> element. Only
one control may be shown at once. (Doesn't apply to inline controls.)
</p>
<h3><code>$.minicolors.hide()</code></h3>
<p>
Hides any control that may be showing. (Doesn't apply to inline controls.)
</p>
<h3><code>$.minicolors.rgbObject(<em>input</em>)</code></h3>
<p>
Returns an object with <code>r</code>, <code>g</code>, <code>b</code>, and
<code>a</code> properties. The <code>a</code> property will only be present
if opacity is enabled on the specified control.
</p>
<h3><code>$.minicolors.rgbString(<em>input</em>)</code></h3>
<p>
Returns an RGB or RGBA string suitable for use in your CSS. If opacity is
enabled on the specified control, an RGBA string will be returned. Otherwise
an RGB string will be returned.
</p>
<!-- Callbacks -->
<h2 id="callbacks">Callbacks</h2>
<h3><code>change</code></h3>
<p>
Attach your <code>change</code> callback to the original <code>input</code> element.
You can access the value and opacity of the control using the <code>value</code> and
<code>data-opacity</code> attributes, respectively.
</p>
<p>
To convert a control's hex value to RGB or RGBA, use the
<code>$.minicolors.rgbObject()</code> or <code>$.minicolors.rgbString()</code>
utility functions.
</p>
<h3><code>show</code> & <code>hide</code></h3>
<p>
The plugin will trigger a <code>show</code> event on the original <code>input</code>
element when the color picker is initially shown, and a <code>event</code> when the
color picker is hidden.
</p>
<!-- Settings -->
<h2 id="settings">Settings</h2>
<p>
Adjust plugin defaults by setting <code>$.minicolors.settings.<em>settingName</em></code>,
where <code><em>settingName</em></code> is one of the following:
</p>
<h3><code>animationSpeed</code> & <code>animationEasing</code></h3>
<p>
The animation speed and easing effect to use when making a color selection.
Defaults to <code>100</code> (milliseconds) and <code>swing</code>, respectively.
Set <code>animationSpeed</code> to <code>0</code> to disabled animation.
</p>
<h3><code>defaultSlider</code></h3>
<p>
Sets the slider variation for all controls that don't specify it through
<code>data-slider</code>. Default value is <code>hue</code>.
</p>
<h3><code>letterCase</code></h3>
<p>
Forces the hex color's letter case to uppercase or lowercase. Possible values
are <code>lowercase</code> (default) and <code>uppercase</code>.
</p>
<h3><code>hideSpeed</code> & <code>showSpeed</code></h3>
<p>
The hide/show speed for dropdown controls. Default is <code>100</code> (milliseconds).
</p>
<!-- Styling Tips -->
<h2 id="styling-tips">Styling Tips</h2>
<p>
If you change the <code>input</code> element's height or width via CSS, you'll also
need to adjust certain style properties in <code>.minicolors-swatch</code>,
<code>.minicolors-panel</code>, <code>.minicolors-position-top</code>, and
<code>.minicolors-position-left</code>.
</p>
</div>
<div id="console"></div>
</body>
</html>