-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.html
90 lines (73 loc) · 2.29 KB
/
filter.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
layout: "default"
title: "Filter"
---
<div class="row">
<div class="column">
<h3>VM operating system</h3>
<select id="os">
<option value="all" selected>All</option>
<option value="windows">Windows</option>
<option value="linux">Linux</option>
<option value="generic">OS independent</option>
</select>
</div>
<div class="column">
<h3>My role</h3>
<select id="role">
<option value="all" selected>All</option>
<option value="admin">Administrator</option>
<option value="user">Normal user</option>
</select>
</div>
<div class="column">
<h3>Article type</h3>
<select id="type">
<option value="all" selected>All</option>
<option value="howto">How to</option>
<option value="tshoot">Trouble shooting</option>
</select>
</div>
</div>
<div class="row">
<ul id="articles">
</ul>
</div>
<script>
function selectChange() {
let os = $("#os").val();
let role = $("#role").val();
let tp = $("#type").val();
let catArray = [os, role, tp];
let dispArticle = docArray.filter((doc) => {
let ret = true;
catArray.forEach((val) => {
if (val != "all") {
ret = ret & doc.categories.includes(val);
}
});
return ret;
});
$("#articles").empty();
dispArticle.forEach((doc) => {
$("#articles").append(`<li> <a href="${doc.url}">${doc.title}</a></li>`)
});
}
// initialise the array
let docArray = new Array();
{% for item in site.documents %}
docArray.push(
{
title: "{{item.title | escape }}",
url: "{{item.url | relative_url}}",
categories: {{ item.categories | jsonify }}
}
);
{% endfor %}
// register event
$("#os").on("change", selectChange);
$("#role").on("change", selectChange);
$("#type").on("change", selectChange);
// trigger a change
selectChange();
</script>