forked from jweir/colorwheel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
299 lines (253 loc) · 9.94 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Color Wheel Demo</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script src="javascripts/raphael-2.1.0-min.js" type="text/javascript"></script>
<script src="javascripts/colorwheel.js" type="text/javascript"></script>
<style type="text/css" media="screen">
body {
background:#FFF;
font:14px/20px helvetica, arial;
text-align:center;
margin:40px;
color:#666;
}
a {
color:#F60;
}
.demo {
text-align:left;
width:600px;
margin:0 auto;
padding:20px;
background:#FFFFEE;
-moz-box-shadow: #a6a6a6 0px 0px 4px;
box-shadow: #a6a6a6 0px 0px 4px;
-webkit-box-shadow: #a6a6a6 0px 0px 4px;
}
input {
font-family: monospace;
font-size:16px;
}
.swatch {
padding:10px;
}
.method {
margin-bottom:20px;
}
.code p{margin:0; padding:0; display:none;}
.source {
font-size:10px;
line-height:14px;
}
.example, .code {
margin:10px 0;
padding:10px 0;
border-top:2px #CCC solid;
}
h2 {
font-size:16px;
}
h1 {
color:#000;
}
.example h2, .example p {
margin:0 0 10px;
}
.example p {
width:300px;
}
.method b {
color:#2e5478;
}
.method div {
width:400px;
}
code {
display:none;
background:#FFF;
padding:10px;
}
.returns {
color:#237210;
}
.show_source {
margin:20px 0 0;
color:#999;
text-decoration:underline;
cursor:pointer;
}
</style>
</head>
<body>
<div class="demo">
<div id="show_off"></div>
<h1 class="title">Colorwheel</h1>
<p>A color picker coded using <a href="http://raphaeljs.com/">Raphael</a> and
<a href="http://jquery.com">jQuery</a>. The wheel is drawn using the Raphael js library. jQuery is used to assist with events.</p>
<p>The wheel size is set on creation. It supports a small set of callbacks and touch events</p>
<p>It was created for the UI at <a href="http://famedriver.com">Fame Driver</a> and distributed with a MIT license. </p>
<p>Hope you enjoy it – <a href="mailto:john@famedriver.com">John Weir</a></p>
<p>
<b>⇓ <a href="http://github.com/jweir/colorwheel/raw/master/javascripts/colorwheel.js">Download</a></b> or <a href="http://github.com/jweir/colorwheel">see the Github</a> page.<br/>
Requires jQuery and Raphael version 2.1.0 or greater.
</p>
<div class="code">
<h2>Usage and methods</h2>
<div class="method">
<b>var cw = Raphael.colorwheel(dom_element, height_width [, segments]);</b>
<div>The wheel is drawn into a square, so only one dimension is required. <b>segments</b> is an option to increase, or decrease, the smoothness of the hue ring. 60 is the default.</div>
</div>
<div class="method">
<b>cw.input(dom_element)</b> <span class="returns">⇒ cw</span>
<div>Binds a text input for setting and receiving the color as a hex value. This will allow the user to input a hex value and update the wheel.</div>
</div>
<div class="method">
<b>cw.onchange(callback)</b> <span class="returns">⇒ cw</span>
<div>Set a callback for any change received. Callback takes one argument, a Raphael RGB color object.</div>
</div>
<div class="method">
<b>cw.ondrag(start, stop)</b> <span class="returns">⇒ cw</span>
<div>Set a start and stop callback for dragging. The callbacks take one argument, a Raphael RGB color object.</div>
</div>
<div class="method">
<b>cw.color()</b> <span class="returns">⇒ Raphael color object</span>
<div>Get the current color as RGB object</div>
</div>
<div class="method">
<b>cw.color(hex_value)</b> <span class="returns">⇒ cw</span>
<div>Set the current color via a hex value</div>
</div>
</div>
<div id="input_example" class="example">
<h2>Input</h2>
<p>Assigning an input to a colorwheel will allow the user to directly change the hex color value.</p>
<p>When the input is set the colorwheel will set its color to the input's value</p>
<div>
<div style="float:left; width:100%; margin-bottom:20px">
<div class="colorwheel" style="float:left; margin-right:20px; width:300px; text-align:left;"></div>
<div style="float:left; width:50%">
<input name="input_example" value="#FF9900" size="7"><br/>
Enter a hex value above
</div>
</div>
</div>
<div class="show_source">Show Source</div>
<code><pre class="source"></pre></code>
</div>
<div id="callback_example" class="example">
<h2>Callbacks</h2>
<p>Simple example using the callback to update an element's text and css.</p>
<div >
<div style="float:left; width:100%; margin-bottom:20px">
<div class="colorwheel" style="float:left; margin-right:20px; width:300px; text-align:left;"></div>
<div style="float:left; width:50%">
<span class="onchange" style="padding:5px; color:#FFF"></span>
<div class="ondrag" style="display:none;"><b>You are dragging the wheel</b></div>
</div>
</div>
</div>
<div class="show_source">Show Source</div>
<code><pre class="source"></pre></code>
</div>
<div id="size_example" class="example">
<h2>Sizes</h2>
<p>The wheel can be scaled to suit your needs. The large ring has larger number of segments, to make it smoother.</p>
<div style="float:left; width:100%">
<div class="colorwheel_small" style="text-align:left; float:left;margin-right:30px; margin-top:125px"></div>
<div class="colorwheel_large" style="text-align:left; float:left;margin-right:30px; float:left;"></div>
<div class="colorwheel_medium" style="text-align:left; margin-top:75px; float:left"></div>
</div>
<div class="show_source">Show Source</div>
<code><pre class="source"></pre></code>
</div>
<div id="cycle_example" class="example">
<h2>A more advanced callback</h2>
<p>When the color is changed a callback is used to change the colors of each letter below.</p>
<div style="text-align:left; float:left; height:180px; width:100%">
<div class="colorwheel" style="text-align:left; float:left; width:200px"></div>
<div class="cycle" style="float:left; width: 200px; padding:5px; background:#666; margin:40px; font-size:18px; font-weight:bold">These letters will get cycled through... and through...</div>
</div>
<div class="show_source">Show Source</div>
<code><pre class="source"></pre></code>
</div>
<script>
function show_source(target){
target.slideDown();
}
function set_source(f, target){
f();
target.text(f.toString())
}
function size_example(){
Raphael.colorwheel($("#size_example .colorwheel_small")[0],50).color("#F00");
Raphael.colorwheel($("#size_example .colorwheel_medium")[0],150).color("#0F0");
Raphael.colorwheel($("#size_example .colorwheel_large")[0],300, 180).color("#00F");
}
function input_example(){
var cw = Raphael.colorwheel($("#input_example .colorwheel")[0],150);
cw.input($("#input_example input")[0]);
}
function callback_example(){
var cw = Raphael.colorwheel($("#callback_example .colorwheel")[0],150),
onchange_el = $("#callback_example .onchange"),
ondrag_el = $("#callback_example .ondrag");
cw.color("#F00");
function start(){ondrag_el.show()}
function stop(){ondrag_el.hide()}
cw.ondrag(start, stop);
cw.onchange(function(color)
{
var colors = [parseInt(color.r), parseInt(color.g), parseInt(color.b)]
onchange_el.css("background", color.hex).text("RGB:"+colors.join(", "))
})
}
function cycle_example(){
var position = 0,
letters = [],
colorwheel;
function setup_the_letters(){
var cycle = $(".cycle"),
l = cycle.text().split("");
cycle.html("");
for (var i=0; i < l.length; i++) {
var letter = $("<span>"+l[i]+"</span>");
cycle.append(letter);
letters.push(letter);
};
}
function update(color){
position++;
if(position > letters.length-1){ position = 0; }
letters[position].css("color", color.hex);
}
colorwheel = Raphael.colorwheel($("#cycle_example .colorwheel")[0],150);
setup_the_letters();
colorwheel.onchange(update).color("#864343");
}
$(document).ready(function(){
Raphael.colorwheel($("#show_off")[0],100).color("#FF6600").onchange(function(c){$(".title").css("color",c.hex)});
set_source(input_example, $("#input_example .source"))
set_source(size_example, $("#size_example .source"))
set_source(callback_example, $("#callback_example .source"))
set_source(cycle_example, $("#cycle_example .source"))
$(".show_source").click(function(){
$(this).parents().filter('.example').find("code").slideDown();
});
})
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-605430-4']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
</body>
</html>