forked from se2018/coffee-chats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
52 lines (45 loc) · 1.21 KB
/
script.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
/**
Shuffles array in place.
@param {Array} a items An array containing the items.
**/
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
}
// read from data.tsv and generate html for each mentor
$.get('./data.tsv', (data) => {
var rows = data.split('\n');
rows.shift(); // remove first header row
shuffle(rows); // shuffle the order of mentors every page load
var mentors = rows.map((row) => {
var col = row.split('\t');
// NOTE: modify what is displayed by changing 1) and 2)
// 1) how mentor data is mapped (columns in the .tsv file to fields)
var mentor = {
'name': col[0],
// 'year': '',
'about': col[1],
'talk': col[2],
'fun': col[3]
};
// 2) the html template used to display each mentor
var mentorTemplate = `
<div class="mentor">
<h2>
${mentor.name}
<!-- <span class="year">${mentor.year}</span> -->
</h2>
<div class="about">${mentor.about}</div>
<div class="fun"><b>Fun fact: </b>${mentor.fun}</div>
<div class="talk"><b>Talk to me about: </b>${mentor.talk}</div>
</div>
`;
return mentorTemplate;
});
$('#mentors').html(mentors);
});