-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpresentation.js
120 lines (93 loc) · 2 KB
/
presentation.js
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
function get_max_page () {
return $(".folie").length;
}
function set_page_footer () {
var max_page = get_max_page();
$("#max_page_nr").html(max_page);
$("#page_nr").html(get_current_page() + 1);
}
function get_current_page() {
var page_id = null;
$(".folie").each(function (i, e) {
if($(e).is(":visible")) {
page_id = i;
}
});
return page_id;
}
function show_folie_nr(i) {
$(".folie").hide();
if(i < 0) {
i = 0;
}
if(i >= get_max_page()) {
end_presentation();
return;
}
if(i === undefined) {
return;
}
if($($(".folie")[i]).length) {
$($(".folie")[i]).show();
} else {
console.error(`Invalid i for show_folie_nr: ${i}`);
}
}
function show_prev_folie() {
var current = get_current_page();
show_folie_nr(current - 1);
set_page_footer();
}
function show_next_folie() {
var current = get_current_page();
show_folie_nr(current + 1);
set_page_footer();
}
function handleKeyPress(event) {
switch (event.key) {
case "ArrowRight":
show_next_folie();
break;
case "ArrowLeft":
show_prev_folie();
break;
default:
break;
}
}
function handleMouseClick(event) {
if(event.target.nodeName != "A") {
show_next_folie();
}
}
function handleMouseWheel(event) {
// Determine the direction of the scroll
var delta = event.deltaY;
if (delta > 0) {
show_next_folie();
} else if (delta < 0) {
show_prev_folie();
}
}
var added_event_listeners_for_presentation = false;
function start_presentation(start_nr=0) {
$("#mainsite").hide();
$("#status_bar").hide();
$("#presentation").show();
if(!added_event_listeners_for_presentation) {
document.addEventListener("keydown", handleKeyPress);
document.addEventListener("click", handleMouseClick);
document.addEventListener("wheel", handleMouseWheel);
added_event_listeners_for_presentation = true;
}
show_folie_nr(start_nr);
set_page_footer();
}
function end_presentation(goto_page) {
$("#mainsite").show();
$("#status_bar").show();
$("#presentation").hide();
if(goto_page !== null) {
show_folie_nr(goto_page);
}
}