-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.js
111 lines (92 loc) · 3.5 KB
/
filter.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
$(document).ready(function(){
function show_all_rows() {
var rows = $('table tbody tr').each(function(i, row) {
var row = $(row)
row.show()
})
}
function uncheck_buttons() {
$('input[type=checkbox]').each(function(button) {
this.checked = false
})
}
$('#reset_filter').click(function() {
show_all_rows()
uncheck_buttons()
})
function create_year_buttons() {
var years = []
$('table tr td:nth-child(3)').each(function(i, year) {
var year_value = $(year).text()
if (!years.includes(year_value)) {
years.push(year_value)
}
})
years.sort()
years.forEach(year => {
$('#filter_section').append($('<label><input type="checkbox" class="years" id="'+ year + '" value="' + year + '"><span class="filter_by_year">' + year + '</span></label>'))
});
}
function create_keyword_buttons() {
var keywords = []
$('table tr td:nth-child(6)').each(function(i, keyword) {
var keyword_value = $(keyword).text()
var splitted_keywords = keyword_value.split(';')
splitted_keywords.forEach(splitted_keyword => {
splitted_keyword = splitted_keyword.replace(' ', '')
if (!keywords.includes(splitted_keyword)) {
keywords.push(splitted_keyword)
}
})
})
/* keywords.sort() */
keywords = ["behavior","brain_imaging","EEG","MEG", "fMRI", "electrophysiology", "human", "monkey", "rodent", "semantic", "visual", "backpropagation", "learning", "review"]
/* i overwrite the nice keyword list by the function create_keyword-function here, to sort these keywords - maybe there is another way to do it better.. */
keywords.forEach(keyword => {
$('#filter_section').append($('<label><input type="checkbox" class="keywords" id="'+ keyword + '" value="' + keyword + '"><span class="filter_by_keyword">' + keyword + '</span></label>'))
});
$('#filter_section').append($('</br>'))
}
create_keyword_buttons()
create_year_buttons()
function filter_rows(years, keywords) {
show_all_rows()
var rows = $('table tbody tr').each(function(i, row) {
var row = $(row)
var year_text = row.find("td:eq(2)").text()
var keyword_text = row.find("td:eq(5)").text()
var row_has_year_value = false;
var row_has_all_keyword_values = true;
years.forEach(function(year) {
if(year_text == year) {
row_has_year_value = true
}
})
keywords.forEach(function(keyword) {
if(!keyword_text.includes(keyword)) {
row_has_all_keyword_values = false
}
})
if(!row_has_all_keyword_values && keywords.length != 0) {
row.hide()
} else if (!row_has_year_value && years.length != 0) {
row.hide()
}
})
}
$("input").change(function(e){
var years = []
$('input[type=checkbox].years').each(function(button) {
if(this.checked) {
years.push(this.value)
}
})
var keywords = []
$('input[type=checkbox].keywords').each(function(button) {
if(this.checked) {
keywords.push(this.value)
}
})
filter_rows(years, keywords)
});
});