-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
81 lines (63 loc) · 2.17 KB
/
test.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
$(document).ready( function() {
$.ajax({
type: 'GET',
url: 'data/univ.csv',
dataType: 'text',
success: processData,
error: function (err) { console.error(err); }
});
//Convert text dump into an array of objects
function processData (res) {
var dataLines = res.split(/\r\n|\n/);
var headers = dataLines[0].split(',');
var masterData = [];
for (var i=1; i<dataLines.length; i++) {
var row = dataLines[i].split(',');
if (row.length == headers.length) {
var rowObj = {};
for (var j=0; j<headers.length; j++) {
rowObj[headers[j]] = row[j];
}
masterData.push(rowObj);
}
}
renderTable(masterData);
//http://isotope.metafizzy.co/layout-modes/vertical.html
// init Isotope
var $container = $('.table-like').isotope({
layoutMode: 'vertical',
getSortData: {
female: '.female parseInt',
rank: '.rank parseInt'
}
});
// bind sort button click
$('#sorts').on( 'click', 'button', function() {
var sortValue = $(this).attr('data-sort-value');
$container.isotope({
sortBy: sortValue,
sortAscending: {female: false}
});
});
// change is-checked class on buttons
$('.button-group').each( function( i, buttonGroup ) {
var $buttonGroup = $( buttonGroup );
$buttonGroup.on( 'click', 'button', function() {
$buttonGroup.find('.is-checked').removeClass('is-checked');
$( this ).addClass('is-checked');
});
});
}
//Render the table from the csv data
function renderTable(data) {
$.each(data, function (i, d) {
var imgPath = 'logos/' + d.university + '.jpg'
var img = '<img class="logo" src="' + imgPath + '" />' + '</div>';
var univDiv = '<div class="univ">' + d.university + '</div>';
var countDiv = '<div class="female">' + d.count + '</div>';
var rankDiv = '<div class="rank">' + d.usnews_ranking + '</div>';
var cells = img + univDiv + countDiv + rankDiv;
$('.table-like').append('<li class="table-like__item">' + cells + '</li>');
});
}
});