summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-16 14:55:56 +0800
committerEltrac <hi@guhub.cn>2025-09-16 14:55:56 +0800
commit7eb322e84a1fc56308614f51342392dbf4135286 (patch)
tree548c3e6388e6ff1512c7c5e56af4722b791e907c /src
parent7a4599565c9871968726b0601a097ac36e1d3ace (diff)
refactor: images can be inline
- remove block style and max width restraint - images no longer need to be wrapped in a link
Diffstat (limited to 'src')
-rw-r--r--src/libra.css2
-rw-r--r--src/lightbox.js28
2 files changed, 2 insertions, 28 deletions
diff --git a/src/libra.css b/src/libra.css
index 2118d14..1c7277c 100644
--- a/src/libra.css
+++ b/src/libra.css
@@ -27,8 +27,6 @@
position: absolute;
transition-duration: 0.2s;
transition-property: transform;
- display: block;
- max-width: 100%;
cursor: pointer;
}
diff --git a/src/lightbox.js b/src/lightbox.js
index 54c5283..d21b7ab 100644
--- a/src/lightbox.js
+++ b/src/lightbox.js
@@ -20,41 +20,17 @@ export default class LightBox {
initOverlay() {
this.overlay = new Overlay();
- this.overlay.element.addEventListener('click', e => {
+ this.overlay.element.addEventListener('click', () => {
this.closeCurrent();
});
}
initImages() {
this.images = document.querySelectorAll(this.selector);
-
- function wrapInLink(image) {
- // wrap image with a link if it's not already wrapped
- const parent = image.parentElement;
- let link;
- if (!parent || parent.tagName !== 'A') {
- link = document.createElement('a');
- link.href = image.src;
- // replace image with the linked one
- parent.insertBefore(link, image);
- link.appendChild(image);
- } else {
- link = parent;
- }
- return link;
- }
-
this.images.forEach(image => {
if (image.tagName !== 'IMG') return;
-
image.id = crypto.randomUUID(); // generate unique id for each image
- const link = wrapInLink(image); // make sure every image has a link
-
- // click link to open lightbox
- link.addEventListener('click', e => {
- e.preventDefault();
- this.openLightBox(image);
- });
+ image.addEventListener('click', () => this.openLightBox(image)); // click image to open lightbox
});
}