-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocomplete.html
103 lines (83 loc) · 4.65 KB
/
autocomplete.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>autocomplete snippet -- geocode.city</title>
<meta name="description" content="geocode.city -- city-only geocoding">
<meta name="author" content="geocode.city">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="dist/base.min.css" type="text/css" rel="stylesheet">
<link href="https://fonts.gstatic.com/" rel="preconnect">
<style>
</style>
</head>
<body class="markdown">
<main class="one-column">
<h1>Autocomplete Snippet</h1>
<p>
<a href="/">back to index</a>
</p>
<p>
For convenience, we provide a simple, unstyled, "drop-it-in-your-page" snippet. We emit a few custom events
and all markup has CSS classes, so you can customize both the look and behavior as you wish.
</p>
<article>
<h2>Usage</h2>
<mark>Note: this is meant to be a quick reference; check out the <a href="https://github.com/geocode-city/autocomplete">source code</a> for the most up to date technical documentation.</mark>
<p>
For the most basic use, you just need to include the snippet, and provide an element with id <code>geocode-city-autocomplete</code>. Ideally, it's a container like a `div`.
</p>
<p>You can inspect the source of <a href="/">the index page</a> to check out some custom usage, but here's a copy/paste for your quick reference:</p>
<!-- HTML generated using hilite.me -->
<div
style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;">
<pre style="margin: 0; line-height: 125%"><div id=<span style="color: #a31515">"geocode-city-autocomplete"</span>></div>
<h2 id=<span style="color: #a31515">"res-title"</span> class=<span style="color: #a31515">"hidden"</span>>You selected:</h3>
<pre id=<span style="color: #a31515">"results"</span>>
</pre>
<script src=<span
style="color: #a31515">"https://cdn.jsdelivr.net/gh/geocode-city/autocomplete@0.1.0.1/dist/geocode_city.min.js"</span>></script>
<script>
<span style="color: #0000ff">let</span> el = document.getElementById(<span style="color: #a31515">"geocode-city-autocomplete"</span>);
<span style="color: #0000ff">let</span> res = document.getElementById(<span style="color: #a31515">"results"</span>);
<span style="color: #0000ff">let</span> title = document.getElementById(<span style="color: #a31515">"res-title"</span>);
el.addEventListener(<span style="color: #a31515">"citySelected"</span>, <span style="color: #0000ff">function</span> (e) {
title.classList.remove(<span style="color: #a31515">"hidden"</span>);
res.textContent = JSON.stringify(e.detail, <span style="color: #0000ff">undefined</span>, 2);
});
</script>
</pre>
</div>
<br>
<h3>Options</h3>
<p>All of the below options are optional, and passed as attributes of the element you identify as <code>geocode-city-autocomplete</code></p>
<dl>
<dt>data-api-key</dt>
<dd>Your api key. If not provided, the user's browser will be used for rate limiting.</dd>
<dt>data-suggestion-count</dt>
<dd>The number of suggestions to show, defaults to 5.</dd>
<dt>data-input-name</dt>
<dd>The <code>name</code> attribute for the text input.</dd>
<dt>data-input-class</dt>
<dd>The <code>class</code> attribute for the text input.</dd>
</dl>
<h3>Events</h3>
<p>All of the below are custom events emitted in the element you use the snippet on. You can use <code>addEventListener</code> to listen for them, and any data
included is sent through the <code>event.detail</code> property (read more about <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events">custom events on MDN</a>.)</p>
<dl>
<dt>citySelected</dt>
<dd>When a city is selected from the dropdown. Includes the full <code>city</code> object.</dd>
<dt>citiesFound</dt>
<dd>An array of cities, if any results are found.</dd>
<dt>noCitiesFound</dt>
<dd>When no results are found, no data is sent.</dd>
<dt>lookupError</dt>
<dd>In the event of a client or server error; the error message is sent.</dd>
</dl>
<h3>Styling</h3>
<p>TODO. In the meantime, check out the <a href="https://github.com/geocode-city/autocomplete">source</a>: all markup
that the snippet generates has the <code>geocode-city__</code> prefix.</p>
</article>
</main>
</body>
</html>