-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
97 lines (85 loc) · 2.4 KB
/
index.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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Kardashian Calculator</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Kardashian Calculator</h1>
</div>
<div class="row">
<div class="span7">
<form id="form">
<div class="clearfix">
<label for="from">Married On</label>
<div class="input">
<input class="disabled" type="text" id="from" type="text" disabled>
</div>
</div>
<div class="clearfix">
<label for="to">Until</label>
<div class="input">
<input class="disabled" type="text" id="to" type="text" disabled>
</div>
</div>
<div class="actions">
<input type="submit" class="btn primary disabled" value="Calculate" disabled>
</div>
</form>
</div>
<div class="span9">
<p>A “Kardashian” is a unit of measure representing 72 days of marriage. See how many Kardashians you have been married for using the form to the left.</p>
<div id="output"></div>
</div>
</div>
</div>
<script>
require = { async: true };
</script>
<script src="dojo/dojo.js"></script>
<script>
require([
"dojo/on",
"dojo/dom",
"dojo/dom-class",
"dojo/query",
"dojo/date",
"dojo/date/locale"
], function(on, dom, cls, query, date, locale){
function kcalc(from, to){
var kardashians = (date.difference(from, to, "day") + 1) / 72;
return (Math.round(kardashians * 100) / 100)
}
var form = dom.byId("form"),
from = dom.byId("from"),
to = dom.byId("to"),
output = dom.byId("output");
to.value = locale.format(new Date(), { selector: "date" });
on(form, "submit", function(evt){
evt.preventDefault();
query("input[type='text']", form).forEach(function(node){
cls.remove(node.parentNode.parentNode, "error");
});
var f = locale.parse(from.value, { selector: "date" }),
t = locale.parse(to.value, { selector: "date" });
if(!f){
cls.add(from.parentNode.parentNode, "error");
return;
}
if(!t){
cls.add(to.parentNode.parentNode, "error");
return;
}
output.innerHTML = "You have been married " + kcalc(f, t) + " Kardashians!";
});
query("input").forEach(function(node){
cls.remove(node, "disabled");
node.disabled = false;
});
});
</script>
</body>
</html>