forked from bevacqua/insignia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
162 lines (159 loc) · 4.19 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
<!doctype html>
<link href='dist/insignia.css' rel='stylesheet' type='text/css' />
<link href='example/example.css' rel='stylesheet' type='text/css' />
<title>Insignia</title>
<h1>Insignia</h1>
<h3>Customizable tag input. Progressive. No non-sense!</h3>
<a href='https://github.com/bevacqua/insignia'>
<img class='gh-fork' src='https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67' alt='Fork me on GitHub' data-canonical-src='https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png' />
</a>
<div class='examples'>
<div class='parent'>
<label for='ty'>Enter a space-separated list of tags: </label>
<div class='input'>
<input id='ty'>
</div>
<pre>
<code>
insignia(input);
</code>
</pre>
</div>
<div class='parent'>
<label for='custom'>Enter a list of tags using a custom delimiter: </label>
<div class='input'>
<input id='custom'>
</div>
<pre>
<code>
insignia(input, {
delimiter: ','
});
</code>
</pre>
</div>
<div class='parent'>
<label for='del'>If you want, you can allow humans to remove tags by clicking on the crosses.</label>
<div class='input'>
<input id='del'>
</div>
<pre>
<code>
insignia(input, {
deletion: true
});
</code>
</pre>
</div>
<div class='parent'>
<label for='def'>Default values are naturally welcome.</label>
<div class='input'>
<input id='def' value='tagging as a service'>
</div>
<pre>
<code>
insignia(input);
</code>
</pre>
</div>
<div class='parent'>
<label for='prs'>Sometimes we need to transform tags: </label>
<div class='input'>
<input id='prs' value='these were lower-case'>
</div>
<pre>
<code>
insignia(input, {
parse: function (value) {
return value.toUpperCase();
}
});
</code>
</pre>
</div>
<div class='parent'>
<label for='dup'>Duplicates are okay sometimes: </label>
<div class='input'>
<input id='dup' value='dupe dupe dupe'>
</div>
<pre>
<code>
insignia(input, {
validate: function (value, tags) {
return true;
}
});
</code>
</pre>
</div>
<div class='parent'>
<label for='bth'>Sometimes we need to do both! </label>
<div class='input'>
<input id='bth' value='a a b b c c'>
</div>
<pre>
<code>
insignia(input, {
parse: function (value) {
return value.toUpperCase();
},
validate: function (value, tags) {
return true;
}
});
</code>
</pre>
</div>
<div class='parent'>
<label for='lng'>Really long lists behave reasonably well, too.</label>
<div class='input'>
<input id='lng' value='Really long lists behave reasonably well, too. Especially if you take into account this is JavaScript!'>
</div>
<pre>
<code>
insignia(input);
</code>
</pre>
</div>
<div class='parent'>
<label for='mss'>Messing with the instance barely scratches the experience.</label>
<div class='inline input'>
<input id='mss' value='here are the tags'>
</div>
<button id='msst'>Destroy!</button>
<pre>
<code>
var tagInput = insignia(input);
// insignia.find(input) also returns tagInput
toggle.addEventListener('click', function () {
if (tagInput.destroyed) {
tagInput = insignia(input);
} else {
tagInput.destroy();
}
});
</code>
</pre>
</div>
<div class='parent'>
<label for='ant'>You can write a custom event handler to accept new tags on <kbd>Enter</kbd>: </label>
<sub>(but we wouldn't endorse doing that in forms, as it'd break the default submit behavior!)</sub>
<div class='input'>
<input id='ant'>
</div>
<pre>
<code>
var tagInput = insignia(input);
input.addEventListener('keypress', function (e) {
if (e.keyCode === 13) {
tagInput.convert();
e.preventDefault(); // prevent form submission
}
});
</code>
</pre>
</div>
</div>
<h3>Get it on GitHub! <a href='https://github.com/bevacqua/insignia'>bevacqua/insignia</a></h3>
<script src='dist/insignia.js'></script>
<script src='example/example.js'></script>