aboutsummaryrefslogtreecommitdiff
path: root/assets/js
diff options
context:
space:
mode:
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