-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
61 lines (54 loc) · 1.16 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
function buttons(data){
var n = 5
var i = 0
var index = 'row-0'
$.each(data.chromosomes, function(){
if (n == 5){
index = 'row-' + i
var row = '<div class = btn-row id =' + index + '></div>'
$('.main').append(row);
n = 0;
i += 1;
}
var name = this.name
var row = '#' + index
var div = '<div class = "btn" id ='+ name +'>' + name + '</div>';
$(row).append(div)
n += 1;
});
}
function activate(){
var submit = '<a href = visualization.html class = "btn" id = "submit">Submit</a>';
$('.main').append(submit);
$('.btn').click(function(event){
if (event.target.id != 'submit') {
$(this).toggleClass('active');
}
});
$('#submit').click(function(event){
var output = [];
$('.btn').each(function(){
if (this.className == 'btn active'){
output.push(this.id);
}
});
document.cookie = 'chromosomes=' + output;
console.log(document.cookie);
});
}
function setup(){
$.ajax({
type: 'GET',
dataType: "json",
url: 'names.json',
})
.done(function(names){
buttons(names);
activate();
})
.fail(function(xhr, status, error) {
console.log("Error: " + error);
console.log("Status: " + status);
});
};
setup()