diff options
author | jan <jan@ruken.pw> | 2015-12-30 14:08:03 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2015-12-30 14:08:03 (UTC) |
commit | a46963a6f9dff657a180ba0c6871c015871a80f5 (patch) | |
tree | 15adfd0298ff1d2fdfec62ceaabf8a904d811e74 /assets/js | |
parent | 36d7f9a0551a98eda1ff2a871254ff19128e7f63 (diff) |
instant. fucking. suche.
Diffstat (limited to 'assets/js')
-rw-r--r-- | assets/js/search.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/assets/js/search.js b/assets/js/search.js new file mode 100644 index 0000000..0f544ab --- /dev/null +++ b/assets/js/search.js | |||
@@ -0,0 +1,31 @@ | |||
1 | var strokeTimeout = null; | ||
2 | |||
3 | function instantSearch() { | ||
4 | value = document.getElementById("search").value; | ||
5 | |||
6 | if (strokeTimeout) { | ||
7 | clearTimeout(strokeTimeout); | ||
8 | } | ||
9 | strokeTimeout = setTimeout(doSearch, 150, value); | ||
10 | } | ||
11 | |||
12 | function doSearch(value) { | ||
13 | if (value == "") { | ||
14 | strokeTimeout = null; | ||
15 | return; | ||
16 | } | ||
17 | var xhr = new XMLHttpRequest(); | ||
18 | xhr.onreadystatechange = function() { | ||
19 | if (xhr.readyState == XMLHttpRequest.DONE) { | ||
20 | if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined') { | ||
21 | console.log(xhr.status); | ||
22 | document.getElementById("search-results").innerHTML = ''; | ||
23 | } | ||
24 | document.getElementById("search-results").innerHTML = xhr.response; | ||
25 | } | ||
26 | } | ||
27 | console.log(value); | ||
28 | xhr.open('GET', '/search/gril_instant/' + value, true); | ||
29 | xhr.send(null); | ||
30 | strokeTimeout = null; | ||
31 | } \ No newline at end of file | ||