index.html
30.7 KB
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Select or Die</title>
<link href='http://fonts.googleapis.com/css?family=Lato:300,700,900' rel='stylesheet' type='text/css'>
<link href="../_src/selectordie.css" rel="stylesheet" type="text/css">
<link href="!inc/css/selectordie_theme_02.css" rel="stylesheet" type="text/css">
<link href="!inc/css/demo.css" rel="stylesheet" type="text/css">
<!-- <script src="!inc/js/jquery-2.1.0.min.js"></script> -->
<script src="!inc/js/jquery-1.8.0.min.js"></script>
<script src="!inc/js/jquery.litelighter.js"></script>
<script src="../_src/selectordie.min.js"></script>
<script src="!inc/js/demo.js"></script>
</head>
<body>
<section id="cover" class="cover">
<!-- Photo from https://www.flickr.com/photos/nlireland/11833296283/ - Found at http://nos.twnsnd.co/ -->
<select class="well_hello_there" data-placeholder="Select or Die" data-custom-class="cover_sod no_highlight">
<option value="#intro">What?</option>
<option value="#config">Config</option>
<option value="#methods">Methods</option>
<option value="#download">Download / Usage</option>
</select>
</section>
<section id="intro">
<div class="content">
<h1>What?</h1>
<p>Here we go again, yet another jQuery plugin to style <span class="option"><select></span> elements. That's pretty much it. Scroll down and take a look if it might be something for you.</p>
</div>
</section>
<section id="config">
<div class="content">
<header>
<h1>Config</h1>
<p>A couple of configurable options to use with Select or Die (SoD).</p>
</header>
<table border="0" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th scope="col">Option</th>
<th scope="col">Type</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="option"><a href="#custom" title="customID">customID</a></td>
<td class="option">string</td>
<td>
<div class="hidden option">
<a href="#custom" title="customID">customID</a> - <span class="type">string</span>
</div>
Add a custom class to the SoD element
</td>
</tr>
<tr>
<td class="option"><a href="#custom" title="customClass">customClass</a></td>
<td class="option">string</td>
<td>
<div class="hidden option">
<a href="#custom" title="customClass">customClass</a> - <span class="type">string</span>
</div>
Add a custom class to the SoD element
</td>
</tr>
<tr>
<td class="option"><a href="#placeholder" title="placeholder">placeholder</a></td>
<td class="option">string</td>
<td>
<div class="hidden option">
<a href="#placeholder" title="placeholder">placeholder</a> - <span class="type">string</span>
</div>
Add a placeholder that's show before a selection has been made
</td>
</tr>
<tr>
<td class="option"><a href="#prefix" title="prefix">prefix</a></td>
<td class="option">string</td>
<td>
<div class="hidden option">
<a href="#prefix" title="prefix">prefix</a> - <span class="type">string</span>
</div>
Add a prefix that's always shown before the selected option
</td>
</tr>
<tr>
<td class="option"><a href="#cycle" title="cycle">cycle</a></td>
<td class="option">boolean</td>
<td>
<div class="hidden option">
<a href="#cycle" title="cycle">cycle</a> - <span class="type">boolean</span>
</div>
Keyboard support is always enabled, but if you set this to <span class="option">true</span> the end user will be able to cycle the list of options. Example: when you've reach the bottom of the list and press the down/right arrow key it will jump back up to the first option.
</td>
</tr>
<tr>
<td class="option"><a href="#links" title="links">links</a></td>
<td class="option">boolean</td>
<td>
<div class="hidden option">
<a href="#links" title="links">links</a> - <span class="type">boolean</span>
</div>
Treat the options as links?
</td>
</tr>
<tr>
<td class="option"><a href="#links" title="links">linksExternal</a></td>
<td class="option">boolean</td>
<td>
<div class="hidden option">
<a href="#links" title="links">links</a> - <span class="type">boolean</span>
</div>
Treat the options as external links?
</td>
</tr>
<tr>
<td class="option"><a href="#size" title="size">size</a></td>
<td class="option">integer</td>
<td>
<div class="hidden option">
<a href="#size" title="size">size</a> - <span class="type">integer</span>
</div>
Do you have a long list of options? Set the <span class="option">size</span> to control how many options that's visible in the SoD before the need to scrol
</td>
</tr>
<tr>
<td class="option"><a href="#tabindex" title="tabindex">tabindex</a></td>
<td class="option">integer</td>
<td>
<div class="hidden option">
<a href="#tabindex" title="tabindex">tabindex</a> - <span class="type">integer</span>
</div>
Set a custom tabindex on the SoD
</td>
</tr>
<tr>
<td class="option"><a href="#callback" title="onChange">onChange</a></td>
<td class="option">function</td>
<td>
<div class="hidden option">
<a href="#callback" title="onChange">onChange</a> - function
</div>
Provide a callback that will fire when a selection has been made
</td>
</tr>
</tbody>
</table>
<p>There's also a couple of public methods available, more about them in the <a href="#methods">methods section</a> further down on the page.</p>
</div>
</section>
<section id="basic">
<div class="content arrow">
<header>
<h1>Basic example</h1>
<p>Apply the plugin and you're good to go.</p>
</header>
<code>
<pre>$("select").selectOrDie();</pre>
</code>
</div>
<div class="preview">
<select class="basic">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<optgroup label="Option Group Label">
<option value="group.one">Option Group.One</option>
<option value="group.two">Option Group.Two</option>
</optgroup>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="custom">
<div class="content arrow">
<header>
<h1>Custom class/ID</h1>
<p><span class="option">""</span> by default</p>
<p>Maybe you have multiple selects on the same page and one should look different, or whatever need you can find for a custom class/ID. In this example we're using a custom class give the SoD a different look.</p>
</header>
<code>
<pre>
$("select").selectOrDie({
customClass: "custom",
customID: "custom"
});</pre>
<p>or</p>
<pre>
$("select").selectOrDie();
<select data-custom-id="custom" data-custom-class="custom"></pre>
</code>
</div>
<div class="preview">
<select class="basic" data-custom-id="custom" data-custom-class="custom">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<optgroup label="Option Group Label">
<option value="group.one">Option Group.One</option>
<option value="group.two">Option Group.Two</option>
</optgroup>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="placeholder">
<div class="content arrow">
<header>
<h1>Placeholder</h1>
<p><span class="option">null</span> by default</p>
<p>If you feel like adding a placeholder that's displayed before anything is selected. Once a selection has been made the placeholder will be removed until the user clicks the SoD again, then it will be shown until the user makes a new selection or focus is lost on the SoD. The "placeholder" is given the class <span class="option">.sod_placeholder</span></p>
</header>
<code>
<pre>
$("select").selectOrDie({
placeholder: "Choose a number"
});</pre>
<p>or</p>
<pre>
$("select").selectOrDie();
<select data-placeholder="Choose a number"></pre>
</code>
</div>
<div class="preview">
<select class="basic" data-placeholder="Choose a number">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="prefix">
<div class="content arrow">
<header>
<h1>Prefix</h1>
<p><span class="option">null</span> by default</p>
<p>Add a prefix that's displayed in front of the selected option. The "prefix" is given the class <span class="option">.sod_prefix</span>,</p>
</header>
<code>
<pre>
$("select").selectOrDie({
prefix: "Number:"
});</pre>
<p>or</p>
<pre>
$("select").selectOrDie();
<select data-prefix="Number:"></pre>
</code>
</div>
<div class="preview">
<select class="basic" data-prefix="Number:">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="cycle">
<div class="content arrow">
<header>
<h1>Keyboard cycle</h1>
<p><span class="option">false</span> by default</p>
<p>When enabled it allows the user to cycle the list using his/hers arrow keys.</p>
</header>
<code>
<pre>
$("select").selectOrDie({
cycle: true
});</pre>
<p>or</p>
<pre>
$("select").selectOrDie();
<select data-cycle="true"></pre>
</code>
</div>
<div class="preview">
<select class="basic" data-cycle="true">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="links">
<div class="content arrow">
<header>
<h1>Links / External links</h1>
<p><span class="option">false</span> by default</p>
<p>There's two different ways of defining links. By using <span class="option">links</span> the links will open in the same window/tab, if you use <span class="option">linksExternal</span> the links will be opened in a new window/tab.</p>
<p>You can also define a specific option to act as a link by adding a data attribute to the specific option in the native select. More on that in the <a href="#various">various</a> section below.</p>
</header>
<code>
<pre>
$("select").selectOrDie({
links: true,
placeholder: "Go to...",
customClass: "no_highlight"
});</pre>
<p>or</p>
<pre>
$("select").selectOrDie();
<select data-links="true" data-placeholder="Go to..." data-custom-class="no_highlight"></pre>
</code>
</div>
<div class="preview">
<select class="basic" data-links="true" data-placeholder="Go to..." data-custom-class="no_highlight">
<option value="https://github.com/vestman/">GitHub</option>
<option value="http://dribbble.com/MyBeardAndI/">Dribbble</option>
<option value="http://twitter.com/MyBeardAndI">Twitter</option>
</select>
</div>
</section>
<section id="size">
<div class="content arrow">
<header>
<h1>Size</h1>
<p><span class="option">0</span> by default</p>
<p>The select below consists of 10 options, but since the size is set to 4 it will only show 4 before you have to scroll (or use your up/down keys) to see the rest of the options.</p>
</header>
<code>
<pre>
$("select").selectOrDie({
size: 5
});</pre>
<p>or</p>
<pre>
$("select").selectOrDie();
<select data-size="5"></pre>
</code>
</div>
<div class="preview">
<select class="basic" data-size="5">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
<option value="six">Six</option>
<option value="seven">Seven</option>
<option value="eight">Eight</option>
<option value="Nine">Nine</option>
<option value="Ten">Ten</option>
<option value="Eleven">Eleven</option>
<option value="Twelve">Twelve</option>
<option value="Thirteen">Thirteen</option>
<option value="Fourteen">Fourteen</option>
<option value="Fifteen">Fifteen</option>
</select>
</div>
</section>
<section id="tabindex">
<div class="content arrow">
<header>
<h1>Tabindex</h1>
<p><span class="option">0</span> by default</p>
<p>The SoD will grab the <span class="option">tabindex</span> set on the native select, but you can override the default tabindex by specifying a custom one. If no tabindex is set on the native select or no custom tabindex is defined then the tabindex of the SoD will be set to <span class="option">0</span></p>
</header>
<code>
<pre>
$("select").selectOrDie({
tabindex: 10
});</pre>
<p>or</p>
<pre>
$("select").selectOrDie();
<select data-tabindex="10"></pre>
</code>
</div>
<div class="preview">
<select class="basic" data-tabindex="10">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="callback">
<div class="content arrow">
<header>
<h1>Callback</h1>
<p><span class="option">$.noop</span> by default</p>
<p>So you want to do something after the user has made a selection? Go ahead.</p>
</header>
<code>
<pre>
$("select").selectOrDie({
onChange: function() { alert( $(this).val() ) }
});</pre>
</code>
</div>
<div class="preview">
<select class="callback">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="methods">
<div class="content">
<header>
<h1>Methods</h1>
<p>These might come in handy one day. Click the different methods below to see them in action.</p>
</header>
<table border="0" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th scope="col">Method</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="option"><a href="#destroy" title="destroy">destroy</a></td>
<td>
<a href="#destroy" class="hidden option" title="destroy">destroy</a>
Kills the SoD element and restore everything back to normal
</td>
</tr>
<tr>
<td class="option"><a href="#update" title="update">update</a></td>
<td>
<a href="#update" class="hidden option" title="update">update</a>
Update the SoD to reflect changes made to the native <span class="option"><select></span>
</td>
</tr>
<tr>
<td class="option"><a href="#disable_enable" title="disable">disable</a></td>
<td>
<a href="#disable_enable" class="hidden option" title="disable">disable</a>
Disable the SoD (and the native <span class="option"><select></span>), an entire option group or an option
</td>
</tr>
<tr>
<td class="option"><a href="#disable_enable" title="enable">enable</a></td>
<td>
<a href="#disable_enable" class="hidden option" title="enable">enable</a>
Enable the SoD (and the native <span class="option"><select></span>), an entire option group or an option
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="destroy">
<div class="content arrow">
<header>
<h1>Destroy</h1>
<p>Destroy the SoD and remove all traces of it.</p>
</header>
<div class="actions">
<span class="trigger" data-method="destroy">
<span>Destroy</span>
<span class="hidden">Initiate</span>
the SoD
</span>
</div>
<code>
<pre>$("select").selectOrDie();</pre>
</code>
</div>
<div class="preview">
<select class="basic">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="update">
<div class="content arrow">
<header>
<h1>Update</h1>
<p>Lets say an option have been added to the native <span class="option"><select></span>, then you might want to update the SoD to reflect the native <span class="option"><select></span>. Then it's just a matter of running the <span class="option">update</span> method and the SoD will update with the new option.</p>
</header>
<div class="actions">
<span class="trigger" data-method="update">Append an option and update the SoD</span>
</div>
<code>
<pre>$("select").selectOrDie();</pre>
</code>
</div>
<div class="preview">
<select class="basic">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
</div>
</section>
<section id="disable_enable">
<div class="content arrow">
<header>
<h1>Disable / Enable</h1>
<p>If you need to disable/enable a SoD or any of its option groups/options manually, then use the <span class="option">disable</span> or <span class="option">enable</span> method.</p>
</header>
<div class="actions">
<span class="trigger" data-method="disable">
<span>Disable</span>
<span class="hidden">Enable</span>
the SoD
</span>
<label for="enable_disable">
<span class="trigger" data-sub-method="option" data-method="disable">
<span>Disable</span>
<span class="hidden">Enable</span>
option "Three"
</span>
</label>
<label for="enable_disable">
<span class="trigger" data-sub-method="group" data-method="disable">
<span>Disable</span>
<span class="hidden">Enable</span>
optgroup "Option Group Label"
</span>
</label>
</div>
<code>
<pre>$("select").selectOrDie();</pre>
</code>
</div>
<div class="preview">
<select class="basic" id="enable_disable">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<optgroup label="Option Group Label">
<option value="group.one">Option Group.One</option>
<option value="group.two">Option Group.Two</option>
</optgroup>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
</section>
<section id="download">
<div class="content">
<header>
<h1>Download / Usage</h1>
</header>
<p>Download the .zip file by clicking the download button below. Once downloaded, unzip it and include the <span class="option">selectordie.css</span> and either of the two <span class="option">.js</span> files found in the "_src" folder. Initialize the plugin, targeting the desired element in the jQuery selector. Just like in the <a href="#basic">basic</a> example above. Then you're all good!</p>
<p class="buttons">
<a href="https://github.com/vestman/Select-or-Die/archive/master.zip" class="external button">Download</a>
<a href="https://github.com/vestman/Select-or-Die/fork" class="external button">Fork</a>
</p>
</div>
</section>
<section id="various">
<div class="content arrow">
<header>
<h1>Various</h1>
</header>
<ul class="list">
<li>Touch devices triggers the native select element</li>
<li>SoD will automatically detect a disabled <span class="option"><select></span>, the same goes for option groups and options</li>
<li>When in focus (the SoD gets focus when tabbing to it or clicking it) you can use your keys to "search" the SoD, just like a native <span class="option"><select></span></li>
<li>Option groups (<span class="option"><optgroup></span>) are given the class <span class="option">.optgroup</span> and its children the class <span class="option">.groupchild</span></li>
<li>Options that won't fit the width of the SoD gets automatically truncated</li>
<li>SoD will detect if any part of the options list is below the user viewport. If it is and it will fit above it will be shown above the SoD</li>
<li>You can pass a custom class or ID to individual options in the SoD by adding either <span class="option">data-custom-class</span> or <span class="option">data-custom-id</span> to an option in the native select</li>
<li>You can set a single option to act as a link without using the <a href="#links" title="links">links</a> option. To do so you add either <span class="option">data-link="true"</span> or <span class="option">data-link-external="true"</span> to the specific option in the native select. The <span class="option">data-link-external</span> can also be used to open a specific link in a new window/tab even if the SoD itself is defined as internal links using the <a href="#links">links</a> option.</li>
<li>If you add the class <span class="option">.no_highlight</span> as a custom class to your SoD then the default check mark highlighting the selected option will not be displayed</li>
<li><span class="option"><label></span> elements targeting the native select will set focus on the SoD. Once a SoD has focus the user can press the space bar to open it or use the arrow keys to move around in the SoD. Give it a try: <label for="label_test" class="action">I'm a label</label> for the SoD below</li>
</ul>
</div>
<div class="preview">
<select class="basic" id="label_test">
<option value="one">Regular option</option>
<option value="two" disabled="disabled">Disabled option</option>
<option value="three">Regular option</option>
<optgroup label="Option Group Label (disabled)" disabled="disabled">
<option value="group.one">Option Group.One</option>
<option value="group.two">Option Group.Two</option>
</optgroup>
<option value="four">An option that's a bit too long for its own good</option>
<option value="six" data-custom-class="bones">Custom class option</option>
<option value="http://www.google.com/" data-link="true">Link option (google.com)</option>
<option value="http://www.google.com/" data-link-external="true">External link option (google.com)</option>
</select>
</div>
</section>
<section id="compability">
<div class="content">
<header>
<h1>Compability / Misc</h1>
<p>I'll try to keep it short.</p>
</header>
<ul class="list">
<li>Tested with jQuery v1.8 and jQuery v2.1 and nothing in between (it should work just fine with a version in between the tested versions). Please note that if you use jQuery 2.x IE8 will not be supported, you can read more about this over att the <a class="external" href="http://blog.jquery.com/2013/04/18/jquery-2-0-released/" title="http://blog.jquery.com/2013/04/18/jquery-2-0-released/">jQuery blog</a>.</li>
<li>Tested in Firefox / Chrome / Safari / Opera / IE8+</li>
<li>This demo is using <a class="external" href="http://trentrichardson.com/examples/jQuery-Litelighter/" title="http://trentrichardson.com/examples/jQuery-Litelighter/">jQuery Litelighter</a> by Trent Richardson. The jQuery Litelighter is NOT required by Select or Die, it's just used to format the code blocks in this demo.</li>
<li>Cover photo found over at <a class="external" href="http://nos.twnsnd.co/image/81190207271" title="http://nos.twnsnd.co/image/81190207271">New Old Stock</a></li>
</ul>
</div>
</section>
<section id="todo">
<div class="content">
<header>
<h1>Todo</h1>
<p>There's probably a ton of things to do/fix, but here's a couple:</p>
</header>
<ul class="list">
<li>Add support for <span class="option"><select multiple></span></li>
<li>Fix typos/grammar in this demo. If you spot any, feel free to send me an email.</li>
</ul>
</div>
</section>
</body>
</html>