summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2016-01-15 01:27:40 +0100
committerVictor Häggqvist <[email protected]>2016-01-15 01:27:40 +0100
commitbe8351486ad1e8c04d4d521a151d54861932ee0b (patch)
tree4a0669f71033dd5d0e7bb31be2aacc4eb1bdb636
parent3dc62a2440daed6692ea3b613e6557ad5b4d42e1 (diff)
caption plugin
-rw-r--r--src/Plugins/Captions.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Plugins/Captions.js b/src/Plugins/Captions.js
new file mode 100644
index 0000000..0286a82
--- /dev/null
+++ b/src/Plugins/Captions.js
@@ -0,0 +1,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) {}
+ }
+
+}