-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol-per-slide-progress.js
154 lines (125 loc) · 4.54 KB
/
symbol-per-slide-progress.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
/**
* reveal.js symbol per slide progress plugin
*
* A plugin which shows every slide as single symbol and the symbol of the current active slide in a different color.
*
* Demo https://naamor.github.io/reveal.js-symbol-per-slide-progress/
*
* MIT License
* Copyright (c) 2018 Roman Stocker
*/
var RevealSymbolPerSlideProgress = window.SymbolPerSlideProgress || (function () {
const VALID_POSITIONS = ["left", "right"];
const VALID_ALIGNS = ["vertical", "horizontal"];
// Set all option defaults
var options = Reveal.getConfig().symbolperslideprogress || {};
var path = options.path || scriptPath() || "plugin/symbol-per-slide-progress/";
if (!path.endsWith('/')) {
path += '/';
}
var position = getStringOption(options.position, VALID_POSITIONS) || "left";
var align = getStringOption(options.align, VALID_ALIGNS) || "vertical";
var symbolColor = options.symbolColor || getColor(".reveal");
var listItemActiveColor = options.symbolActiveColor || getColor(".controls");
loadResource(path + "symbol-per-slide-progress.css", "stylesheet");
initialize();
function initialize() {
var reveal = document.querySelector(".reveal");
var div = document.createElement("div");
div.className = "navigation " + position;
var ul = document.createElement("ul");
ul.className = "navigation-list";
updateNavigation(ul);
Reveal.addEventListener("slidechanged", function () {
updateNavigation(ul);
});
div.appendChild(ul);
reveal.appendChild(div);
}
// Check input if it is valid and return it
function getStringOption(option, VALID_ELEMENTS) {
if (typeof option === "string" && VALID_ELEMENTS.includes(option.toLowerCase())) {
return option.toLowerCase();
}
}
// Get a color of the theme
function getColor(selectorValue) {
var selector = document.querySelector(selectorValue),
style = window.getComputedStyle(selector),
color = style.getPropertyValue("color");
return color;
}
function updateNavigation(ul) {
var totalSlides = Reveal.getTotalSlides();
// Reset all child element
while (ul.firstChild) {
ul.removeChild(ul.firstChild);
}
for (counter = 1; counter <= totalSlides; counter++) {
var li = document.createElement("li");
li.className = getClassName();
if (Reveal.getSlidePastCount() + 1 === counter) {
li.classList.add("active");
li.style.color = listItemActiveColor;
} else {
li.style.color = symbolColor;
}
ul.appendChild(li);
}
};
function getClassName() {
if (align === "horizontal") {
switch (position) {
case "right":
return "navigation-list-element horizontal-right";
case "left":
default:
return "navigation-list-element horizontal-left";
}
}
return "navigation-list-element";
}
// Modified from math plugin
function loadResource(url, type, callback) {
var head = document.querySelector("head");
var resource;
if (type === "script") {
resource = document.createElement("script");
resource.type = "text/javascript";
resource.src = url;
} else if (type === "stylesheet") {
resource = document.createElement("link");
resource.rel = "stylesheet";
resource.href = url;
}
// Wrapper for callback to make sure it only fires once
var finish = function () {
if (typeof callback === "function") {
callback.call();
callback = null;
}
};
resource.onload = finish;
// IE
resource.onreadystatechange = function () {
if (this.readyState === "loaded") {
finish();
}
};
// Normal browsers
head.appendChild(resource);
}
function scriptPath() {
// obtain plugin path from the script element
var path;
if (document.currentScript) {
path = document.currentScript.src.slice(0, -28);
} else {
var sel = document.querySelector('script[src$="symbol-per-slide-progress.js"]');
if (sel) {
path = sel.src.slice(0, -28);
}
}
return path;
}
})();