-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab.js
120 lines (82 loc) · 2.7 KB
/
tab.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var timer = null;
var currentSection = '';
var handleFormSubmit = function() {
// set the current dob
var dobEl = document.getElementById("property_field_dob");
if(dobEl.value == "") return;
saveOptions({
dob: dobEl.value
}, function(){
render();
});
return false;
};
var render = function(params) {
if(!params) params = {};
if(timer) {
clearTimeout(timer);
timer = null;
}
getOptions(function(options){
// sanity check with sections
var sections = ((options || {}).dob || '').split('-');
// set the current dob
var dobEl = document.getElementById("property_field_dob");
dobEl.value = (options || {}).dob;
if(!options.dob || sections.length < 3) {
// birth date is not set!
return showSection('tab-section', 'properties');
}
// birth date is not set!
showSection('tab-section', 'counter');
// constants
var timer = null;
var UPDATE_PERIOD = 1000; // 1 second
var timestamp = new Date();
var median = Math.floor(daysBetweenDates(new Date(2000, 01, 01), new Date(2070, 01, 01)));
// create the ticker
var tick = new Clock(document.querySelectorAll('.clock')[0]);
// parse the dob date
var sections = ((options || {}).dob || '').split('-');
// sets the actual UI components up
var setState = function() {
if(getSection() != 'counter') return;
if(timer) clearTimeout(timer);
// get the days
var days = daysBetweenDates(new Date(), new Date(parseInt(sections[0]), parseInt(sections[1])-1, parseInt(sections[2])));
var rdays = Math.floor(days);
var fdays = rdays.toLocaleString(
undefined, // use a string like 'en-US' to override browser locale
{ minimumFractionDigits: 0 }
);
// create the element
tick.update(fdays);
// set the items
document.title = rdays + ' Days';
// set mean
document.getElementById('days_left').innerText = Math.floor(median - days).toLocaleString(
undefined, // use a string like 'en-US' to override browser locale
{ minimumFractionDigits: 0 }
).toString();
// run again
timer = setTimeout(setState, UPDATE_PERIOD);
};
// do a run
setState();
});
};
var boot = function() {
// bind events
bindToClass('link-properties', function() {
showSection('tab-section', 'properties');
return false;
});
var formEl = document.getElementById('property-form');
if (formEl.attachEvent) {
formEl.attachEvent("submit", handleFormSubmit);
} else {
formEl.addEventListener("submit", handleFormSubmit);
}
render({});
};
document.addEventListener('DOMContentLoaded', function() { boot() });