diff options
author | rtz12 <koenig@fagott.pw> | 2016-01-20 18:34:19 (UTC) |
---|---|---|
committer | rtz12 <koenig@fagott.pw> | 2016-01-20 18:34:19 (UTC) |
commit | 5325336ea46e4347f4ca12d4daaeec6269ce6c7b (patch) | |
tree | e608e0eecc6da33aa23fd7811c2e488cfe22ce5d /assets_src/js/lib | |
parent | 94da9601d1d17ddeaf1d7d5ea8df68008e90f3ab (diff) |
Buildsystem verfeinert
Dafuer JS temporaer kaputtgemacht
Diffstat (limited to 'assets_src/js/lib')
-rw-r--r-- | assets_src/js/lib/search.js | 40 |
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 @@ | |||
1 | var strokeTimeout = null; | ||
2 | |||
3 | function instantSearch() { | ||
4 | if (strokeTimeout) { | ||
5 | clearTimeout(strokeTimeout); | ||
6 | } | ||
7 | strokeTimeout = setTimeout(doSearch, 150); | ||
8 | } | ||
9 | |||
10 | function 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 | |||
38 | function clickSearchResult(resId) { | ||
39 | |||
40 | } \ No newline at end of file | ||