-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc6fb3c
commit eb00ce9
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="popup" id="popup-images"> | ||
<div class="popup-background"> | ||
<img src=""> | ||
</div> | ||
</div> | ||
<script type="module"> | ||
import { Popups, ResponsiveImages } from "{{ .Page.Site.BaseURL }}/js/custom.js"; | ||
let popups = new Popups(); | ||
let responsive_images = new ResponsiveImages(popups); | ||
window.custom = { popups, responsive_images }; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class Popups { | ||
constructor() { | ||
this.elems = {}; | ||
|
||
let popup_elems = document.getElementsByClassName("popup"); | ||
for (let popup_elem of popup_elems) { | ||
let id = popup_elem.getAttribute("id"); | ||
if (id !== null) { | ||
this.elems[id] = popup_elem; | ||
} else { | ||
continue; | ||
} | ||
|
||
popup_elem.classList.add("inactive"); | ||
let popup_background = popup_elem.querySelector(".popup-background"); | ||
popup_background.addEventListener("click", (ev) => { | ||
ev.preventDefault(); | ||
this.close_popups(); | ||
}); | ||
} | ||
} | ||
|
||
close_popups() { | ||
for (let id in this.elems) { | ||
let elem = this.elems[id]; | ||
elem.classList.add("inactive"); | ||
} | ||
} | ||
|
||
show_popup(id) { | ||
let elem = this.elems[id]; | ||
elem.classList.remove("inactive"); | ||
} | ||
|
||
get_popup(id) { | ||
let elem = this.elems[id]; | ||
let background = elem.querySelector(".popup-background"); | ||
return background; | ||
} | ||
} | ||
|
||
class ResponsiveImages { | ||
constructor(popups) { | ||
let id = "popup-images"; | ||
let popup_elem = popups.get_popup(id); | ||
let popup_image = popup_elem.querySelector("img"); | ||
|
||
let images = document.getElementsByClassName("responsive-image"); | ||
for (let image of images) { | ||
let elem = image.querySelector("img"); | ||
elem.addEventListener("click", (ev) => { | ||
ev.preventDefault(); | ||
ev.stopPropagation(); | ||
popup_image.src = elem.src; | ||
popups.show_popup(id); | ||
}); | ||
} | ||
this.images = images; | ||
} | ||
} | ||
|
||
export { Popups, ResponsiveImages }; |