aboutsummaryrefslogtreecommitdiff
path: root/assets/js
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-30 14:19:43 (UTC)
committerjan <jan@ruken.pw>2015-12-30 14:19:43 (UTC)
commit05e0c7d20701640e16db361fb66fc2bc0b85276e (patch)
treeea521679d9c4fd7bd1c2de869e09227d4021dec7 /assets/js
parentcbdd91454ac9ac7a44766f67d374fde1ee27ec9e (diff)
kleine verbesserungen bei der clientseitigen suche. hoffentlich fühlt es sich jetzt etwas runder an.
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/search.js13
1 files changed, 6 insertions, 7 deletions
diff --git a/assets/js/search.js b/assets/js/search.js
index 0f544ab..ebf46cb 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -1,30 +1,29 @@
1var strokeTimeout = null; 1var strokeTimeout = null;
2 2
3function instantSearch() { 3function instantSearch() {
4 value = document.getElementById("search").value;
5
6 if (strokeTimeout) { 4 if (strokeTimeout) {
7 clearTimeout(strokeTimeout); 5 clearTimeout(strokeTimeout);
8 } 6 }
9 strokeTimeout = setTimeout(doSearch, 150, value); 7 strokeTimeout = setTimeout(doSearch, 150, value);
10} 8}
11 9
12function doSearch(value) { 10function doSearch() {
13 if (value == "") { 11 value = document.getElementById("search").value;
12
13 if (value === "") {
14 strokeTimeout = null; 14 strokeTimeout = null;
15 return; 15 return;
16 } 16 }
17 var xhr = new XMLHttpRequest(); 17 var xhr = new XMLHttpRequest();
18 xhr.onreadystatechange = function() { 18 xhr.onreadystatechange = function() {
19 if (xhr.readyState == XMLHttpRequest.DONE) { 19 if (xhr.readyState == XMLHttpRequest.DONE) {
20 if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined') { 20 if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined' || xhr.response === '404 not found') {
21 console.log(xhr.status);
22 document.getElementById("search-results").innerHTML = ''; 21 document.getElementById("search-results").innerHTML = '';
22 return
23 } 23 }
24 document.getElementById("search-results").innerHTML = xhr.response; 24 document.getElementById("search-results").innerHTML = xhr.response;
25 } 25 }
26 } 26 }
27 console.log(value);
28 xhr.open('GET', '/search/gril_instant/' + value, true); 27 xhr.open('GET', '/search/gril_instant/' + value, true);
29 xhr.send(null); 28 xhr.send(null);
30 strokeTimeout = null; 29 strokeTimeout = null;