-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.lnr.js
133 lines (98 loc) · 3.13 KB
/
script.lnr.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
addEventListener('DOMContentLoaded', (event) =>
{
// * These keywords are used in the filter menu
let kwWhitelist = ['machine learning', 'reinforcement learning', 'health', 'biomedical ai', 'linked open data',
'graph learning', 'semantic web']
// * Collect all keywords
let pubs = document.querySelectorAll('ul.publications li');
pubs = [...pubs];
pubs.forEach((pub) =>
{
let kws = pub.querySelectorAll('ul.keywords li');
kws = [...kws];
let myKeywords = new Set();
kws.forEach(kw => {
myKeywords.add(kw.innerHTML);
});
pub['keywords'] = myKeywords;
});
// * Generate filter menu
let nav = document.querySelector('nav.publication-links');
let span = document.createElement('span');
span.innerHTML = 'keyword: ';
let ul = document.createElement('ul');
nav.prepend(span, ul);
let li0 = document.createElement('li');
let button0 = document.createElement('button');
button0.innerHTML = 'show all';
button0.className = 'link'
button0.disabled = true;
button0.addEventListener('click', filterClick);
li0.append(button0);
ul.append(li0);
kwWhitelist.forEach(keyword =>
{
let li = document.createElement('li');
let button = document.createElement('button');
button.innerHTML = keyword;
button.className = 'link'
button.addEventListener('click', filterClick)
li.append(button);
ul.append(li);
});
});
function isIn(term, list) {
/**
* Check whether a term is in a list of string, ignoring cases both ways.
*
* In the case of a match, return the string in the list. Otherwise return false.
*/
for(let lterm of list)
{
if (lterm.toLowerCase() == term.toLowerCase())
return true;
}
return false;
}
/**
* Filter click event.
*/
function filterClick(event)
{
let keyword = event.target.innerHTML;
let all = keyword == 'show all';
let pubs = document.querySelectorAll('ul.publications > li')
pubs = [...pubs];
pubs.forEach(pub =>
{
pub.classList.remove('hidden');
if ( ! ( all || isIn(keyword, pub['keywords'])) )
{
pub.classList.add('hidden');
}
});
// * Reset all links to active, and disable the one that was clicked
let links = document.querySelectorAll('nav.publication-links ul li button')
links = [...links];
links.forEach(link => {
link.disabled = false;
});
event.target.disabled = true;
// * Reset the years so that only the top pub for a given year has it as non-hidden.
let lastYear = -1;
// * loop over all non-hidden publications
pubs.forEach(pub => {
if ( ! pub.classList.contains('hidden') )
{
let yearNode = pub.querySelector('.issued')
if (yearNode)
{
yearNode.classList.remove('hidden');
if (yearNode.innerHTML == lastYear)
yearNode.classList.add('hidden')
lastYear = yearNode.innerHTML
}
}
});
}