This repository was archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathweenote.js
More file actions
71 lines (52 loc) · 1.47 KB
/
weenote.js
File metadata and controls
71 lines (52 loc) · 1.47 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
onload = function() {
var body = document.body
var slides = {}
var slide
function fit(el) {
var style = el.style
var i = 1000
var top
var left
style.display = "inline"
style.fontSize = i + "px"
style.position = "absolute"
while (1) {
left = innerWidth - el.offsetWidth
top = innerHeight - el.offsetHeight
if (top > 0 && left > 0) break
style.fontSize = (i -= i * 0.05) + "px"
}
style.display = "block"
style.top = top / 2 + "px"
style.left = left / 2 + "px"
}
for (var el, count = 0; el = body.firstChild;) {
if (el.nodeType == 1) slides[++count] = el
body.removeChild(el)
}
body.appendChild(document.createComment(""))
!function sync() {
setTimeout(sync, 50)
var next = 0 | location.hash.match(/\d+/)
if (slide == next) return
next = Math.max(Math.min(count, next), 1)
next = slides[location.hash = slide = next]
body.replaceChild(next, body.firstChild)
fit(next)
}()
const FORWARD = 1
const BACKWARD = -1
const keyToSlideDirection = {
"ArrowRight": FORWARD, "ArrowLeft": BACKWARD,
"PageDown": FORWARD, "PageUp": BACKWARD
}
document.onkeydown = function(e) {
var i = slide + keyToSlideDirection[e.key]
if (i in slides) location.hash = i
}
document.ontouchstart = function(e) {
if (e.target.href) return
var i = slide + (e.touches[0].pageX > innerWidth / 2 ? 1 : -1)
if (i in slides) location.hash = i
}
}