-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·237 lines (210 loc) · 6.71 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<html>
<head>
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" />
<title>On Css Animations</title>
<!-- <link href='http://fonts.googleapis.com/css?family=Istok+Web' rel='stylesheet' type='text/css'> -->
<link rel="stylesheet" href="css/presentation.css" type="text/css" media="screen" charset="utf-8">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
if (!window.jQuery) {
document.write('<script src="js/jquery.min.js"><\/script>');
}
</script>
<script type="text/javascript" src="js/showdown.js"></script>
</head>
<body tabindex="1">
<div class="for-screen">
<div class="bg"> </div>
<table style="width:100%;height:100%;border-collapse:collapse">
<tr valign=center>
<td>
<div class='centered'>
<em>Loading</em>
</div>
</td>
</tr>
</table>
<div class="slideCount">
<select tabindex="-1">
</select>
</div>
<div class="padding">
<!-- This padding need to hiding address bar automatically at iPhone/iPad/Android browser. -->
</div>
</div>
<div class="for-print">
<table class="content-holder template">
<tr valign=center>
<td>
<div class='centered'><h2>Foo</h2>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
<script>
var Present = { };
Present.slideRegEx = /<p>(?:!SLIDE|!)<\/p>/i;
Present.hashToSlideIndex = function () {
var matches = window.location.hash.match(/#(\d+)/);
if (matches == null) return 0;
return parseInt(matches[1]) - 1;
}
Present.currentSlide = Present.hashToSlideIndex();
Present.showSlide = function(slide) {
slide = Math.max(0, Math.min(slide, Present.slides.length - 1));
Present.currentSlide = slide;
$('.for-screen .centered').html(Present.slides[Present.currentSlide]);
$('.slideCount select').val(this.currentSlide);
window.location.hash = '#' + (Present.currentSlide + 1);
};
Present.nextSlide = function() {
if (Present.currentSlide < Present.slides.length-1) {
Present.showSlide(Present.currentSlide+1);
}
};
Present.prevSlide = function() {
if (Present.currentSlide > 0) {
Present.showSlide(Present.currentSlide-1);
}
};
Present.buildPrintPage = function () {
var forPrint = $('.for-print');
$('.content-holder:not(.template)', forPrint).remove();;
var template = $('.content-holder.template', forPrint);
$.each(Present.slides, function (_, slide) {
var holder = template.clone()
.appendTo(forPrint)
.removeClass('template');
$('.centered', holder).html(slide);
});
}
Present.buildSlideCounter = function () {
var $counter = $('.slideCount select');
var optionHtmls = [];
var numOfSlides = this.slides.length;
$.each(this.slides, function (i) {
optionHtmls.push('<option value="' + i + '">Slide ' + (i + 1) + ' of ' + numOfSlides + '</option>');
});
$counter.html(optionHtmls.join(''));
}
Present.reload = function() {
$.ajax({
url: 'presentation.md',
cache: false,
success: function(data) {
if (data.length>0) {
converter = new Showdown.converter();
var converted = converter.makeHtml(data);
Present.slides = converted.split(Present.slideRegEx);
console.log(Present.slides);
Present.buildSlideCounter();
Present.showSlide(Present.currentSlide);
// If beforeprint event not supported, build pages to printing now.
if (('onbeforeprint' in window) === false) Present.buildPrintPage();
}
}
});
};
Present.reload();
(function () {
var pageToJump = '';
$(document).keydown(function(e){
if (e.keyCode == 13) { // enter
if (pageToJump != '') {
Present.showSlide(parseInt(pageToJump) - 1);
pageToJump = '';
}
}
if (48 <= e.keyCode && e.keyCode <= 57) {
pageToJump += String.fromCharCode(e.keyCode);
}
else {
pageToJump = '';
}
if (e.keyCode == 37) {
Present.prevSlide();
return false;
}
if (e.keyCode == 39) {
Present.nextSlide();
return false;
}
if (e.keyCode == 32) { // space
Present.reload();
return false;
}
});
})();
// Build print page on demand.
$(window).bind('beforeprint', Present.buildPrintPage);
$(function () {
var startPos = null;
var isPointerTypeTouch = function (e) {
if ('pointerType' in e.originalEvent)
return (e.originalEvent.pointerType === e.originalEvent.MSPOINTER_TYPE_TOUCH);
else true;
};
var getPos = function (e) {
if ('touches' in e.originalEvent) {
var touches = e.originalEvent.touches;
if (touches.length < 1) return { x: 0, y: 0 };
return { x: touches[0].pageX, y: touches[0].pageY };
}
return { x: e.pageX, y: e.pageY };
};
var ontouchstart = function (e) {
if (isPointerTypeTouch(e) === false) return;
startPos = getPos(e);
}
var ontouchmove = function (e) {
if (startPos === null || isPointerTypeTouch(e) === false) return;
var pos = getPos(e);
var d = { x: startPos.x - pos.x, y: startPos.y - pos.y };
if (Math.abs(d.x) >=40) {
startPos = null;
$(this).trigger(d.x < 0 ? 'swiperight' : 'swipeleft');
return false;
}
}
var ontouchend = function (e) {
if (startPos === null || isPointerTypeTouch(e) === false) return;
startPos = null;
}
var hideaddressbar = function () {
setTimeout(function () { window.scrollTo(0, 1); }, 100);
};
$(document.body)
.bind({
'MSPointerDown': ontouchstart,
'MSPointerMove': ontouchmove,
'MSPointerUp': ontouchend,
'touchstart': ontouchstart,
'touchmove': ontouchmove,
'touchend': ontouchend,
'swiperight': function () {
Present.prevSlide();
hideaddressbar();
},
'swipeleft': function () {
Present.nextSlide();
hideaddressbar();
}
});
hideaddressbar();
$(window).bind('orientationchange', hideaddressbar);
});
// Go to page by hash of URL changed.
$(window).bind('hashchange', function () {
var slideIndex = Present.hashToSlideIndex();
if (Present.currentSlide != slideIndex)
Present.showSlide(slideIndex);
});
// Go to page by drop down list changed.
$('.slideCount select').change(function () {
Present.showSlide(parseInt($(this).val()));
setTimeout(function () { document.body.focus(); }, 0);
});
</script>