-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathioslide_modifications.html
More file actions
129 lines (104 loc) · 2.94 KB
/
ioslide_modifications.html
File metadata and controls
129 lines (104 loc) · 2.94 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
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
<!-- The code below will add some custom formatting and keyboard navigation
to ioslides. Insert the code just before the closing body tag (</tbody>) -->
<style type="text/css">
article {
width: 100%;
height: 100%;
overflow-y: auto;
margin-left: -60px;
padding-left: 60px;
padding-bottom: 160px;
box-sizing: border-box;
}
article pre.prettyprint.lang-r:before{
content: '';
display: block;
height: 100%;
width: 60px;
position: absolute;
top: 0px;
left: 0px;
background-color: #e6e6e6;
}
p + pre.prettyprint.lang-r, pre + pre.prettyprint.lang-r {
margin-top: 80px;
}
@media print {
slides {
height: auto !important;
}
slide {
page-break-inside: avoid;
}
article p, article pre {
page-break-inside: avoid;
}
}
</style>
<script>
function slideVertical(event){
// handle only pressing of y (down) or a (up)
if (event.keyCode == 89 || event.keyCode == 65) {
var direction = null;
var codeBlock = null;
// set the direction of traversal
if (event.keyCode == 89) {
direction = "down";
} else {
direction = "up";
}
// get the current article
var article = document.querySelector('slide.current article');
// select all code blocks in the article
var allBlocks = document.querySelectorAll('slide.current article pre.prettyprint');
// jump slides if not code blocks are present
if (allBlocks.length === 0) {
if (direction === "down") {
slidedeck.nextSlide();
} else {
slidedeck.prevSlide();
}
return;
}
// get the index of the currently active elements
currentIndex = Array.prototype.reduce.call(allBlocks, function(previousValue, currentItem, index) {
if (currentItem.className.includes('active-item')) {
return index;
}
return previousValue;
}, null);
// remove the active-item class from all codeblocks
Array.prototype.map.call(allBlocks, function(item){
item.className = item.className.replace(/\bactive-item\b/, '').trim();
});
// set the current index to zero (first element) if no active element was found
if (currentIndex === null) {
currentIndex = 0;
}
// get the next/previous code block item
if (direction === "down") {
if (currentIndex < allBlocks.length - 1 ) {
codeBlock = allBlocks[currentIndex + 1];
} else {
codeBlock = allBlocks[currentIndex];
slidedeck.nextSlide();
}
} else {
if (currentIndex >= 1) {
codeBlock = allBlocks[currentIndex - 1];
} else {
codeBock = allBlocks[0];
slidedeck.prevSlide();
}
}
// if we are not at the last codeBlock
if (codeBlock !== null) {
// add the class active item to the code-block
codeBlock.className = codeBlock.className + " active-item";
// scroll/jump to the respective codeBlock
article.scrollTop = codeBlock.offsetTop - article.offsetTop;
}
}
}
document.addEventListener('keydown', slideVertical, true);
</script>