-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcountdown.js
90 lines (77 loc) · 3.19 KB
/
countdown.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
$(document).ready( function () {
countDownElections();
setInterval(countDownElections, 60000);
countDownVotingPass();
setInterval(countDownVotingPass, 60000);
countDownVotingByPost();
setInterval(countDownVotingByPost, 60000);
function countDownElections() {
var counter = $('#count-down-elections');
var remaining = getRemainingTimeText('2016-03-05T07:00:00','#count-down-elections','Voľby sa už začali');
if(remaining){
var text = 'Do volieb zostáva: ' + remaining;
counter.html(text);
}
}
function countDownVotingPass() {
var counter = $('#count-down-voting-pass');
var remaining = getRemainingTimeText('2016-02-15T23:59:59','#count-down-voting-pass','Uplynul termín pre podanie žiadosti o hlasovací preukaz');
if(remaining){
var text = 'Pre podanie žiadosti o hlasovací preukaz ostáva: ' + remaining;
counter.html(text);
}
}
function countDownVotingByPost() {
var counter = $('#count-down-vote-by-post');
var remaining = getRemainingTimeText('2016-01-15T23:59:59','#count-down-vote-by-post','Uplynul termín pre podanie žiadosti o voľbu poštou');
if(remaining){
var text = 'Pre podanie žiadosti o hlasovací preukaz ostáva: ' + remaining;
counter.html(text);
}
}
function getRemainingTimeText(time,elid,timeouttext){
var remainingTime = (new Date(time)).getTime() - Date.now();
var counter = $(elid);
if (remainingTime < 0) {
counter.html(timeouttext);
return;
} else {
var daysInfo = 90;
var daysWarning = 60;
var daysDanger = 30;
if (daysNumber <= daysDanger && ! counter.hasClass('label-danger'))
switchLabelClass('label-danger');
else if (daysNumber <= daysWarning && ! counter.hasClass('label-warning'))
switchLabelClass('label-warnign');
else if (daysNumber <= daysInfo && ! counter.hasClass('label-info'))
switchLabelClass('label-info')
}
var daysNumber = Math.floor(remainingTime / (24 * 60 * 60 * 1000));
var dayInflection;
if (daysNumber == 1)
dayInflection = 'deň';
else if (daysNumber > 1 && daysNumber < 5)
dayInflection = 'dni';
else
dayInflection = 'dní';
remainingTime -= daysNumber * (24 * 60 * 60 * 1000);
var hoursNumber = Math.floor(remainingTime / (60 * 60 * 1000));
var hourInflection;
if (hoursNumber == 1)
hourInflection = 'hodina';
else if (hoursNumber > 1 && hoursNumber < 5)
hourInflection = 'hodiny';
else
hourInflection = 'hodín';
remainingTime -= hoursNumber * (60 * 60 * 1000);
var minutesNumber = Math.floor(remainingTime / (60 * 1000));
var minuteInflection;
if (minutesNumber == 1)
minuteInflection = 'minúta';
else if (minutesNumber > 1 && minutesNumber < 5)
minuteInflection = 'minúty';
else
minuteInflection = 'minút';
return ''+ daysNumber +' '+ dayInflection + ', '+ hoursNumber +' '+ hourInflection +' a '+ minutesNumber +' '+ minuteInflection;
}
});