aboutsummaryrefslogtreecommitdiff
blob: 2d38c0dd8d2986c36dc3c59466c0b75c77fac78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function getParameter(param) {
    var result = null,
        tmp = [];
    location.search
        .substr(1)
        .split("&")
        .forEach(function (item) {
          tmp = item.split("=");
          if (tmp[0] === param) result = decodeURIComponent(tmp[1]);
        });
    return result;
}


if(getParameter('q') == null){
  document.getElementById("spinner").style.display = "none";
}


var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {

    var data = JSON.parse(this.responseText)

    var idx = lunr(function () {
        this.ref('title')
        this.field('author')
        this.field('nickname')
        this.field('date')
        this.field('scope')
        this.field('content')

        data.forEach(function (doc) {
          this.add(doc)
        }, this)

      })

    var searchterm = getParameter('q');
    if(searchterm == null){
      console.log("No search term given");
    }else{
      idx.search(searchterm).forEach(function (doc) {
        $("#articles").append("<li>" + doc.ref + "</li>");
      }, this)
      document.getElementById("spinner").style.display = "none";
    }

  }
};
xhttp.open("GET", "data.json", true);
xhttp.send();