aboutsummaryrefslogtreecommitdiff
path: root/assets_src/js/lib/search.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets_src/js/lib/search.js')
-rw-r--r--assets_src/js/lib/search.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/assets_src/js/lib/search.js b/assets_src/js/lib/search.js
new file mode 100644
index 0000000..0cb33df
--- /dev/null
+++ b/assets_src/js/lib/search.js
@@ -0,0 +1,40 @@
1var strokeTimeout = null;
2
3function instantSearch() {
4 if (strokeTimeout) {
5 clearTimeout(strokeTimeout);
6 }
7 strokeTimeout = setTimeout(doSearch, 150);
8}
9
10function doSearch() {
11 value = document.getElementById("search").value;
12
13 if (value === "") {
14 strokeTimeout = null;
15 document.getElementById("search-results").innerHTML = "";
16 return;
17 }
18 var xhr = new XMLHttpRequest();
19 xhr.onreadystatechange = function() {
20 if (xhr.readyState == XMLHttpRequest.DONE) {
21 if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined' || xhr.response === '404 not found') {
22 document.getElementById("search-results").innerHTML = '';
23 return
24 }
25 if (value === "") {
26 document.getElementById("search-results").innerHTML = "";
27 return;
28 }
29
30 document.getElementById("search-results").innerHTML = xhr.response.replace(new RegExp('{ (.*?)(' + value + ')(.*?) }', 'gi'), "$1<b>$2</b>$3").replace(new RegExp('{ (.*?) }', 'gi'), '$1');
31 }
32 }
33 xhr.open('GET', '/search/gril_instant/' + value, true);
34 xhr.send(null);
35 strokeTimeout = null;
36}
37
38function clickSearchResult(resId) {
39
40} \ No newline at end of file