Refactor: move event listeners out of load
This commit is contained in:
parent
71dca0a9ce
commit
194c00a280
12
index.php
12
index.php
|
@ -190,13 +190,6 @@ if (isset($_GET['random'])) {
|
||||||
// initialize glightbox
|
// initialize glightbox
|
||||||
const lightbox = GLightbox();
|
const lightbox = GLightbox();
|
||||||
|
|
||||||
// if imgproxy version fails to load, fallback to full-size image
|
|
||||||
document.querySelectorAll(".gallery img").forEach(function(img) {
|
|
||||||
img.addEventListener("error", function() {
|
|
||||||
this.src = this.parentElement.href;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// add hash to url when image is opened
|
// add hash to url when image is opened
|
||||||
lightbox.on("slide_changed", function(slide) {
|
lightbox.on("slide_changed", function(slide) {
|
||||||
window.location.hash = slide.current.slideConfig.alt;
|
window.location.hash = slide.current.slideConfig.alt;
|
||||||
|
@ -211,6 +204,7 @@ if (isset($_GET['random'])) {
|
||||||
if (window.location.hash) {
|
if (window.location.hash) {
|
||||||
openImageFromHash();
|
openImageFromHash();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// if hash is changed and lightbox is closed, open image
|
// if hash is changed and lightbox is closed, open image
|
||||||
window.addEventListener("hashchange", function() {
|
window.addEventListener("hashchange", function() {
|
||||||
|
@ -218,6 +212,10 @@ if (isset($_GET['random'])) {
|
||||||
openImageFromHash();
|
openImageFromHash();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// if imgproxy version fails to load, fallback to full-size image
|
||||||
|
document.querySelectorAll(".gallery img").forEach(function(img) {
|
||||||
|
this.src = this.parentElement.href;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue