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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/* This work is licensed under Creative Commons GNU LGPL License.
License: http://creativecommons.org/licenses/LGPL/2.1/
Author: Stefan Goessner/2005-2006
Web: http://goessner.net/
*/
var Slideous = {
version: 1.0,
// == user customisable ===
clickables: { a: true, button: true, img: true, input: true, object: true, textarea: true, select: true, option: true },
incrementables: { blockquote: { filter: "self, parent" },
dd: { filter: "self, parent" },
dt: { filter: "self, parent" },
h2: { filter: "self, parent" },
h3: { filter: "self, parent" },
h4: { filter: "self, parent" },
h5: { filter: "self, parent" },
h6: { filter: "self, parent" },
li: { filter: "self, parent" },
p: { filter: "self" },
pre: { filter: "self" },
img: { filter: "self, parent" },
object: { filter: "self, parent" },
table: { filter: "self, parent" },
td: { filter: "self, parent" },
th: { filter: "self, parent" },
tr: { filter: "parent, grandparent" }
},
autoincrementables: { ol: true, ul: true, dl: true },
autoincrement: false,
statusbar: true,
navbuttons: { incfontbutton: function(){Slideous.changefontsize(+Slideous.fontdelta);},
decfontbutton: function(){Slideous.changefontsize(-Slideous.fontdelta);},
contentbutton: function(){Slideous.gotoslide(Slideous.tocidx(), true, true);},
homebutton: function(){Slideous.gotoslide(1, true, true);},
prevslidebutton: function(){Slideous.previous(false);},
previtembutton: function(){Slideous.previous(true);},
nextitembutton: function(){Slideous.next(true);},
nextslidebutton: function(){Slideous.next(false);},
endbutton: function(){Slideous.gotoslide(Slideous.count,true,true);} },
fontsize: 125, // in percent, corresponding to body.font-size in css file
fontdelta: 5, // increase/decrease fontsize by this value
mousesensitive: true,
tocidx: 0,
tocitems: { toc: "<li><a href=\"#s{\$slideidx}\">{\$slidetitle}</a></li>",
tocbox: "<option value=\"#s{\$slideidx}\" title=\"{\$slidetitle}\">{\$slidetitle}</option>" },
keydown: function(evt) {
evt = evt || window.event;
var key = evt.keyCode || evt.which;
if (key && !evt.ctrlKey && !evt.altKey) {
switch (key) {
case 33: // page up ... previous slide
Slideous.previous(false); evt.cancel = !Slideous.showall; break;
case 37: // left arrow ... previous item
Slideous.previous(true); evt.cancel = !Slideous.showall; break;
case 32: // space bar
case 39: // right arrow
Slideous.next(true); evt.cancel = !Slideous.showall; break;
case 13: // carriage return ... next slide
case 34: // page down
Slideous.next(false); evt.cancel = !Slideous.showall; break;
case 35: // end ... last slide (not recognised by opera)
Slideous.gotoslide(Slideous.count, true, true); evt.cancel = !Slideous.showall; break;
case 36: // home ... first slide (not recognised by opera)
Slideous.gotoslide(1, true, true); evt.cancel = !Slideous.showall; break;
case 65: // A ... show All
case 80: // P ... Print mode
Slideous.toggleshowall(!Slideous.showall); evt.cancel = true; break;
case 67: // C ... goto contents
Slideous.gotoslide(Slideous.tocidx, true, true); evt.cancel = true; break;
case 77: // M ... toggle mouse sensitivity
Slideous.mousenavigation(Slideous.mousesensitive = !Slideous.mousesensitive); evt.cancel = true; break;
case 83: // S ... toggle statusbar
Slideous.togglestatusbar(); evt.cancel = true; break;
case 61: // + ... increase fontsize
case 107:
Slideous.changefontsize(+Slideous.fontdelta); evt.cancel = true; break;
case 109: // - ... decrease fontsize
Slideous.changefontsize(-Slideous.fontdelta); evt.cancel = true; break;
default: break;
}
if (evt.cancel) evt.returnValue = false;
}
return !evt.cancel;
},
// == program logic ===
count: 0, // # of slides ..
curidx: 0, // current slide index ..
mousedownpos: null, // last mouse down position ..
contentselected: false, // indicates content selection ..
showall: true,
init: function() {
Slideous.curidx = 1;
Slideous.importproperties();
Slideous.registerslides();
document.body.innerHTML = Slideous.injectproperties(document.body.innerHTML);
Slideous.buildtocs();
Slideous.registeranchors();
Slideous.toggleshowall(false);
Slideous.updatestatus();
document.body.style.fontSize = Slideous.fontsize+"%";
document.getElementById("s1").style.display = "block";
document.onkeydown = Slideous.keydown;
Slideous.mousenavigation(Slideous.mousesensitive);
Slideous.registerbuttons();
if (window.location.hash)
Slideous.gotoslide(window.location.hash.substr(2), true, true);
},
registerslides: function() {
var div = document.getElementsByTagName("div");
Slideous.count = 0;
for (var i in div)
if (Slideous.hasclass(div[i], "slide"))
div[i].setAttribute("id", "s"+(++Slideous.count));
},
registeranchors: function() {
var a = document.getElementsByTagName("a"),
loc = (window.location.hostname+window.location.pathname).replace(/\\/g, "/");
for (var i in a) {
if (a[i].href && a[i].href.indexOf(loc) >= 0 && a[i].href.lastIndexOf("#") >= 0) {
a[i].href = "javascript:Slideous.gotoslide(" + a[i].href.substr(a[i].href.lastIndexOf("#")+2)+",true,true)";
}
}
},
registerbuttons: function() {
var button;
for (var b in Slideous.navbuttons)
if (button = document.getElementById(b))
button.onclick = Slideous.navbuttons[b];
},
importproperties: function() { // from html meta section ..
var meta = document.getElementsByTagName("meta"), elem;
for (var i in meta)
if (meta[i].attributes && meta[i].attributes["name"] && meta[i].attributes["name"].value in Slideous)
switch (typeof(Slideous[meta[i].attributes["name"].value])) {
case "number": Slideous[meta[i].attributes["name"].value] = parseInt(meta[i].attributes["content"].value); break;
case "boolean": Slideous[meta[i].attributes["name"].value] = meta[i].attributes["content"].value == "true" ? true : false; break;
default: Slideous[meta[i].attributes["name"].value] = meta[i].attributes["content"].value; break;
}
},
injectproperties: function(str) {
var meta = document.getElementsByTagName("meta"), elem;
for (var i in meta) {
if (meta[i].attributes && meta[i].attributes["name"])
str = str.replace(new RegExp("{\\$"+meta[i].attributes["name"].value+"}","g"), meta[i].attributes["content"].value);
}
return str = str.replace(/{\$generator}/g, "Slideous")
.replace(/{\$version}/g, Slideous.version)
.replace(/{\$title}/g, document.title)
.replace(/{\$slidecount}/g, Slideous.count);
},
buildtocs: function() {
var toc = document.getElementById("toc"), list = "",
tocbox = document.getElementById("tocbox");
if (toc) {
for (var i=0; i<Slideous.count; i++)
list += Slideous.tocitems.toc.replace(/{\$slideidx}/g, i+1).replace(/{\$slidetitle}/, document.getElementById("s"+(i+1)).getElementsByTagName("h1")[0].innerHTML);
toc.innerHTML = list;
while (toc && !Slideous.hasclass(toc, "slide")) toc = toc.parentNode;
if (toc) Slideous.tocidx = toc.getAttribute("id").substr(1);
}
if (tocbox) {
tocbox.innerHTML = "";
for (var i=0; i<Slideous.count; i++)
tocbox.options[tocbox.length] = new Option((i+1)+". "+document.getElementById("s"+(i+1)).getElementsByTagName("h1")[0].innerHTML, "#s"+(i+1));
tocbox.onchange = function() { Slideous.gotoslide(this.selectedIndex+1, true, true); };
}
},
next: function(deep) {
if (!Slideous.showall) {
var slide = document.getElementById("s"+Slideous.curidx),
item = Slideous.firstitem(slide, Slideous.isitemhidden);
if (deep) { // next item
if (item)
Slideous.displayitem(item, true);
else
Slideous.gotoslide(Slideous.curidx+1, false, false);
}
else if (item) // complete slide ..
while (item = Slideous.firstitem(slide, Slideous.isitemhidden))
Slideous.displayitem(item, true);
else // next slide
Slideous.gotoslide(Slideous.curidx+1, true, false);
Slideous.updatestatus();
}
},
previous: function(deep) {
if (!Slideous.showall) {
var slide = document.getElementById("s"+Slideous.curidx);
if (deep) {
var item = Slideous.lastitem(slide, Slideous.isitemvisible);
if (item)
Slideous.displayitem(item, false);
else
Slideous.gotoslide(Slideous.curidx-1, true, false);
}
else
Slideous.gotoslide(Slideous.curidx-1, true, false);
Slideous.updatestatus();
}
},
gotoslide: function(i, showitems, updatestatus) {
if (!Slideous.showall && i > 0 && i <= Slideous.count && i != Slideous.curidx) {
document.getElementById("s"+Slideous.curidx).style.display = "none";
var slide = document.getElementById("s"+(Slideous.curidx=i)), item;
while (item = Slideous.firstitem(slide, showitems ? Slideous.isitemhidden : Slideous.isitemvisible))
Slideous.displayitem(item, showitems);
slide.style.display = "block";
if (updatestatus)
Slideous.updatestatus();
}
},
firstitem: function(root, filter) {
var found = filter(root);
for (var node=root.firstChild; node!=null && !found; node = node.nextSibling)
found = Slideous.firstitem(node, filter);
return found;
},
lastitem: function(root, filter) {
var found = null;
for (var node=root.lastChild; node!=null && !found; node = node.previousSibling)
found = Slideous.lastitem(node, filter);
return found || filter(root);
},
isitem: function(node, visible) {
var nodename;
return node && node.nodeType == 1 // elements only ..
&& (nodename=node.nodeName.toLowerCase()) in Slideous.incrementables
&& ( Slideous.incrementables[nodename].filter.match("\\bself\\b") && (Slideous.hasclass(node, "incremental") || (Slideous.autoincrement && nodename in Slideous.autoincrementables))
|| Slideous.incrementables[nodename].filter.match("\\bparent\\b") && (Slideous.hasclass(node.parentNode, "incremental") || (Slideous.autoincrement && node.parentNode.nodeName.toLowerCase() in Slideous.autoincrementables))
|| Slideous.incrementables[nodename].filter.match("\\bgrandparent\\b") && (Slideous.hasclass(node.parentNode.parentNode, "incremental") || (Slideous.autoincrement && node.parentNode.parentNode.nodeName.toLowerCase() in Slideous.autoincrementables))
)
&& (visible ? (node.style.visibility != "hidden")
: (node.style.visibility == "hidden"))
? node : null;
},
isitemvisible: function(node) { return Slideous.isitem(node, true); },
isitemhidden: function(node) { return Slideous.isitem(node, false); },
displayitem: function(item, show) {
if (item) item.style.visibility = (show ? "visible" : "hidden");
},
updatestatus: function() {
if (Slideous.statusbar) {
var eos = document.getElementById("eos"),
idx = document.getElementById("slideidx"),
tocbox = document.getElementById("tocbox");
if (eos)
eos.style.visibility = Slideous.firstitem(document.getElementById("s"+Slideous.curidx), Slideous.isitemhidden) != null
? "visible" : "hidden";
if (idx)
idx.innerHTML = Slideous.curidx;
if (tocbox)
tocbox.selectedIndex = Slideous.curidx-1;
}
},
changefontsize: function(delta) {
document.body.style.fontSize = (Slideous.fontsize+=delta)+"%";
},
togglestatusbar: function() {
document.getElementById("statusbar").style.display = (Slideous.statusbar = !Slideous.statusbar) ? "block" : "none";
},
toggleshowall: function(showall) {
var slide, item;
for (var i=0; i<Slideous.count; i++) {
slide = document.getElementById("s"+(i+1));
slide.style.display = showall ? "block" : "none";
while (item = Slideous.firstitem(slide, showall ? Slideous.isitemhidden : Slideous.isitemvisible))
Slideous.displayitem(item, showall);
var divs = slide.getElementsByTagName("div");
for (var j in divs)
if (Slideous.hasclass(divs[j], "handout"))
divs[j].style.display = showall ? "block" : "none";
}
if (!showall)
document.getElementById("s"+Slideous.curidx).style.display = "block";
if (Slideous.statusbar)
document.getElementById("statusbar").style.display = showall ? "none" : "block";
Slideous.showall = showall;
},
hasclass: function(elem, classname) {
var classattr = null;
return (classattr=(elem.attributes && elem.attributes["class"]))
&& classattr.nodeValue.match("\\b"+classname+"\\b");
},
selectedcontent: function() {
return window.getSelection ? window.getSelection().toString()
: document.getSelection ? document.getSelection()
: document.selection ? document.selection.createRange().text
: "";
},
mousenavigation: function(on) {
if (on) {
document.onmousedown = Slideous.mousedown;
document.onmouseup = Slideous.mouseup;
}
else
document.onmousedown = document.onmouseup = null;
},
mousepos: function(e) {
return e.pageX ? {x: e.pageX, y: e.pageY}
: {x: e.x+document.body.scrollLeft, y: e.y+document.body.scrollTop};
},
mousedown: function(evt) {
evt = evt||window.event;
Slideous.mousedownpos = Slideous.mousepos(evt);
Slideous.contentselected = !!Slideous.selectedcontent() || ((evt.target || evt.srcElement).nodeName.toLowerCase() in Slideous.clickables);
return true;
},
mouseup: function(evt) {
evt = evt||window.event;
var pos = Slideous.mousepos(evt);
if (pos.x == Slideous.mousedownpos.x && pos.y == Slideous.mousedownpos.y && !Slideous.contentselected) {
Slideous.next(true);
return evt.returnValue = !(evt.cancel = true);
}
return false;
}
};
window.onload = Slideous.init;
|