blob: 0286a82a4fda2f17365496b436962cf8e64b331a (
plain)
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
|
/**
* @author Victor Häggqvist
* @since 2016-01-16
*/
export class Captions {
constructor() {
this.element = document.createElement('div');
this.element.id = 'imagelightbox-caption';
//this.element.innerHTML = 'Close';
}
register(lightbox) {
this.lightbox = lightbox;
lightbox.addOnLoadStartListener(this.hideCaption.bind(this));
lightbox.addOnLoadEndListener(this.showCaption.bind(this));
lightbox.addOnEndListener(this.hideCaption.bind(this));
}
showCaption() {
let img = this.lightbox.target.querySelector('img');
if (img === null) return;
let caption = img.getAttribute('alt');
if (caption !== null && caption.length > 0) {
this.element.innerHTML = img.alt;
document.body.appendChild(this.element);
}
}
hideCaption() {
try {
document.body.removeChild(this.element);
} catch (e) {}
}
}
|