forked from claviska/jquery-minicolors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
314 lines (268 loc) · 8.49 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
<!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;
}
A {
color: #08C;
}
A:hover {
color: #0BE;
}
CODE {
background: #F8F8F8;
padding: 2px;
}
.alert {
background: #FFFCCC;
color: black;
padding: 1px 10px;
margin: 20px 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;
}
#console {
position: fixed;
left: 0;
right: 0;
bottom: 0;
height: 32px;
font-family: monospace;
line-height: 32px;
text-align: center;
background: black;
color: black;
z-index: 100;
-moz-transition: all .5s;
-ms-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
}
#console.busy {
color: white;
}
</style>
<script>
$(document).ready( function() {
var consoleTimeout;
$('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;
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);
});
});
</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>
<h2>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>How it Works</h2>
<h3>Basic Control</h3>
<p>
Create an <code><input type="minicolors" /></code> element. MiniColors
will automatically initialize all controls on the page.
</p>
<p>
<input type="minicolors" name="color" />
</p>
<h3>Color Wheel</h3>
<p>
Add <code>data-type="wheel"</code> to the <code>input</code> element to use
a color wheel.
</p>
<p>
<input type="minicolors" name="color" data-type="wheel" />
</p>
<h3>Preset Colors</h3>
<p>
Add <code>value="#ffcc00"</code> to the <code>input</code> element to set
a preset color.
</p>
<p>
<input type="minicolors" name="color" value="#ffcc00" />
</p>
<h3>Default Values</h3>
<p>
Add <code>data-default="#ffffff"</code> to the <code>input</code> element to
force a default hex value. Try clearing the box—it will revert to its default
value.
</p>
<p>
<input type="minicolors" name="color" data-default="#ffffff" />
</p>
<h3>Without Textfields</h3>
<p>
Turn the color picker into a stand-alone swatch by adding
<code>data-textfield="false"</code> to the <code>input</code> element.
</p>
<p>
<input type="minicolors" name="color" value="#FF6600" data-textfield="false" />
<input type="minicolors" name="color" value="#2facd6" data-textfield="false" data-type="wheel" />
</p>
<h3>With Opacity</h3>
<p>
Enable opacity by adding <code>data-opacity="0.75"</code> to the <code>input</code> element.
</p>
<p>
<input type="minicolors" name="color" value="#4471a3" data-opacity=".75" />
</p>
<h3>Inline Controls</h3>
<p>
<input type="minicolors" name="color" value="#3c9641" data-control="inline" data-style="margin: 10px;" />
<input type="minicolors" name="color" value="#3099bf" data-control="inline" data-type="wheel" data-style="margin: 10px;" />
</p>
<h3>Dropdown Position</h3>
<p>
Add <code>data-position="top"</code> to position the color picker above the
<code>input</code> element instead of below it. Valid options are <code>top</code>,
<code>left</code>, or <code>top left</code>.
</p>
<p>
<input type="minicolors" name="color" data-position="top" />
</p>
<h3>Swatch Position</h3>
<p>
Add <code>data-swatch-position="left"</code> to the <code>input</code> element to position
the swatch to the left of the <code>input</code> element instead of to the right of it.
</p>
<p>
<input type="minicolors" name="color" data-swatch-position="left" />
</p>
<h2>Utility Functions</h2>
<h3><code>$.minicolors.init()</code></h3>
<p>
To initialize controls that are created dynamically, simply call
<code>$.minicolors.init();</code>.
</p>
<h3><code>$.minicolors.refresh()</code></h3>
<p>
You'll need to call this function if you programmatically change the value
of your controls. Call it immediately after you change any values and every
control on the page will update.
</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 affect inline controls.)
</p>
<h3><code>$.minicolors.hide()</code></h3>
<p>
Hides control that may be showing. (Doesn't affect 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>
<h2>Settings</h2>
<h3><code>$.minicolors.settings.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>$.minicolors.settings.hideSpeed</code><br /><code>$.minicolors.settings.showSpeed</code></h3>
<p>
The hide/show speed for dropdown controls. Default is <code>100</code> (milliseconds).
</p>
<h2>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>
<h2>Tips</h2>
<ul>
<li>
You can apply one or more classes to your controls by adding <code>data-class="class1 class2..."</code>
to the <code>input</code> element. This will let you style controls individually, if necessary.
</li>
<li>
You can apply an inline style to your controls by adding <code>data-style="<em>[your css here]</em>"</code>
to the <code>input</code> element. This style will be applied to the control's wrapper
element, which has the <code>minicolors</code> class.
</li>
<li>
If you change the <code>input</code> element's height or width, you'll also
need to adjust <code>.minicolors-swatch</code>, <code>.minicolors-panel</code>,
<code>.minicolors-position-top</code>, and <code>.minicolors-position-left</code>.
</li>
</ul>
</div>
<div id="console"></div>
</body>
</html>