Repository navigation
Expand file tree
/
Copy pathcontrols.js
More file actions
96 lines (77 loc) · 1.74 KB
/
Copy pathcontrols.js
File metadata and controls
96 lines (77 loc) · 1.74 KB
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
var allSlides = new Array();
var currentPage = 0;
var urlStack = new Array();
$(document).ready(function() {
$.getJSON("../order.json", function (data) {
var currentUrl = window.location.pathname;
var currentFilename = currentUrl.substring(currentUrl.lastIndexOf('/') +1);
currentFilename = currentFilename.slice(0,-5);
$.each(data, function (counter, page) {
if(page.page == currentFilename)
{
currentPage = counter
}
allSlides[counter] = page.page;
});
console.log(allSlides);
});
});
function loadPage(url, history_search)
{
console.log(currentPage);
if(!history_search)
{
var stateObj = {url: url};
history.pushState(stateObj, 'page', url);
} else {
var stackPosition = $.inArray(url, urlStack);
var direction;
if(currentPage > stackPosition)
{
direction = 'back';
currentPage = currentPage -1;
}
else {
direction = 'forward';
currentPage = currentPage + 1;
}
}
$('body').hide();
$('body').load(url , null, function( data ){
$('body').show('fast');
});
}
function slideBack()
{
if(currentPage - 1 in allSlides)
{
currentPage--;
var url = '../' + allSlides[currentPage] + '/' + allSlides[currentPage] + '.html';
loadPage(url);
}
else
{
console.log("ERROR, you are at start of presentation.");
}
}
function slideForward()
{
if(currentPage + 1 in allSlides)
{
currentPage++;
var url = '../' + allSlides[currentPage] + '/' + allSlides[currentPage] + '.html';
loadPage(url);
}
else
{
console.log("ERROR, you have reached the end of the presentation");
}
}
$(document.documentElement).keyup(function (event) {
// handle cursor keys
if (event.keyCode == 37) {
slideBack();
} else if (event.keyCode == 39) {
slideForward();
}
});