forked from chrishulbert/MarkdownPresenter
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Presenter.html
398 lines (364 loc) · 10.4 KB
/
Presenter.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<html>
<head>
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" />
<title>Markdown Presenter</title>
<style>
html, body {
margin:0;
border:0;
padding:0;
font-family: helvetica;
color: white;
overflow: hidden;
-ms-touch-action: none;
-moz-user-select:none;
}
div.centered {
margin:auto;
font-size:40px;
width:20em; /* So we get about 10 words per line */
}
.slideCount {
position: fixed;
bottom: 1em;
right: 2px;
height:1.5em;
width:8em;
overflow:hidden;
}
.slideProgress
{
background-color: green;
width: 100%;
min-height: 10px;
}
.slideCount select {
color:white;
background-color:#112;
border-color:#112;
border:none;
font-size:1em;
height:1.3em;
width:10em;
-webkit-appearance: none;
border-radius:0;
-webkit-border-radius: 0;
}
.padding {
height: 60px;
}
/* My styling here */
body,
.content-holder {
background: #223;
background: -webkit-gradient(linear, left top, left bottom, from(#334), to(#112));
background: -moz-linear-gradient(top, #334, #112);
text-shadow: #000 0 -2px 0;
}
.bg {
background-image: url(bg.jpg);
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
opacity:0.01;
z-index:-1;
}
code {
color: rgb(235, 174, 108);
}
.for-print .content-holder {
width: 100%;
height: 100%;
border-collapse: collapse;
}
.for-print .content-holder.template { display:none; }
@media screen {
.for-print { display:none; }
}
@media print {
.for-screen { display: none; }
}
@media only screen and (max-width: 768px) {
.centered {
-ms-zoom: 0.8;
zoom: 0.8;
}
}
@media only screen and (max-width: 480px) {
.centered {
-ms-zoom: 0.5;
zoom: 0.5;
}
}
@media only screen and (max-width: 320px) {
.centered {
-ms-zoom: 0.35;
zoom: 0.35;
}
}
/* End styling */
</style>
<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="jquery.min.js"><\/script>');
}
</script>
<script type="text/javascript" src="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 class="slideProgress"></div>
</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 = {
// Slide transition effects.
effects: {
// n: no effect.
n: {
pre: function (view, callback) { callback(); },
post: function (view) { }
},
// f: fade in/out.
f: {
pre: function (view, callback) { view.fadeOut('fast', callback); },
post: function (view) { view.fadeIn('fast'); }
}
},
currentDocument: '',
autoReloadTimerID: null
};
Present.currentEffect = Present.effects['n']; // Default slide transiton effect is nothing.
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;
var $view = $('.for-screen .centered');
this.currentEffect.pre($view, $.proxy(function () {
$view.html(this.slides[this.currentSlide]);
this.currentEffect.post($view);
}, this));
$('.slideCount select').val(this.currentSlide);
$('.slideProgress').css("width", (this.currentSlide + 1)/this.slides.length * 100 + "%");
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() {
Present.duringReloading = true;
$.ajax({
url: 'presentation.md',
cache: false,
dataType: 'text',
success: function(data) {
if (data.length>0 && Present.currentDocument != data) {
converter = new Showdown.converter();
var converted = converter.makeHtml(data);
Present.slides = converted.split('<p>!</p>');
Present.buildSlideCounter();
Present.showSlide(Present.currentSlide);
Present.currentDocument = data;
// If beforeprint event not supported, build pages to printing now.
if (('onbeforeprint' in window) === false) Present.buildPrintPage();
}
Present.duringReloading = false;
}
});
};
Present.reload();
Present.toggleAutoReload = function() {
if (Present.autoReloadTimerID == null) {
Present.autoReloadTimerID = setInterval(function() {
if (Present.duringReloading) return;
Present.reload();
}, 200);
}
else {
clearInterval(Present.autoReloadTimerID);
Present.autoReloadTimerID = null;
}
};
(function () {
var pageToJump = '';
var effectCmd = false;
$(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 = '';
}
// Detect key combination to change slide transition effect.
// ex) 'e','f' -> change effect to fade in/out.
if (e.keyCode == 'E'.charCodeAt(0)) effectCmd = true;
else if (effectCmd)
{
var effectName = String.fromCharCode(e.keyCode).toLowerCase();
var effect = Present.effects[effectName];
if (typeof (effect) !== 'undefined') Present.currentEffect = effect;
effectCmd = false;
}
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;
}
if (e.keyCode == 'A'.charCodeAt(0)) {
Present.toggleAutoReload();
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 == '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({
// IE10
'MSPointerDown': ontouchstart,
'MSPointerMove': ontouchmove,
'MSPointerUp': ontouchend,
// IE11+
'pointerdown': ontouchstart,
'pointermove': ontouchmove,
'pointerup': ontouchend,
// Webkit, Gecko
'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>