-
Notifications
You must be signed in to change notification settings - Fork 98
/
index.html
144 lines (144 loc) · 4.88 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
<!doctype html>
<link href='dist/horsey.css' rel='stylesheet' type='text/css' />
<link href='example/example.css' rel='stylesheet' type='text/css' />
<title>horsey</title>
<h1>horsey</h1>
<h3>Progressive and customizable autocomplete component</h3>
<a href='https://github.com/bevacqua/horsey'>
<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='hy'>Enter the name of a fruit: </label>
<input id='hy'/>
<pre>
<code>
horsey(document.querySelector('input'), {
source: [{ list: ['banana', 'apple', 'orange'] }]
});
</code>
</pre>
</div>
</div>
<div class='parent'>
<label for='ly'>Lazy load the fruits, useful for AJAX! <i>(loading starts when the field is focused)</i></label>
<div><i id='lyr'>Being lazy...</i></div>
<input id='ly'/>
<pre>
<code>
horsey(document.querySelector('input'), {
source (data, done) {
var items = [ 'banana', 'apple', 'orange' ];
setTimeout(() => done(null, [{
list: items.filter(item => item.indexOf(data.input) !== -1)
}]), 2000);
}
});
</code>
</pre>
</div>
<div class='parent'>
<label for='kv'>You can also use "key value pairs": </label>
<input id='kv'/>
<pre>
<code>
horsey(document.querySelector('input'), {
source: [{ list: [
{ value: 'banana', text: 'Bananas from Amazon Rainforest' },
{ value: 'apple', text: 'Red apples from New Zealand' },
{ value: 'orange', text: 'Oranges from Moscow' },
{ value: 'lemon', text: 'Juicy lemons from Amalfitan Coast' }
]}],
getText: 'text',
getValue: 'value'
});
</code>
</pre>
</div>
<div class='parent'>
<label for='ig'>But why stop there? You can render the suggestion however you like! </label>
<input id='ig'/>
<pre>
<code>
horsey(document.querySelector('input'), {
source: [{ list: [
{ value: 'banana', text: 'Bananas from Amazon Rainforest' },
{ value: 'apple', text: 'Red apples from New Zealand' },
{ value: 'orange', text: 'Oranges from Moscow' },
{ value: 'lemon', text: 'Juicy lemons from Amalfitan Coast' }
]}],
getText: 'text',
getValue: 'value',
renderItem: function (li, suggestion) {
var image = '<img class="autofruit" src="example/fruits/' + suggestion.value + '.png" /> ';
li.innerHTML = image + suggestion.text;
}
});
</code>
</pre>
</div>
<div class='parent'>
<label for='ig'>You can also limit the amount of suggestions to display! </label>
<input id='il'/>
<pre>
<code>
horsey(document.querySelector('input'), {
source: [{ list: [
{ value: 'banana', text: 'Bananas from Amazon Rainforest' },
{ value: 'banana-boat', text: 'Banana Boat' },
{ value: 'apple', text: 'Red apples from New Zealand' },
{ value: 'apple-cider', text: 'Red apple cider beer' },
{ value: 'orange', text: 'Oranges from Moscow' },
{ value: 'orange-vodka', text: 'Classic orange vodka cocktail' },
{ value: 'lemon', text: 'Juicy lemons from Amalfitan Coast' }
]}],
getText: 'text',
getValue: 'value',
limit: 2
});
</code>
</pre>
</div>
<div class='parent'>
<label for='ig'>Want to use it as in a textarea? </label>
<textarea id='ta'>Add a mention somewhere in the textarea, using an at-sign like in emails. For example, you can type @michael. The cursor will actually follow you, pretty nice!</textarea>
<pre>
<code>
horsey(document.querySelector('textarea'), {
source: [{ list: [
{ value: '@michael', text: 'Michael Jackson' },
{ value: '@jack', text: 'Jack Johnson' },
{ value: '@ozzy', text: 'Ozzy Osbourne' }
]}],
getText: 'text',
getValue: 'value',
anchor: '@'
});
</code>
</pre>
</div>
<div class='parent'>
<label for='ig'>Want to use it as a drop-down list? </label>
<div id='ddl'>Click here to set fruity treat type</div>
<pre>
<code>
horsey(document.querySelector('div'), {
source: [{ list: [
{ value: 'banana', text: 'Bananas from Amazon Rainforest' },
{ value: 'banana-boat', text: 'Banana Boat' },
{ value: 'apple', text: 'Red apples from New Zealand' },
{ value: 'apple-cider', text: 'Red apple cider beer' },
{ value: 'orange', text: 'Oranges from Moscow' },
{ value: 'orange-vodka', text: 'Classic orange vodka cocktail' },
{ value: 'lemon', text: 'Juicy lemons from Amalfitan Coast' }
]}],
getText: 'text',
getValue: 'value'
});
</code>
</pre>
</div>
</div>
<h3>Get it on GitHub! <a href='https://github.com/bevacqua/horsey'>bevacqua/horsey</a></h3>
<script src='dist/horsey.js'></script>
<script src='example/example.js'></script>