aboutsummaryrefslogtreecommitdiff
path: root/assets/js
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-30 14:08:03 (UTC)
committerjan <jan@ruken.pw>2015-12-30 14:08:03 (UTC)
commita46963a6f9dff657a180ba0c6871c015871a80f5 (patch)
tree15adfd0298ff1d2fdfec62ceaabf8a904d811e74 /assets/js
parent36d7f9a0551a98eda1ff2a871254ff19128e7f63 (diff)
instant. fucking. suche.
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/search.js31
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 @@
1var strokeTimeout = null;
2
3function instantSearch() {
4 value = document.getElementById("search").value;
5
6 if (strokeTimeout) {
7 clearTimeout(strokeTimeout);
8 }
9 strokeTimeout = setTimeout(doSearch, 150, value);
10}
11
12function 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