-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (52 loc) · 1.69 KB
/
Copy pathindex.js
File metadata and controls
67 lines (52 loc) · 1.69 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
class EscapeHandler {
constructor (images = [], anchorFn = null, btnText = 'ESCAPE', exitText = 'EXIT') {
this.images = images;
this.anchorFn = anchorFn;
this.btnText = btnText;
this.exitText = exitText;
this.cover = document.createElement('div');
this.cover.classList.add('cover-wrapper');
const body = document.querySelector('body');
body.appendChild(this.cover);
this.inner = document.createElement('div');
this.inner.classList.add('cover-content');
this.appendAllImages();
this.appendExit();
this.cover.appendChild(this.inner);
}
trigger() {
const state = [...this.cover.classList].includes('visible');
if (state === true) {
this.cover.classList.remove('visible');
this.cover.scrollTop = 0;
} else {
this.cover.classList.add('visible');
this.cover.scrollTop = 0;
}
}
appendAllImages() {
this.images.forEach(image => this.appendImage(image));
}
appendImage(image) {
const imgWrapper = document.createElement('div');
const anchor = document.createElement('a');
if (this.anchorFn === null) {
anchor.setAttribute('href', image.location);
} else {
anchor.setAttribute('href', '#');
anchor.setAttribute('onclick', this.anchorFn(image));
}
const img = document.createElement('img');
img.setAttribute('src', image.file);
anchor.appendChild(img);
imgWrapper.appendChild(anchor);
this.inner.appendChild(imgWrapper);
}
appendExit() {
const exit = document.createElement('div');
exit.classList.add('exit-scramble');
exit.innerText = this.exitText;
exit.onclick = this.trigger.bind(this);
this.inner.appendChild(exit);
}
}