forked from christianhujer/XSlides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slides.js
275 lines (257 loc) · 8.92 KB
/
slides.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
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
const NORMAL = 1;
const BLANK = 2;
const BLACK = 3;
const WHITE = 4;
const HELP = 5;
currentSlide = 0;
blank = NORMAL;
commandlineEnabled = false;
/** Set to true if the mouse wheel is used on an overflown div.
* That way on an overflown div the mouse wheels first scroll the div before swapping the slides.
*/
nowheel = false;
/** Event handler for mouse wheel.
* @param e Event object.
*/
function mousewheel(e) {
if (!e) { e = window.event; }
if (nowheel) {
nowheel = false;
return;
}
if (e.wheelDeltaX || e.wheelDeltaY) {
/* Chrome supports two wheels, nice. */
if (e.wheelDeltaY > 0) { previousSlide(); }
if (0 > e.wheelDeltaY) { nextSlide(); }
if (e.wheelDeltaX > 0) { previousSlide(); }
if (0 > e.wheelDeltaX) { nextSlide(); }
return;
}
/* Opera and Internet Explorer support one wheel. */
if (e.wheelDelta > 0) { previousSlide(); }
if (0 > e.wheelDelta) { nextSlide(); }
/* No wheel support in Firefox. */
}
/** Eventhandler for wheel on div.
* @param e Event object.
*/
function divwheel(e) {
if (!e) { e = window.event; }
if (0 > e.wheelDelta)
if (e.currentTarget.scrollHeight > e.currentTarget.scrollTop + e.currentTarget.clientHeight)
nowheel = true;
if (e.wheelDelta > 0)
if (e.currentTarget.scrollTop > 0)
nowheel = true;
}
/** Event handler for mouse down event.
* @param e Event object.
*/
function mousedown(e) {
if (!e) e = window.event;
/*window.alert(e.button);*/
return false;
}
/** Event handler for mouse click event.
* @param e Event object.
*/
function click(e) {
if (!e) e = window.event;
/* Note: On IE, e.button is always 0 here - looks like a bug. */
switch (e.button) {
/*LMB*/case 0: nextSlide(); return false;
/*MMB*/case 1: previousSlide(); return false;
/*RMB*/case 2: /* TODO:2011-07-02:hujerc:3:Implement context menu. */; return false;
}
}
/** Event handler for the keydown event.
* @param e Event object.
*/
function keydown(e) {
if (!e) e = window.event;
var keyCode = e.keyCode;
if (commandlineEnabled) {
switch (keyCode) {
case 27: disableCommandline(); return; /* esc */
/*default: window.alert(keyCode);*/
}
} else {
switch (keyCode) {
case 8: previousSlide(); return false; /* Backspace */
case 33: previousSlide(); return; /* PowerPoint: page up */
case 34: nextSlide(); return; /* PowerPoint: page down */
case 35: lastSlide(); return; /* PowerPoint: end */
case 36: firstSlide(); return; /* PowerPoint: pos1 */
case 37: if (!commandlineEnabled) previousSlide(); return; /* PowerPoint: left */
case 38: if (!commandlineEnabled) previousSlide(); return; /* PowerPoint: up */
case 39: if (!commandlineEnabled) nextSlide(); return; /* PowerPoint: right */
case 40: if (!commandlineEnabled) nextSlide(); return; /* PowerPoint: down */
case 112: help(); return false; /* PowerPoint: vi: F1 */
case 116: enableCommandline(); return false; /* F5 */
/*default: window.alert(keyCode);*/
}
}
}
/** Toggles blanking the slides / screen. */
function toggleBlank(newBlank) {
document.getElementById('screenWhite').style.display = 'none';
document.getElementById('screenBlack').style.display = 'none';
document.getElementById('slide_help').style.display = 'none';
if (newBlank == blank) {
blank = NORMAL;
activateSlide(currentSlide);
return;
}
if (newBlank == BLACK) {
document.getElementById('screenBlack').style.display = 'block';
} else if (newBlank == WHITE) {
document.getElementById('screenWhite').style.display = 'block';
} else if (newBlank == BLANK) {
document.getElementById('slide_' + currentSlide).style.display = 'none';
document.getElementById('currentSlide').innerHTML = currentSlide + ' (blank)';
} else if (newBlank == HELP) {
document.getElementById('slide_' + currentSlide).style.display = 'none';
document.getElementById('slide_help').style.display = 'block';
document.getElementById('currentSlide').innerHTML = currentSlide + ' (help)';
}
blank = newBlank;
}
/** Event handler for the keypress event.
* @param e Event object.
*/
function keypress(e) {
if (!e) {
e = window.event;
}
var keyCode = e.keyCode;
if (commandlineEnabled) {
switch (keyCode) {
case 58: retval = commandlineEnabled; enableCommandline(); return retval; /* vi: : */
/*default: window.alert(keyCode);*/
}
} else {
switch (keyCode) {
case 104: previousSlide(); return; /* vi: h */
case 106: nextSlide(); return; /* vi: j */
case 107: previousSlide(); return; /* vi: k */
case 108: nextSlide(); return; /* vi: l */
case 110: nextSlide(); return; /* PowerPoint: n */
case 112: previousSlide(); return; /* PowerPoint: p */
case 32: nextSlide(); return; /* PowerPoint: <SP> */
case 13: nextSlide(); return; /* PowerPoint: <CR> */
case 10: nextSlide(); return; /* PowerPoint: <LF> */
case 71: lastSlide(); return; /* vi: G */
case 103: firstSlide(); return; /* vi: g */
case 58: retval = commandlineEnabled; enableCommandline(); return retval; /* vi: : */
case 46: if (!commandlineEnabled) toggleBlank(BLANK); return; /* PowerPoint: . */
case 98: if (!commandlineEnabled) toggleBlank(BLACK); return; /* PowerPoint: b */
case 119: if (!commandlineEnabled) toggleBlank(WHITE); return; /* PowerPoint: w */
case 63: help(); return; /* ? */
/*default: window.alert(keyCode);*/
}
}
}
/** Disables the commandline. */
function disableCommandline() {
document.getElementById('command').blur();
document.getElementById('commandline').style.display = 'none';
document.getElementById('command').value = "";
commandlineEnabled = false;
}
/** Enables the commandline. */
function enableCommandline() {
document.getElementById('commandline').style.display = 'block';
document.getElementById('command').focus();
commandlineEnabled = true;
}
/** Activates the specified slide.
* @param newSlide Slide to activate (number).
*/
function activateSlide(newSlide) {
if (blank != NORMAL) {
return;
}
if (newSlide > LAST_SLIDE) {
newSlide = LAST_SLIDE;
}
if (0 > newSlide) {
newSlide = 0;
}
document.getElementById('slide_' + currentSlide).style.display = 'none';
document.getElementById('slide_' + newSlide).style.display = 'block';
currentSlide = newSlide;
document.getElementById('currentSlide').innerHTML = currentSlide;
if (document.getElementById('slide_' + currentSlide + "_logo")) {
document.getElementById('logo').src = document.getElementById('slide_' + currentSlide + "_logo").src;
} else {
document.getElementById('logo').src = logoSrc;
}
}
/** Activates the first slide. */
function firstSlide() {
activateSlide(0);
}
/** Activates the last slide. */
function lastSlide() {
activateSlide(LAST_SLIDE);
}
/** Activates the next slide. */
function nextSlide() {
activateSlide(currentSlide + 1);
}
/** Activates the previous slide. */
function previousSlide() {
activateSlide(currentSlide - 1);
}
/** Processes a command. */
function processCommand() {
command = document.getElementById('command').value;
command = command.replace(/^:/, "");
if (command.match(/^\d+$/)) {
activateSlide(Number(command));
} else if (command.match(/^(\+|-)\d+$/)) {
activateSlide(currentSlide + Number(command));
} else if (command.match(/^e$/)) {
window.location.reload();
} else if (command.match(/^n(ext)?$/)) {
nextSlide();
} else if (command.match(/^prev(ious)?$/)) {
previousSlide();
} else if (command.match(/^fir(st)?$/)) {
firstSlide();
} else if (command.match(/^la(st)?$/)) {
lastSlide();
}
disableCommandline();
}
/** Display help. */
function help() {
toggleBlank(HELP);
}
/** Start handler. */
function begin() {
if (document.getElementById('logo')) {
logoSrc = document.getElementById('logo').src;
}
divs = document.getElementsByTagName('div');
for (i = 0; divs.length > i; i++) {
el = divs.item(i);
el.onmousewheel = divwheel;
}
activateSlide(0);
}
function enableNavigator() {
/* TODO:2011-07-02:hujerc:3:Implement enable navigator. */
document.body.style.cursor = 'crosshair';
/*document.getElementById('navBar').style.display = 'block';*/
}
function disableNavigator() {
/* TODO:2011-07-02:hujerc:3:Implement disable navigator. */
document.body.style.cursor = 'default';
/*document.getElementById('navBar').style.display = 'none';*/
}
document.onkeydown = keydown;
document.onkeypress = keypress;
document.onclick = click;
document.onmousedown = mousedown;
document.onmousewheel = mousewheel;