| 1 |
import {Lightbox} from "./Lightbox"; |
| 2 |
import * as Util from "../Util"; |
| 3 |
|
| 4 |
export class PhotonicBaguetteBox extends Lightbox { |
| 5 |
constructor() { |
| 6 |
super(); |
| 7 |
} |
| 8 |
|
| 9 |
soloImages() { |
| 10 |
const solos = super.soloImages(); |
| 11 |
let idIndex = 1; |
| 12 |
solos.forEach(solo => { |
| 13 |
if (solo.getAttribute('id') == null) { |
| 14 |
solo.setAttribute('id', 'photonic-baguettebox-' + idIndex); |
| 15 |
idIndex++; |
| 16 |
} |
| 17 |
}); |
| 18 |
}; |
| 19 |
|
| 20 |
hostedVideo(a) { |
| 21 |
const self = this; |
| 22 |
const html5 = a.getAttribute('href').match(new RegExp(/(\.mp4|\.webm|\.ogg)/i)), |
| 23 |
css = a.classList.contains('photonic-lb'); |
| 24 |
|
| 25 |
if (html5 !== null && !css) { |
| 26 |
a.classList.add(Photonic_JS.lightbox_library + "-html5-video"); |
| 27 |
self.modifyAdditionalVideoProperties(a); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
modifyAdditionalVideoProperties(anchor) { |
| 33 |
if (anchor != null && anchor instanceof Element && anchor.tagName === 'A') { |
| 34 |
anchor.setAttribute('data-content-type', 'video'); |
| 35 |
if (anchor.getAttribute('id') == null) { |
| 36 |
anchor.setAttribute('id', 'photonic-baguettebox-video-' + this.videoIndex); |
| 37 |
this.videoIndex++; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
initialize(selector, destroy) { |
| 43 |
this.handleSolos(); |
| 44 |
const self = this; |
| 45 |
|
| 46 |
let selection; |
| 47 |
if (selector == null) { |
| 48 |
selection = document.querySelectorAll('.photonic-level-1-container'); |
| 49 |
} |
| 50 |
else if (selector instanceof NodeList) { |
| 51 |
selection = selector; |
| 52 |
} |
| 53 |
else if (selector instanceof Element) { |
| 54 |
selection = [selector]; |
| 55 |
} |
| 56 |
else { |
| 57 |
selection = document.querySelectorAll(selector); |
| 58 |
} |
| 59 |
|
| 60 |
if (destroy) { |
| 61 |
baguetteBox.destroy(); |
| 62 |
} |
| 63 |
|
| 64 |
selection.forEach(function (current) { |
| 65 |
const galleryId = current.getAttribute('id'); |
| 66 |
baguetteBox.run('#' + galleryId, { |
| 67 |
captions: (a) => { |
| 68 |
return a.getAttribute('data-title') ? Util.HTMLSanitizer.SanitizeHTML(a.getAttribute('data-title')) : (a.getAttribute('title') ? Util.getText(a.getAttribute('title')) : ''); |
| 69 |
}, |
| 70 |
onChange: (idx, count) => { |
| 71 |
const links = current.querySelectorAll('.photonic-lb'); |
| 72 |
const a = links.item(idx); |
| 73 |
if (a != null) { |
| 74 |
self.setHash(a); |
| 75 |
|
| 76 |
const shareable = { |
| 77 |
'url': location.href, |
| 78 |
'title': Util.getText(a.getAttribute('data-title')), |
| 79 |
'image': a.getAttribute('href') |
| 80 |
}; |
| 81 |
self.addSocial('#baguetteBox-overlay', shareable); |
| 82 |
} |
| 83 |
}, |
| 84 |
afterHide: () => { |
| 85 |
self.unsetHash(); |
| 86 |
}, |
| 87 |
}); |
| 88 |
}); |
| 89 |
}; |
| 90 |
|
| 91 |
initializeForNewContainer(containerId) { |
| 92 |
this.initialize(containerId); |
| 93 |
} |
| 94 |
} |
| 95 |
|