-
Notifications
You must be signed in to change notification settings - Fork 0
/
life.html
105 lines (99 loc) · 3.8 KB
/
life.html
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
<!DOCTYPE html>
<html>
<head>
<title>My Life In Weeks</title>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//www.geoplugin.net/javascript.gp"></script>
<style type="text/css">
.week {
width: 10px;
height: 10px;
margin: 1px;
border: solid 1px black;
float: left;
background-color: white;
}
.age {
font-size: xx-small;
margin-left: -13px;
position:relative;
z-index: -10;
}
#weeks {
margin-left: 20px;
}
.inline {
display: inline-block;
}
fieldset {
border: none;
}
</style>
<script type="application/javascript">
$(function(){
$.ajax('http://apps.who.int/gho/athena/data/COUNTRY.json', {dataType: 'jsonp'}).done(function(data) {
var map = {};
$.each(data.dimension[0].code, function(i,code){
if (code.attr === undefined) return;
var isoAttr = code.attr.find(function(item){ return item.category == 'ISO2'; });
if (isoAttr) map[isoAttr.value] = code.label;
isoAttr = code.attr.find(function(item){ return item.category == 'ISO'; });
if (isoAttr) map[isoAttr.value] = code.label;
});
var country = map[geoplugin_countryCode()];
console.log(country);
var url = 'http://apps.who.int/gho/athena/data/GHO/WHOSIS_000001.json?profile=simple&filter=SEX:MLE;COUNTRY:'+country;
$.ajax(url, {dataType: 'jsonp'}).done(function(life){
console.log(life);
});
});
var dob = new Date(localStorage['weeks-dob'] || '1970-01-01');
$('input[name=dob]')
.val(dob.toISOString().substr(0,10))
.change(function(){
localStorage['weeks-dob'] = $(this).val();
});
var sex = localStorage['weeks-sex'] || 'FMLE';
$('input[value='+sex+']').prop('checked',true);
$('input[name=sex]').change(function(){
localStorage['weeks-sex'] = $(this).val();
});
$('select[name=country]').append($('<option/>').text(geoplugin_countryName()).val(geoplugin_countryCode()).attr('selected','true'));
for (var i = 0; i < 52*90; i++) {
var age = Math.floor(i / 52);
var month = Math.floor((i - age*52) * 7 * 12 / 365);
var color = '#DDFF9D';
if (age > 4) color = '#FFE47A';
if (age > 19) color = '#97DFFF';
if (age > 23) color = '#FFB8BF';
if (age > 63) color = '#D9C7FF';
if (age > 76) color = '';
$('<div class="week"/>')
.attr('title', 'Age ' + age + ' years and ' + month + ' months')
.css('background-color', color)
.append($('<div class="age"/>').text(age.toFixed(0)))
.appendTo('#weeks');
}
});
</script>
</head>
<body>
<div>
<h3 class="inline">My life in weeks</h3>
<fieldset class="inline">
Gender:
<input type="radio" name="sex" id="sex-female" value="FMLE"/><label for="sex-female">Female</label>
<input type="radio" name="sex" id="sex-male" value="MLE"/><label for="sex-male">Male</label>
</fieldset>
<fieldset class="inline">
Date of birth:
<input type="date" name="dob"/>
</fieldset>
<fieldset class="inline">
Country:
<select name="country"></select>
</fieldset>
</div>
<div id="weeks"></div>
</body>
</html>