forked from denis-taran/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
362 lines (314 loc) · 8.42 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
<!doctype html>
<head>
<meta charset="utf-8">
<title>Autocomplete - lightweight open-source autocomplete library</title>
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width">
<script src="./autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="./autocomplete.css">
<link rel="shortcut icon" type="image/x-icon" href="./favicon.ico" />
<style>
html {
height: 100%;
box-sizing: border-box;
overflow: auto;
padding: 0;
margin: 0;
}
body {
height: 100%;
background: linear-gradient(-77deg, transparent 95%, rgba(255, 255, 255, 0.23) 15%),
linear-gradient(-77deg, transparent 90%, rgba(255, 255, 255, 0.18) 10%),
linear-gradient(-77deg, transparent 85%, rgba(255, 255, 255, 0.1) 10%),
#1789c7;
background-size: cover;
box-sizing: border-box;
overflow-x: hidden;
overflow-y: auto;
padding: 0;
margin: 0;
font: 14px/18px "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif
}
body * {
font: inherit;
max-width: 100%;
}
@media (max-width: 800px) {
body {
background: #1789c7;
padding-left: 20px;
padding-right: 20px;
}
}
::-webkit-input-placeholder {
color: #888;
}
:-moz-placeholder {
color: #888;
}
::-moz-placeholder {
color: #888;
}
:-ms-input-placeholder {
color: #888;
}
input[type="text"] {
display: block;
float: left;
width: 100%;
box-sizing: border-box;
font: 13px/20px 'Lucida Sans Unicode', sans-serif;
color: black;
padding: 5px 9px 4px 9px;
outline: none;
border: 1px solid #2da5da;
position: relative;
border-radius: 4px;
-webkit-appearance: none;
}
input[type="text"]:focus {
border-color: #2da5da;
}
body > .main {
padding-top: 35px;
width: 600px;
margin: 0 auto;
}
@media (max-width: 600px) {
body > .main {
padding-top: 25px;
}
}
h1 {
font: bold 38px/38px "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
color: white;
padding: 0 0 20px 0;
margin: 0;
}
h2 {
font: 15px/24px "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
color: white;
padding: 0 0 20px 0;
margin: 0;
position: relative;
top: -20px;
}
@media (max-width: 600px) {
h2 {
padding-top: 15px;
font-size: 14px;
line-height: 20px;
padding-bottom: 0;
}
}
.autocomplete {
border-color: #2da5da;
border-radius: 4px;
}
.autocomplete > div {
padding: 0 9px;
font-size: 12px;
line-height: 21px;
padding-bottom: 2px;
}
.label {
color: white;
font: 11px/17px "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.box {
width: 190px;
box-sizing: border-box;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 4px;
float: left;
margin: 0;
padding: 0;
background: white;
text-align:center;
display: table;
font-size: 17px;
line-height: 26px;
box-shadow: rgba(0,0,0,0.3) 0 0 2px;
}
.box > div {
display: table-cell;
vertical-align: middle;
font-size: 14px;
}
@media (max-width: 600px) {
.box {
color: white;
background: none;
border: none;
text-align: left;
box-shadow: none;
}
.box > div {
line-height: 14px;
}
}
.text-shadow {
text-shadow: 0 1px 1px rgba(0,0,0,0.4)
}
.box + .box {
margin-left: 15px;
}
@media (max-width: 600px) {
.box {
width: 100%;
}
.box + .box {
margin-top: 20px;
margin-left: 0;
}
}
.boxes {
margin-top: 20px;
}
.boxes:after {
content: '';
display: table;
clear: both;
}
.boxes + .boxes {
margin-top: 18px;
}
.headline {
width: 100%;
margin: 60px 0 0 0;
padding: 0;
color: white;
font: 18px/30px "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
border-bottom: 1px dotted white;
}
.headline.links {
margin-top: 30px;
}
.link {
color: white;
text-decoration: none;
font: 15px/30px "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.link:hover {
text-decoration: underline;
}
.link + .link {
margin-left: 15px;
}
strong {
font-weight: bold!important;
}
@media (max-width: 600px) {
.headline + .link {
margin-top: 10px;
}
.link {
width: 100%;
display: block;
font-size: 14px;
}
.link + .link {
margin-left: 0;
}
}
</style>
</head>
<body>
<div class="main">
<h1 class="text-shadow">Autocomplete</h1>
<h2 class="text-shadow">Blazing fast and lightweight autocomplete library without dependencies. 1KB gzipped.</h2>
<span class="label">Demo</span>
<input type="text" id="testinput" placeholder="Type 'a'" />
<div class="headline text-shadow">Features</div>
<div class="boxes">
<div class="box">
<div>
Only 1KB gzipped
</div>
</div>
<div class="box">
<div>Load data with AJAX</div>
</div>
<div class="box">
<div>
Suggestion Groups
</div>
</div>
</div>
<div class="boxes">
<div class="box">
<div>
Custom Rendering
</div>
</div>
<div class="box">
<div>
Made with Typescript
</div>
</div>
<div class="box small">
<div>Open-Source & Free</div>
</div>
</div>
<div class="boxes">
<div class="box">
<div>
Debouncing
</div>
</div>
<div class="box">
<div>
No Dependencies
</div>
</div>
<div class="box small">
<div>Easy-to-Use</div>
</div>
</div>
<div class="headline links text-shadow"></div>
<a class="link" href="https://github.com/kraaden/autocomplete">Getting Started</a>
<a class="link" href="https://github.com/kraaden/autocomplete">Download</a>
<a class="link" href="https://github.com/kraaden/autocomplete/issues">Issue Tracker</a>
<a class="link" href="https://www.npmjs.com/package/autocompleter">NPM Package</a>
</div>
<script>
var countries = ['Afghanistan', 'Albania', 'Algeria', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bangladesh', 'Belarus', 'Belgium', 'Bolivia', 'Brazil', 'Bulgaria', 'Cameroon', 'Canada', 'Central African Republic', 'Chad', 'Chile', 'China', 'Colombia', 'Denmark', 'Dominica', 'Dominican Republic', 'Ecuador', 'Finland', 'France', 'Georgia', 'Germany', 'Gibraltar', 'Greece', 'Greenland', 'Guadeloupe', 'Guatemala', 'Guyana', 'Haiti', 'Iceland', 'India', 'Indonesia', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Mauritius', 'Mayotte', 'Mexico', 'Moldova', 'Norway', 'Palau', 'Paraguay', 'Poland', 'Portugal', 'Romania', 'Saint Helena', 'Saint Pierre and Miquelon', 'South Africa', 'South Georgia', 'South Korea', 'Spain', 'Sweden', 'Swaziland', 'Switzerland', 'United Kingdom', 'United States'];
var continents = ["Africa", "Europe", "America", "Australia", "Asia", "Antarctica"];
var conts = continents.map(function(n) { return { label: n, group: "Continents" }});
var items = countries.map(function (n) { return { label: n, group: "Countries" }}).concat(conts);
var allowedChars = new RegExp(/^[a-zA-Z\s]+$/)
function charsAllowed(value) {
return allowedChars.test(value);
}
autocomplete({
input: document.getElementById('testinput'),
minLength: 1,
onSelect: function (item, inputfield) {
inputfield.value = item.label
},
fetch: function (text, callback) {
var match = text.toLowerCase();
callback(items.filter(function(n) { return n.label.toLowerCase().indexOf(match) !== -1; }));
},
render: function(item, value) {
var itemElement = document.createElement("div");
if (charsAllowed(value)) {
var regex = new RegExp(value, 'gi');
var inner = item.label.replace(regex, function(match) { return "<strong>" + match + "</strong>" });
itemElement.innerHTML = inner;
} else {
itemElement.textContent = item.label;
}
return itemElement;
},
emptyMsg: "No countries found",
customize: function(input, inputRect, container, maxHeight) {
if (maxHeight < 100) {
container.style.top = "";
container.style.bottom = (window.innerHeight - inputRect.bottom + input.offsetHeight) + "px";
container.style.maxHeight = "140px";
}
}
})
document.querySelector("input").focus();
</script>
</body>