-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·117 lines (91 loc) · 2.97 KB
/
main.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
var facultyURL = 'https://docs.google.com/spreadsheets/d/1p8r5qRrLbDJp1tmBXvZow9ygzn2EVv3f_m0lgONC1HE/pubhtml';
Tabletop.init({
key: facultyURL,
callback: processData,
simpleSheet: true,
});
function mergeNameAndWebsite(name, website) {
if (!website) { return name; }
return '<span class="invisible">' + name + '</span>'
+ '<a target="_blank" href="http://' + website + '">' + name + '</a>';
}
function mergeTitleResearchNeeds(title, research, needs) {
res = '';
if (title) {
res += '<h3>' + title + '</h3>';
}
res += '<p><span class="emphasis">Research Project: </span>' + research + '</p>';
if (needs) {
res += '<p><span class="emphasis">Student Researchers: </span>' + needs + '</p>';
}
return res;
}
function emailToLink(email) {
if (!email) { return ''; }
return ' <a href="mailto:' + email + '"> <i class="fa fa-envelope"> </a>'
}
function processData(data, tabletop) {
if (!data[0]) return;
var processedData = [];
for (i in data) {
var r = data[i];
if (r.Display !== 'y') continue;
// Add a row to the final dataset
processedData.push([
mergeNameAndWebsite(r.Name, r.Website),
emailToLink(r.Email),
r.Division + (r['Applying for Public Humanities Collaborative?'] == 'Yes' ? ', Public Humanities Collaborative' : ''),
mergeTitleResearchNeeds(r.Title, r.Research, r['Student Researchers']),
]);
}
// Adding custom filtering
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
// This is a JavaScript object whose keys will
// be the checked values (e.g. Arts, "Social Sciences")
showOnly = {};
$('input:checkbox:checked').each(function() {
showOnly[this.value] = 1;
});
var divisions = data[2].split(',').map(function(x) {return x.trim()});
for (i in divisions) {
if (showOnly[divisions[i]] === 1) {
return true;
}
}
return false;
}
);
$(document).ready(function() {
var table = $('#results').DataTable({
paging: false,
info: false,
ordering: true,
data: processedData,
columns: [
{title: 'Faculty', width: '120px', className: 'td-center'},
{title: 'Email', className: 'td-center', orderable: false},
{title: 'Division', width: '50px', orderable: false},
{title: 'Research', orderable: false},
]
});
$('input[name="filter"]').change(function() {
table.draw();
});
});
var filters = [
['Arts', 'Art'],
['Humanities', 'Hum'],
['Sciences', 'Sci'],
['Social Sciences', 'Soc'],
['Public Humanities Collaborative', 'PHC']
]
function renameCheckboxes() {
var shorten = $(window).width() < 900 ? 1 : 0;
$('#filters label').each(function(i) {
$(this).text(filters[i][shorten])
});
}
$(window).resize(renameCheckboxes);
renameCheckboxes();
}