| 1 |
import {Core} from "../Core"; |
| 2 |
import {Lightbox} from "./Lightbox"; |
| 3 |
import * as Util from "../Util"; |
| 4 |
|
| 5 |
export class PhotonicLightGallery extends Lightbox { |
| 6 |
constructor() { |
| 7 |
super(); |
| 8 |
} |
| 9 |
|
| 10 |
soloImages() { |
| 11 |
const a = document.querySelectorAll('a[href]'); |
| 12 |
const solos = Array.from(a).filter(elem => /(\.jpg|\.jpeg|\.bmp|\.gif|\.png)/i.test(elem.getAttribute('href'))) |
| 13 |
.filter(elem => !elem.classList.contains('photonic-lb')); |
| 14 |
solos.forEach(solo => { |
| 15 |
solo.classList.add("photonic-" + Photonic_JS.lightbox_library); |
| 16 |
solo.classList.add(Photonic_JS.lightbox_library); |
| 17 |
solo.setAttribute('rel', 'photonic-' + Photonic_JS.lightbox_library); |
| 18 |
}); |
| 19 |
}; |
| 20 |
|
| 21 |
changeVideoURL(element, regular, embed) { |
| 22 |
element.setAttribute('href', regular); |
| 23 |
}; |
| 24 |
|
| 25 |
hostedVideo(a) { |
| 26 |
const html5 = a.getAttribute('href').match(new RegExp(/(\.mp4|\.webm|\.ogg)/i)), |
| 27 |
css = a.classList.contains('photonic-lb'); |
| 28 |
|
| 29 |
if (html5 !== null && !css) { |
| 30 |
let videoSrc = { |
| 31 |
"source": [ |
| 32 |
{ |
| 33 |
"src": a.getAttribute('href'), |
| 34 |
"type": "video/mp4", |
| 35 |
"attributes": { |
| 36 |
"preload": false, |
| 37 |
"playsinline": true, |
| 38 |
"controls": true |
| 39 |
} |
| 40 |
} |
| 41 |
] |
| 42 |
} |
| 43 |
|
| 44 |
a.classList.add(Photonic_JS.lightbox_library + "-html5-video"); |
| 45 |
|
| 46 |
a.setAttribute('data-html5-href', a.getAttribute('href')); |
| 47 |
a.setAttribute('href', ''); |
| 48 |
a.setAttribute('data-video', JSON.stringify(videoSrc)); |
| 49 |
a.setAttribute('data-sub-html', (a.getAttribute('title') ? Util.getText(a.getAttribute('title')) : '')); |
| 50 |
|
| 51 |
this.videoIndex++; |
| 52 |
} |
| 53 |
}; |
| 54 |
|
| 55 |
initialize(selector, selfSelect) { |
| 56 |
this.handleSolos(); |
| 57 |
const self = this; |
| 58 |
|
| 59 |
let selection; |
| 60 |
if (selector instanceof NodeList) { |
| 61 |
selection = selector; |
| 62 |
} |
| 63 |
else if (selector instanceof Element) { |
| 64 |
selection = [selector]; |
| 65 |
} |
| 66 |
else { |
| 67 |
selection = document.querySelectorAll(selector); |
| 68 |
} |
| 69 |
|
| 70 |
const plugins = Photonic_JS.lg_plugins.split(','); |
| 71 |
|
| 72 |
selection.forEach(function (current) { |
| 73 |
const lguid = current.getAttribute('lg-uid'); |
| 74 |
if (lguid != null && lguid !== '') { |
| 75 |
window.lgData[lguid].destroy(true); |
| 76 |
} |
| 77 |
|
| 78 |
let thumbs; |
| 79 |
thumbs = current.querySelectorAll('a.photonic-lightgallery'); |
| 80 |
let rel = ''; |
| 81 |
if (thumbs.length > 0) { |
| 82 |
rel = thumbs[0].getAttribute('rel'); |
| 83 |
} |
| 84 |
|
| 85 |
current.addEventListener('lgAfterSlide', event => { |
| 86 |
thumbs = current.querySelectorAll('a.photonic-lightgallery'); // Need to fetch again, since the next line causes issues after "Add More". |
| 87 |
let thumb; |
| 88 |
if (thumbs.length !== 0) { |
| 89 |
thumb = thumbs[event.detail.index]; |
| 90 |
} |
| 91 |
else if (current.classList.contains('photonic-lightgallery')) { |
| 92 |
thumb = current; |
| 93 |
} |
| 94 |
|
| 95 |
let lgId = event.target.getAttribute('data-photonic-lg-uid'); |
| 96 |
if (thumb != null && lgId != null) { |
| 97 |
self.setHash(thumb); |
| 98 |
const shareable = { |
| 99 |
'url': location.href, |
| 100 |
'title': Util.getText(thumb.getAttribute('data-title')), |
| 101 |
'image': thumb.getAttribute('href') |
| 102 |
}; |
| 103 |
self.addSocial('#lg-toolbar-' + lgId, shareable); |
| 104 |
} |
| 105 |
}, false); |
| 106 |
|
| 107 |
current.addEventListener('lgAfterClose', function () { |
| 108 |
self.unsetHash(); |
| 109 |
}); |
| 110 |
|
| 111 |
let options = { |
| 112 |
selector: (selfSelect === undefined || !selfSelect) ? 'a[rel="' + rel + '"]' : 'this', |
| 113 |
speed: 500, |
| 114 |
counter: selfSelect === undefined || !selfSelect, |
| 115 |
pause: Photonic_JS.slideshow_interval, |
| 116 |
mode: Photonic_JS.lg_transition_effect, |
| 117 |
download: Photonic_JS.lg_enable_download, |
| 118 |
loop: Photonic_JS.lightbox_loop, |
| 119 |
hideBarsDelay: Photonic_JS.lg_hide_bars_delay, |
| 120 |
getCaptionFromTitleOrAlt: false, |
| 121 |
exThumbImage: 'data-photonic-thumb', |
| 122 |
mobileSettings: { |
| 123 |
controls: Photonic_JS.lg_mobile_controls, |
| 124 |
showCloseIcon: Photonic_JS.lg_mobile_close, |
| 125 |
download: Photonic_JS.lg_mobile_download |
| 126 |
} |
| 127 |
}; |
| 128 |
|
| 129 |
let lgPlugins = [lgVideo]; |
| 130 |
|
| 131 |
if (plugins.indexOf('thumbnail') > -1) { |
| 132 |
lgPlugins.push(lgThumbnail); |
| 133 |
options.thumbnail = true; |
| 134 |
} |
| 135 |
|
| 136 |
if (plugins.indexOf('zoom') > -1) { |
| 137 |
lgPlugins.push(lgZoom); |
| 138 |
} |
| 139 |
|
| 140 |
if (plugins.indexOf('fullscreen') > -1) { |
| 141 |
lgPlugins.push(lgFullscreen); |
| 142 |
} |
| 143 |
|
| 144 |
if (plugins.indexOf('autoplay') > -1) { |
| 145 |
lgPlugins.push(lgAutoplay); |
| 146 |
options.slideShowInterval = Photonic_JS.lg_transition_speed; |
| 147 |
} |
| 148 |
|
| 149 |
options.plugins = lgPlugins; |
| 150 |
|
| 151 |
const lightbox = lightGallery(current,options); |
| 152 |
if (!selfSelect === undefined || !selfSelect) { |
| 153 |
Core.addToLightboxList(rel, lightbox); |
| 154 |
} |
| 155 |
current.setAttribute('data-photonic-lg-uid', lightbox.lgId); |
| 156 |
}); |
| 157 |
}; |
| 158 |
|
| 159 |
initializeForNewContainer(containerId) { |
| 160 |
this.initialize(containerId); |
| 161 |
}; |
| 162 |
} |
| 163 |
|