-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.js
93 lines (86 loc) · 2.93 KB
/
application.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
var reload = function(){
$.get({
url: "https://recuperem-cors-anywhere.herokuapp.com/docs.google.com/spreadsheets/d/e/2PACX-1vQiCUlLoI5grAcifORhhWirGLoaFA7t9v024l3V4MMhoC7XHvMLSNWZs2-1IPOIil1Wxgzm0J8kjCpi/pub?gid=2065355145&single=true&output=csv&cache=" + Date.now(),
dataType: "text",
success: function(response){
var data = $.csv.toArrays(response),
$entitats = $('#entitats'),
$individuals = $('#individuals'),
entities_count = 0,
people_count = 0,
goal_count = 0;
// clear
$entitats.empty();
$individuals.empty();
// fill
for(var i = 0; i<data.length; i++) {
var row = data[i],
name = row[1];
if(row[0] == 'Persona individual') {
people_count++;
$individuals.append("<li>" + name + "</li>")
} else {
entities_count++;
$entitats.append("<li>" + name + "</li>")
}
}
goal_count = 5000;
if(people_count > goal_count) goal_count = 7500;
if(people_count > goal_count) goal_count = 10000;
if(people_count > goal_count) goal_count = 15000;
if(people_count > goal_count) goal_count = 20000;
if(people_count > goal_count) goal_count = 25000;
if(people_count > goal_count) goal_count = 50000;
if(people_count > goal_count) goal_count = 75000;
if(people_count > goal_count) goal_count = 100000;
var formatNumber = function (x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
$('#entities-count').html(formatNumber(entities_count));
$('#people-count').html(formatNumber(people_count));
$('#goal-count').html(formatNumber(goal_count));
$('.progress').show();
$('.progress .bar').css('width', (100 * people_count/goal_count) + '%')
}
});
};
$(document).ready(function() {
reload();
setInterval(function(){
reload();
}, 60 * 1000);
$('[data-action=scroll-to][data-destination]').on('click', function(e){
e.preventDefault();
var destionationId = $(this).data('destination'),
$destination = $('#' + destionationId);
if($destination) {
$('body,html').animate({
scrollTop: $destination.offset().top
}, {
duration: 600
});
}
});
$('[data-action=share]').on('click', function(e){
e.preventDefault();
var $share = $('.share');
$share.slideToggle();
$share.toggleClass('active');
if($share.hasClass('active')) {
var destination = $share.offset().top - $(window).height()/2 - $share.outerHeight()/2;
var destination = $share.offset().top - 100;
if(window.scrollY < destination) {
$('body,html').animate({
scrollTop: destination
}, {
duration: 600
});
}
}
});
$('[data-action=more-drawings]').on('click', function(e){
e.preventDefault();
$('.drawings .hidden').toggle();
$(this).parents('.more').remove()
});
});