forked from visionmedia/uikit
/
index.html
629 lines (535 loc) · 20 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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
<!DOCTYPE html>
<html>
<head>
<title>UIKit - Modern UI components for a modern web</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="jquery.js"></script>
<script src="../build/ui.js"></script>
<script src="highlight.js"></script>
<link rel="stylesheet" href="../build/ui.css">
<link rel="stylesheet" href="style.css">
<script>
$(function(){
var menu = ui.menu()
.add('Add item')
.add('Edit item', function(){ console.log('edit'); })
.add('Remove item', function(){ console.log('remove'); })
.add('Remove "Add item"', function(){
menu
.remove('Add item')
.remove('Remove "Add item"');
});
menu.on('Add item', function(){
console.log('added an item');
});
oncontextmenu = function(e){
e.preventDefault();
menu
.moveTo(e.pageX, e.pageY)
.show();
};
$('#simple-dialog').click(function(){
new ui.Dialog({ title: 'Title', message: "I'm a simple dialog" })
.show()
.hide(2000);
return false;
});
$('#closable-dialog').click(function(){
new ui.Dialog({ title: 'Title', message: "I'm a dialog that wont auto-close" })
.show()
.closable();
return false;
});
$('#ui-dialog-1').click(function(){
ui.dialog('Just another dialog')
.closable()
.show();
return false;
});
$('#ui-dialog-2').click(function(){
ui.dialog('Title', 'Just another dialog')
.closable()
.show();
return false;
});
$('#dialog-effect-slide').click(function(){
ui.dialog('Hello!')
.effect('slide')
.show()
.hide(1500);
return false;
})
$('.effect-slide').click(function(){
ui.dialog('Hello!')
.effect('slide')
.show()
.hide(1500);
return false;
})
$('.effect-scale').click(function(){
ui.dialog('Hello!')
.effect('scale')
.show()
.hide(1500);
return false;
})
$('.effect-fade').click(function(){
ui.dialog('Hello!')
.effect('fade')
.show()
.hide(1500);
return false;
})
$('#dialog-hide').click(function(){
var dialog = ui.dialog("I'll close in 2 seconds").show();
setTimeout(function(){
dialog.hide();
}, 2000);
return false;
})
$('#simple-confirmation').click(function(){
new ui.Confirmation({ title: 'Remove user', message: 'are you sure?' })
.show(function(ok){
if (ok) ui.dialog('user removed!').show().hide(1500);
});
return false;
})
$('#ui-confirm').click(function(){
ui.confirm('Remove user', 'are you sure?')
.ok('Remove')
.cancel('No dont!')
.show(function(ok){
if (ok) ui.dialog('user removed!').show().hide(1500);
});
return false;
});
$('#ui-confirm-2').click(function(){
ui.confirm('are you sure?')
.closable()
.show(function(ok){
if (ok) ui.dialog('done!').show().hide(1500);
else ui.dialog('never-mind').show().hide(1500);
});
return false;
});
$('#dialog-overlay').click(function(){
ui.dialog('Overlay time')
.closable()
.overlay()
.show();
return false;
})
$('#modal-overlay').click(function(){
ui.dialog('Overlay time')
.closable()
.modal()
.show();
return false;
})
$('#dialog-picker').click(function(){
ui.dialog('Select a color', new ui.ColorPicker)
.effect('slide')
.closable()
.show();
return false;
})
var picker = new ui.ColorPicker;
picker.el.appendTo('#default-color-picker');
picker.on('change', function(color){
$('.r').text(color.r)
$('.g').text(color.g)
$('.b').text(color.b)
$('.rgb').text(color.toString()).css('background', color)
});
var picker = new ui.ColorPicker;
picker.size(100);
picker.el.appendTo('#color-picker-size');
var picker = new ui.ColorPicker;
picker.width(80);
picker.el.appendTo('#color-picker-width');
var picker = new ui.ColorPicker;
var card = ui.card('<p>Click to show a color picker</p>', picker);
card.el.appendTo('#card');
$('#flip').click(function(){
card.flip();
return false;
})
$('#wrapper section section').hide();
$('h2 a').click(function(e){
e.preventDefault();
$(this)
.parents('section')
.find('section')
.slideToggle();
});
$('#notify').click(function(e){
e.preventDefault();
ui.notify('Email', 'you have 3 new messages')
.effect('slide');
setTimeout(function(){
ui.warn('Warning', 'something happened')
.effect('slide');
setTimeout(function(){
ui.error('Error', 'something failed')
.closable()
.hide(8000)
.effect('slide');
setTimeout(function(){
ui.notify('Stick notification')
.sticky()
.effect('slide');
}, 200);
}, 200);
}, 200);
});
});
</script>
</head>
<body>
<a href="http://github.com/visionmedia/uikit"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/4c7dc970b89fd04b81c8e221ba88ff99a06c6b61/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub"></a>
<div id="wrapper">
<div id="logo">
<h1>UI<strong>kit</strong></h1>
<span>Modern UI components for the modern web</span>
</div>
<p>UIKit is a small collection of flexible, decoupled jQuery JavaScript components for the modern web. With an emphasis on structure-only styling it's easy to style UIKit to match your application, no preprocessor variables, just raw CSS structure! As a result most of the styling you see in this document is for demonstration only.</p>
<section>
<h2 id="emitter-section"><a href="#">Emitter</a></h2>
<p>The event Emitter is used by many of the components to emit events like "hide" and "show" among others, but it's public API! so you're free to use it in your projects.</p>
<section>
<h3>API</h3>
<p>Currently the Emitter API is defined as following:</p>
<pre><code>var emitter = new ui.Emitter;
emitter.on('event', callback);
emitter.once('event', callback);
emitter.off('event', callback);
emitter.off('event');
emitter.emit('event', foo, bar, baz);</code></pre>
</section>
</section>
<section>
<h2 id="dialog-section"><a href="#">Dialog</a></h2>
<p>The Dialog component is the basis of more specific components
such the Confirmation Dialog.</p>
<section>
<h3>Example</h3>
<p>Click <a href="#" id="simple-dialog">here</a> to
open a simple dialog that closes after 2 seconds.</p>
<pre>
<code>
new ui.Dialog({ title: 'Title', message: "I'm a simple dialog" })
.show()
.hide(2000);
</code>
</pre>
<h3>.closable()</h3>
<p>By default dialogs do not have a close button, but it's
easy to add one! Click <a href="#" id="closable-dialog">here</a> to try it.</p>
<pre>
<code>
new ui.Dialog({ title: 'Title', message: "I'm a dialog that wont auto-close" })
.closable()
.show();
</code>
</pre>
<h3>ui.dialog(msg)</h3>
<p><code>ui.dialog(msg)</code> is a nice shortcut, try it <a href="#" id="ui-dialog-1">here</a>.</p>
<pre>
<code>
ui.dialog('Just another dialog')
.closable()
.show();
</code>
</pre>
<h3>ui.dialog(title, msg)</h3>
<p>How about a title this time? <a href="#" id="ui-dialog-2">try it</a>.</p>
<pre>
<code>
ui.dialog('Title', 'Just another dialog')
.closable()
.show();
</code>
</pre>
<h3>.hide([ms])</h3>
<p>Dialogs will remain open until you .close() them, optionally providing a delay in milliseconds. <a href="#" id="dialog-hide">Try it</a>.</p>
<pre>
<code>
var dialog = ui.dialog("I'll close in 2 seconds").show();
setTimeout(function(){
dialog.hide();
}, 2000);
</code>
</pre>
<h3>.overlay()</h3>
<p>This method adds an overlay, which may be clicked (by default) to close the dialog. <a href="#" id="dialog-overlay">Test it out</a>.</p>
<pre>
<code>
ui.dialog('Overlay time')
.closable()
.overlay()
.show();
</code>
</pre>
<h3>.modal()</h3>
<p>This method adds an overlay which is not clickable, the user must interact with the dialog. <a href="#" id="modal-overlay">Test it out</a>.</p>
<pre>
<code>
ui.dialog('Overlay time')
.closable()
.modal()
.show();
</code>
</pre>
<h3>.effect(name)</h3>
<p>Effects are simply applied via CSS classes, no JavaScript animations, so they're nice and fast! Try out the <a href="#" id="dialog-effect-slide">slide</a> effect.</p>
<pre>
<code>
ui.dialog('Hello!')
.effect('slide')
.show()
.hide(1500);
</code>
</pre>
<p>Try a few more, and remember, they're just classes! create your own.</p>
<ul>
<li><a href="#" class="effect-slide">slide</a></li>
<li><a href="#" class="effect-fade">fade</a></li>
<li><a href="#" class="effect-scale">scale</a></li>
</ul>
<h3>Auto-closing</h3>
<p>Dialog is aware of the "active" dialog, and when shown will hide the other. Test it out! click one of the links below and then quickly click another.</p>
<ul>
<li><a href="#" class="effect-slide">slide</a></li>
<li><a href="#" class="effect-fade">fade</a></li>
<li><a href="#" class="effect-scale">scale</a></li>
</ul>
<h3>Rich content</h3>
<p>Dialogs are of course not limited to the textual content mentioned so far, jQuery objects and other UIKit components may also be passed.</p>
<script>
$(function(){
$('#dialog-jquery').click(function(e){
e.preventDefault();
ui.dialog('jQuery object', $('Just a <strong>string</strong> of <em>HTML</em>.'))
.closable()
.show();
});
$('#dialog-colorpicker').click(function(e){
e.preventDefault();
var picker = new ui.ColorPicker;
ui.dialog('UIKit component', picker)
.closable()
.show();
});
});
</script>
<ul>
<li><a href="#" id="dialog-jquery">jQuery object</a></li>
<li><a href="#" id="dialog-colorpicker">ColorPicker</a></li>
</ul>
</section>
</section>
<section>
<h2 id="confirmation-section"><a href="#">Confirmation</a></h2>
<p>The Confirmation extends Dialog to provide a confirmation dialog.</p>
<section>
<h3>Example</h3>
<p>Click <a href="#" id="simple-confirmation">here</a> to
confirm removal of a user.</p>
<pre>
<code>
new ui.Confirmation({ title: 'Remove user', message: 'are you sure?' })
.show(function(ok){
if (ok) ui.dialog('user removed!').show().hide(1500);
});
</code>
</pre>
<h3>ui.confirm(title, msg)</h3>
<p>Much like ui.dialog() there's a shortcut, try it <a href="#" id="ui-confirm">here</a>. We can tweak the button text with .ok() and .cancel().</p>
<pre>
<code>
ui.confirm('Remove user', 'are you sure?')
.ok('Remove')
.cancel('No dont!')
.show(function(ok){
if (ok) ui.dialog('user removed!').show().hide(1500);
});
</code>
</pre>
<h3>ui.confirm(msg)</h3>
<p>You may omit the title as well, try it <a href="#" id="ui-confirm-2">here</a>. Clicking cancel or close will invoke the callback with false.</p>
<pre>
<code>
ui.confirm('are you sure?')
.closable()
.show(function(ok){
if (ok) ui.dialog('done!').show().hide(1500);
else ui.dialog('never-mind').show().hide(1500);
});
</code>
</pre>
</section>
</section>
<section>
<h2 id="colorpicker-section"><a href="#">ColorPicker</a></h2>
<p>A simple, small, elegant color picker component.</p>
<section>
<h3>Example</h3>
<p>With default dimensions of 180x180. On change rgb(<em class="r">0</em>,<em class="g">0</em>,<em class="b">0</em>) will update channels individually, or <em class="rgb">rgb(0,0,0)</em> with toString().</p>
<div id="default-color-picker"></div>
<pre>
<code>
var picker = new ui.ColorPicker;
picker.el.appendTo('#default-color-picker');
picker.on('change', function(color){
$('.r').text(color.r)
$('.g').text(color.g)
$('.b').text(color.b)
$('.rgb').text(color.toString()).css('background', color)
});
</code>
</pre>
<h3>.size(n)</h3>
<p>Adjust both width and height.</p>
<div id="color-picker-size"></div>
<pre>
<code>
var picker = new ui.ColorPicker;
picker.size(100);
picker.el.appendTo('#color-picker-size');
</code>
</pre>
<h3>.width(n) / .height(n)</h3>
<p>Either the width or height may be adjusted individually.</p>
<div id="color-picker-width"></div>
<pre>
<code>
var picker = new ui.ColorPicker;
picker.width(80);
picker.el.appendTo('#color-picker-width');
</code>
</pre>
<h3>ColorPicker in a Dialog</h3>
<p>Tight uikit integration means that components can interact, providing you with a simple API, simply add the picker as the message. Click to <a href="#" id="dialog-picker">try</a> it.</p>
<pre>
<code>
ui.dialog('Select a color', new ui.ColorPicker)
.effect('slide')
.closable()
.show();
</code>
</pre>
</section>
</section>
<section>
<h2 id="card-section"><a href="#">Card</a></h2>
<p>A simple double-sided card component.</p>
<section>
<h3>Example</h3>
<p>The following example displays a ColorPicker on the back face
and a simple paragraph on the front. Any component or jQuery()-able value may be used. You may also programmatically <a href="#" id="flip"> flip</a> the card.</p>
<div id="card"></div>
<pre>
<code>
var picker = new ui.ColorPicker;
var card = ui.card('<p>Click to show a color picker</p>', picker);
card.el.appendTo('#card');
$('#flip').click(function(){
card.flip();
})
</code>
</pre>
</section>
</section>
<section>
<h2 id="notification-section"><a href="#">Notification</a></h2>
<p>Unobtrusive growl-style notifications.</p>
<section>
<h3>Example</h3>
<p>Notifications come in three flavours, <code>ui.notify()</code> for general "info" messages, <code>ui.warn()</code> for warnings, and <code>ui.error()</code> for errors. These are identical except for the additional CSS class added to the list element. The notifications API is much like Dialog, titles are optional, and you can do things like <code>.hide()</code> the notification after a given duration defaulting to 4 seconds, they are <code>.closable()</code>, and may also be <code>.sticky()</code>. Click <a href="#" id="notify">here</a> to give it a try!</p>
<pre><code>$('#notify').click(function(e){
e.preventDefault();
ui.notify('Email', 'you have 3 new messages')
.effect('slide');
setTimeout(function(){
ui.warn('Warning', 'something happened')
.effect('slide');
setTimeout(function(){
ui.error('Error', 'something failed')
.closable()
.hide(8000)
.effect('slide');
setTimeout(function(){
ui.notify('Stick notification')
.sticky()
.effect('slide');
}, 200);
}, 200);
}, 200);
});</code>
</pre>
</section>
</section>
<section>
<h2 id="menu-section"><a href="#">Menu</a></h2>
<p>Simple menu component.</p>
<section>
<h3>Example</h3>
<p>A <code>Menu</code> is comprised of textual menu items and optional arbitrary callback functions. To add an item invoke <code>Menu#add()</code>, and to remove pass the same text to <code>Menu#remove()</code>. Give it a try! right click on this page.</p>
<pre><code>var menu = ui.menu()
.add('Add item')
.add('Edit item', function(){ console.log('edit'); })
.add('Remove item', function(){ console.log('remove'); })
.add('Remove "Add item"', function(){
menu
.remove('Add item')
.remove('Remove "Add item"');
});
menu.on('Add item', function(){
console.log('item added');
});
oncontextmenu = function(e){
e.preventDefault();
menu.moveTo(e.pageX, e.pageY).show();
};</code>
</pre>
</section>
</section>
<section>
<h2 id="split-button-section"><a href="#">SplitButton</a></h2>
<p>The split button component </p>
<section>
<h3>Example</h3>
<p>The <code>SplitButton</code> component emits three events, "click" when the button itself is clicked, "show" and "hide" for when the contents display is toggled. This component is abstract, it is not bound to a <code>Menu</code> or <code>ColorPicker</code> etc. One should inherit from this component to display content.</p>
<script>
$(function(){
var button = new ui.SplitButton('Action');
button.on('click', function(){
ui.notify('Button clicked');
});
button.on('show', function(){
ui.notify('Show dropdown');
});
button.on('hide', function(){
ui.notify('Hide dropdown');
});
button.el.appendTo('.example-split-button');
})
</script>
<p class="example-split-button"></p>
<pre><code>var button = new ui.SplitButton('Action');
button.on('click', function(){
ui.notify('Button clicked');
});
button.on('show', function(){
ui.notify('Show dropdown');
});
button.on('hide', function(){
ui.notify('Hide dropdown');
});
button.el.appendTo('.example-split-button');</code>
</pre>
</section>
</section>
</div>
</body>
</html>