Compare commits
No commits in common. "e0de885cddd28498405ddd71754a335e4436c79e" and "71f795bae5e867611aef1ba9fc46325d6035d0c8" have entirely different histories.
e0de885cdd
...
71f795bae5
@ -176,7 +176,7 @@ pre code {
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#delete-dialog, .lightbox-dialog {
|
#delete-dialog {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
border: 2px solid black;
|
border: 2px solid black;
|
||||||
@ -190,27 +190,6 @@ pre code {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lightbox-inner {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 20px;
|
|
||||||
min-width: 400px;
|
|
||||||
background-color: #c1ceb1;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lightbox-image {
|
|
||||||
max-width: 70vw;
|
|
||||||
max-height: 70vh;
|
|
||||||
object-fit: scale-down;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lightbox-nav {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-code-container {
|
.copy-code-container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
width: calc(100% - 4px);
|
width: calc(100% - 4px);
|
||||||
@ -463,6 +442,7 @@ input[type=text]:focus, input[type=password]:focus, textarea:focus, select:focus
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.contain-svg:not(.full) > svg {
|
.contain-svg:not(.full) > svg {
|
||||||
height: 50%;
|
height: 50%;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
@ -730,6 +710,7 @@ ul, ol {
|
|||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
min-width: 36px;
|
min-width: 36px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.babycode-button > * {
|
.babycode-button > * {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
99
js/ui.js
99
js/ui.js
@ -21,86 +21,6 @@ function activateSelfDeactivateSibs(button) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openLightbox(post, idx) {
|
|
||||||
lightboxCurrentPost = post;
|
|
||||||
lightboxCurrentIdx = idx;
|
|
||||||
lightboxObj.img.src = lightboxImages.get(post)[idx].src;
|
|
||||||
lightboxObj.openOriginalAnchor.href = lightboxImages.get(post)[idx].src
|
|
||||||
lightboxObj.prevButton.disabled = lightboxImages.get(post).length === 1
|
|
||||||
lightboxObj.nextButton.disabled = lightboxImages.get(post).length === 1
|
|
||||||
lightboxObj.imageCount.textContent = `Image ${idx + 1} of ${lightboxImages.get(post).length}`
|
|
||||||
|
|
||||||
if (!lightboxObj.dialog.open) {
|
|
||||||
lightboxObj.dialog.showModal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const modulo = (n, m) => ((n % m) + m) % m
|
|
||||||
|
|
||||||
function lightboxNext() {
|
|
||||||
const l = lightboxImages.get(lightboxCurrentPost).length;
|
|
||||||
const target = modulo(lightboxCurrentIdx + 1, l);
|
|
||||||
openLightbox(lightboxCurrentPost, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
function lightboxPrev() {
|
|
||||||
const l = lightboxImages.get(lightboxCurrentPost).length;
|
|
||||||
const target = modulo(lightboxCurrentIdx - 1, l);
|
|
||||||
openLightbox(lightboxCurrentPost, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
function constructLightbox() {
|
|
||||||
const dialog = document.createElement("dialog");
|
|
||||||
dialog.classList.add("lightbox-dialog");
|
|
||||||
dialog.addEventListener("click", (e) => {
|
|
||||||
if (e.target === dialog) {
|
|
||||||
dialog.close();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const dialogInner = document.createElement("div");
|
|
||||||
dialogInner.classList.add("lightbox-inner");
|
|
||||||
dialog.appendChild(dialogInner);
|
|
||||||
const img = document.createElement("img");
|
|
||||||
img.classList.add("lightbox-image")
|
|
||||||
dialogInner.appendChild(img);
|
|
||||||
const openOriginalAnchor = document.createElement("a")
|
|
||||||
openOriginalAnchor.text = "Open original in new window"
|
|
||||||
openOriginalAnchor.target = "_blank"
|
|
||||||
openOriginalAnchor.rel = "noopener noreferrer nofollow"
|
|
||||||
dialogInner.appendChild(openOriginalAnchor);
|
|
||||||
|
|
||||||
const navSpan = document.createElement("span");
|
|
||||||
navSpan.classList.add("lightbox-nav");
|
|
||||||
const prevButton = document.createElement("button");
|
|
||||||
prevButton.type = "button";
|
|
||||||
prevButton.textContent = "Previous";
|
|
||||||
prevButton.addEventListener("click", lightboxPrev);
|
|
||||||
const nextButton = document.createElement("button");
|
|
||||||
nextButton.type = "button";
|
|
||||||
nextButton.textContent = "Next";
|
|
||||||
nextButton.addEventListener("click", lightboxNext);
|
|
||||||
const imageCount = document.createElement("span");
|
|
||||||
imageCount.textContent = "Image of ";
|
|
||||||
navSpan.appendChild(prevButton);
|
|
||||||
navSpan.appendChild(imageCount);
|
|
||||||
navSpan.appendChild(nextButton);
|
|
||||||
|
|
||||||
dialogInner.appendChild(navSpan);
|
|
||||||
return {
|
|
||||||
img: img,
|
|
||||||
dialog: dialog,
|
|
||||||
openOriginalAnchor: openOriginalAnchor,
|
|
||||||
prevButton: prevButton,
|
|
||||||
nextButton: nextButton,
|
|
||||||
imageCount: imageCount,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let lightboxImages = new Map(); //.post-inner : Array<Object>
|
|
||||||
let lightboxObj = null;
|
|
||||||
let lightboxCurrentPost = null;
|
|
||||||
let lightboxCurrentIdx = -1;
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
// tabs
|
// tabs
|
||||||
document.querySelectorAll(".tab-button").forEach(button => {
|
document.querySelectorAll(".tab-button").forEach(button => {
|
||||||
@ -125,23 +45,4 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
|
|
||||||
toggleButton.addEventListener("click", toggle);
|
toggleButton.addEventListener("click", toggle);
|
||||||
});
|
});
|
||||||
|
|
||||||
//lightboxes
|
|
||||||
lightboxObj = constructLightbox();
|
|
||||||
document.body.appendChild(lightboxObj.dialog);
|
|
||||||
const postImages = document.querySelectorAll(".post-inner img.block-img");
|
|
||||||
postImages.forEach(postImage => {
|
|
||||||
const belongingTo = postImage.closest(".post-inner");
|
|
||||||
const images = lightboxImages.get(belongingTo) ?? [];
|
|
||||||
images.push({
|
|
||||||
src: postImage.src,
|
|
||||||
alt: postImage.alt,
|
|
||||||
});
|
|
||||||
const idx = images.length - 1;
|
|
||||||
lightboxImages.set(belongingTo, images);
|
|
||||||
postImage.style.cursor = "pointer";
|
|
||||||
postImage.addEventListener("click", () => {
|
|
||||||
openLightbox(belongingTo, idx);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -71,7 +71,7 @@ local tags = {
|
|||||||
b = "<strong>$S</strong>",
|
b = "<strong>$S</strong>",
|
||||||
i = "<em>$S</em>",
|
i = "<em>$S</em>",
|
||||||
s = "<del>$S</del>",
|
s = "<del>$S</del>",
|
||||||
img = "<div class=\"post-img-container\"><img class=\"block-img\" src=$A alt=$S></div>",
|
img = "<div class=\"post-img-container\"><img class=\"block-img\" src=$A alt=%S></div>",
|
||||||
url = "<a href=\"$A\">$S</a>",
|
url = "<a href=\"$A\">$S</a>",
|
||||||
quote = "<blockquote>$S</blockquote>",
|
quote = "<blockquote>$S</blockquote>",
|
||||||
code = function(children)
|
code = function(children)
|
||||||
|
@ -220,7 +220,7 @@ pre code {
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#delete-dialog, .lightbox-dialog {
|
#delete-dialog {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
border: 2px solid black;
|
border: 2px solid black;
|
||||||
@ -234,27 +234,6 @@ pre code {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lightbox-inner {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 20px;
|
|
||||||
min-width: 400px;
|
|
||||||
background-color: $accent_color;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lightbox-image {
|
|
||||||
max-width: 70vw;
|
|
||||||
max-height: 70vh;
|
|
||||||
object-fit: scale-down;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lightbox-nav {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-code-container {
|
.copy-code-container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
// width: 100%;
|
// width: 100%;
|
||||||
|
Loading…
Reference in New Issue
Block a user