| 1 |
import {Lightbox} from "./Lightbox"; |
| 2 |
import {Core} from "../Core"; |
| 3 |
import * as Util from "../Util"; |
| 4 |
|
| 5 |
export class PhotonicGLightbox extends Lightbox { |
| 6 |
constructor() { |
| 7 |
super(); |
| 8 |
} |
| 9 |
|
| 10 |
hostedVideo(a) { |
| 11 |
const self = this; |
| 12 |
|
| 13 |
const html5 = a.getAttribute('href').match(new RegExp(/(\.mp4|\.webm|\.ogg)/i)), |
| 14 |
css = a.classList.contains('photonic-lb'); |
| 15 |
|
| 16 |
if (html5 !== null && !css) { |
| 17 |
a.classList.add(Photonic_JS.lightbox_library + "-html5-video"); |
| 18 |
} |
| 19 |
}; |
| 20 |
|
| 21 |
initialize(selector) { |
| 22 |
this.handleSolos(); |
| 23 |
const self = this; |
| 24 |
|
| 25 |
let selection; |
| 26 |
if (selector == null) { |
| 27 |
selection = document.querySelectorAll('.photonic-level-1-container'); |
| 28 |
} |
| 29 |
else if (selector instanceof NodeList) { |
| 30 |
selection = selector; |
| 31 |
} |
| 32 |
else if (selector instanceof Element) { |
| 33 |
selection = [selector]; |
| 34 |
} |
| 35 |
else { |
| 36 |
selection = document.querySelectorAll(selector); |
| 37 |
} |
| 38 |
|
| 39 |
selection.forEach((gallery) => { |
| 40 |
const galleryItems = gallery.querySelectorAll('.photonic-lb'); |
| 41 |
if (galleryItems.length > 0) { |
| 42 |
const rel = galleryItems.item(0).getAttribute('rel'); // Get "rel" from first "a" element |
| 43 |
if (rel != null) { |
| 44 |
let lightbox; |
| 45 |
lightbox = Core.getLightboxList()[rel]; |
| 46 |
if (lightbox) { |
| 47 |
lightbox.destroy(); |
| 48 |
} |
| 49 |
lightbox = GLightbox({ |
| 50 |
selector: '[rel="' + rel + '"]', |
| 51 |
loop: Photonic_JS.lightbox_loop, |
| 52 |
}); |
| 53 |
lightbox.on('slide_changed', ({prev, current}) => { |
| 54 |
const idx = current.index; |
| 55 |
const thumb = galleryItems.item(idx); |
| 56 |
let social = document.querySelector('#photonic-social'); |
| 57 |
if (social) { |
| 58 |
social.parentNode.removeChild(social); |
| 59 |
} |
| 60 |
self.setHash(thumb); |
| 61 |
|
| 62 |
const shareable = { |
| 63 |
'url': location.href, |
| 64 |
'title': Util.getText(thumb.getAttribute('data-title')), |
| 65 |
'image': thumb.getAttribute('href') |
| 66 |
}; |
| 67 |
self.addSocial('.gslide.loaded.current .ginner-container', shareable); |
| 68 |
}); |
| 69 |
lightbox.on('close', () => { |
| 70 |
self.unsetHash(); |
| 71 |
}); |
| 72 |
Core.addToLightboxList(rel, lightbox); |
| 73 |
} |
| 74 |
} |
| 75 |
else if (!gallery.classList.contains('photonic-level-2-container') && !gallery.querySelector('.photonic-level-2-container') && !gallery.querySelector('.photonic-tree')) { // Probably a solo item |
| 76 |
GLightbox({ |
| 77 |
selector: selector, |
| 78 |
}); |
| 79 |
} |
| 80 |
}); |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
initializeForNewContainer(containerId) { |
| 85 |
this.initialize(containerId); |
| 86 |
} |
| 87 |
} |
| 88 |
|