This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.htm
188 lines (151 loc) · 6.55 KB
/
index.htm
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mayan Calendar</title>
<!-- bootstrap css files -->
<link href="lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="lib/jquery-ui-1.9.2.custom/css/smoothness/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<link href="lib/jquery-bootstrap-slider/css/bootstrap-slider.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Mayan Calendar</h2>
<div class="well">
<div id="slider"></div>
</div>
<div class="well navbar-fixed-bottom" style="text-align:center">
<canvas id="stela" width="0" height="0"></canvas>
</div>
</div>
<!-- requestAnimationFrame shim -->
<script src="lib/requestAnimationFrame.js"></script>
<!-- calendar conversion tool -->
<script src="lib/fourmilab/astro.js"></script>
<script src="lib/fourmilab/calendar.js"></script>
<!-- Mayan calendar code -->
<script src="mayan/calendar.js"></script>
<script src="mayan/glyphs.js"></script>
<script src="mayan/stela.js"></script>
<script src="mayan/counter.js"></script>
<script src="mayan/renderer.js"></script>
<script src="mayan/tests.js"></script>
<!-- user interface components -->
<script src="lib/jquery-1.8.3.min.js"></script>
<script src="lib/jquery-bootstrap-slider/js/jquery-ui.min.js"></script>
<script src="lib/bootstrap/js/bootstrap.js"></script>
<!-- startup script -->
<script>
$(function(){
// Create Mayan calendar and pass it a canvas object
var renderer = new Mayan.Renderer(document.getElementById('stela'));
// Update the calendar with a count (number of days since Mayan creation date)
var updateCount = function(count) {
// Update target date for transitioning
renderer.targetCal.setFromCount(count);
// Update slider tooltip
var text = mayan_days_to_gregorian_str(count);
sliderTooltip.options.title = text;
refreshTooltip(sliderTooltip);
};
// Create an initial Mayan count representing today's date
var initialCount = gregorian_to_mayan_days.apply(null, todaysdate());
// Initialize the slider
$('#slider').slider({
min:0,
max:2880000,
step:1,
slide: function(evt,ui) { updateCount(ui.value); },
change: function(evt,ui) { updateCount(ui.value); },
value: initialCount,
});
// Initialize the slider tooltip
var sliderHandle = $('#slider .ui-slider-handle');
sliderHandle.tooltip({title:' ',trigger:"manual",placement:"bottom"});
sliderHandle.tooltip("show");
var sliderTooltip = sliderHandle.data('tooltip');
// Set the initial date
updateCount(initialCount);
// Load all the glyph images and start animation when done
Mayan.loadGlyphs(function() {
renderer.stela.updateCanvasSize();
requestAnimationFrame(function(){renderer.render();});
});
});
</script>
<!-- misc utility scripts -->
<script>
// zero-padding from:
// http://stackoverflow.com/questions/1267283/how-can-i-create-a-zerofilled-value-using-javascript
function paddy(n, p, c) {
var pad_char = typeof c !== 'undefined' ? c : '0';
var pad = new Array(1 + p).join(pad_char);
return (pad + n).slice(-pad.length);
}
// get current date from:
// http://stackoverflow.com/questions/1531093/how-to-get-current-date-in-javascript
function todaysdate() {
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1; //January is 0!
var year = today.getFullYear();
return [year,month,day];
}
// extra date conversion functions
function mayan_days_to_gregorian(count) {
return jd_to_gregorian(MAYAN_COUNT_EPOCH + count);
}
function gregorian_to_mayan_days(year, month, day) {
return gregorian_to_jd(year,month,day) - MAYAN_COUNT_EPOCH;
}
var mayan_days_to_gregorian_str = function(count) {
var greg = mayan_days_to_gregorian(count);
var year = greg[0];
var month = greg[1];
var day = greg[2];
var dayStr = paddy(day,2);
var yearStr = "";
if (year <= 0) {
year = -year+1;
yearStr += " BC";
}
else {
yearStr += " AD";
}
yearStr = paddy(year,4) + yearStr;
var monthStr = [
"", "Jan", "Feb", "Mar", "Apr", "May","Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ][month];
return monthStr + " " + dayStr + ", " + yearStr;
};
// custom function to refresh a Bootstrap Tooltip (in case its anchor has moved)
// (I copied the Tooltip.prototype.show method for the important bits)
var refreshTooltip = function(t) {
var $tip = t.tip();
$tip.find('.tooltip-inner')[t.options.html ? 'html' : 'text'](t.getTitle());
var placement = typeof t.options.placement == 'function' ?
t.options.placement.call(t, $tip[0], t.$element[0]) :
t.options.placement;
var inside = /in/.test(placement);
var pos = t.getPosition(inside);
actualWidth = $tip[0].offsetWidth;
actualHeight = $tip[0].offsetHeight;
switch (inside ? placement.split(' ')[1] : placement) {
case 'bottom':
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2};
break;
case 'top':
tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2};
break;
case 'left':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth};
break;
case 'right':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width};
break;
}
$tip.offset(tp);
};
</script>
</body>
</html>