-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslideshow.js.precoffee
169 lines (158 loc) · 3.83 KB
/
slideshow.js.precoffee
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
var slideCount = 0; //index of array for <section class="slide">
var speakerNotesShown = false;
var helpMenuShown = false;
var controlsShown = false;
//called when page is loaded, looks for #bookmark in url and makes sure the correct slide is shown
function load()
{
console.log(window.location.hash);
elems = getElementsByClass("slide", null, "section");
//if the hash tag is set, change the slideCount number
if (window.location.hash != "") {
for (i = 0; i < elems.length; i++) {
if (elems[i].id == window.location.hash.slice(1)) {
slideCount = i;
}
}
}
for (i = 0; i < elems.length; i++)
{
if (i == slideCount)
{
elems[i].style.display = "inline";
elems[i].style.opacity = 1;
} else {
elems[i].style.display = "none";
elems[i].style.opacity = 0.0;
}
}
}
//will handle keypresses for slide show
function slideControl(event)
{
switch(event.which)
{
//both of these are 'n' & 'N', respectively
case 110:
case 78:
speakerNotes();
break;
//right keyboard arrow
case 37:
previousSlide();
break;
//left keyboard arrow
case 39:
nextSlide();
break;
//'h' & 'H'
case 72:
helpMenu();
break;
//'c' & 'C'
case 67:
controlsMenu();
break;
default:
//alert(event.which);
}
}
//will move to next slide
function nextSlide()
{
elems = getElementsByClass("slide", null, "section");
elems[slideCount].style.display = "none";
elems[slideCount].style.opacity = 0;
//make sure it doesn't go out of bounds
if (slideCount < (elems.length - 1))
{
slideCount++;
}
window.history.pushState("string 1", "title", "/slideshow/index.htm#" + elems[slideCount].id);
elems[slideCount].style.display = "inline";
elems[slideCount].style.opacity = 1;
elems[slideCount].style.position = "relative";
elems[slideCount].style.left = "0px";
}
//will move to previous slide
function previousSlide()
{
elems = getElementsByClass("slide", null, "section");
elems[slideCount].style.display = "none";
elems[slideCount].style.opacity = 0;
//make sure it doesn't go out of bounds
if (slideCount > 0)
{
slideCount--;
}
window.history.pushState("string 1", "title", "/slideshow/index.htm#" + elems[slideCount].id);
elems[slideCount].style.display = "inline";
elems[slideCount].style.opacity = 1;
elems[slideCount].style.position = "relative";
elems[slideCount].style.left = "0px";
}
//will toggle speaker notes
function speakerNotes()
{
elems = getElementsByClass("note", null, "aside");
if (speakerNotesShown)
{
//change CSS so that speaker notes are hidden
for (i = 0; i < elems.length; i++)
{
elems[i].style.display = "none";
}
} else {
//change CSS so that speaker notes are shown
for (i = 0; i < elems.length; i++)
{
elems[i].style.display = "inline";
}
}
speakerNotesShown = !speakerNotesShown;
}
//will toggle help menu
function helpMenu()
{
elems = getElementsByClass("help", null, "aside");
if (helpMenuShown)
{
//change CSS so that help menu is hidden
elems[0].style.display = "none";
} else {
//change CSS so that help menu is shown
elems[0].style.display = "block";
}
helpMenuShown = !helpMenuShown;
}
//will toggle help menu
function controlsMenu()
{
elems = getElementsByClass("controls", null, "aside");
if (controlsShown)
{
//change CSS so that help menu is hidden
elems[0].style.display = "none";
} else {
//change CSS so that help menu is shown
elems[0].style.display = "block";
}
controlsShown = !controlsShown;
}
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}