-
Notifications
You must be signed in to change notification settings - Fork 6
Fix ImageEnlarger: accessibility, modal re-entry, responsive images, MutationObserver perf #925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e6653cc
c1e5246
9b68c78
2b8330d
259cc7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5590,26 +5590,6 @@ int main() | |||||||||
| transition: opacity 0.2s ease; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| .xmoj-image-preview::after { | ||||||||||
| content: "点击放大"; | ||||||||||
| position: absolute; | ||||||||||
| background-color: rgba(0, 0, 0, 0.7); | ||||||||||
| color: white; | ||||||||||
| padding: 5px 10px; | ||||||||||
| border-radius: 3px; | ||||||||||
| font-size: 12px; | ||||||||||
| white-space: nowrap; | ||||||||||
| pointer-events: none; | ||||||||||
| opacity: 0; | ||||||||||
| transition: opacity 0.2s ease; | ||||||||||
| top: 50%; | ||||||||||
| left: 50%; | ||||||||||
| transform: translate(-50%, -50%); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| .xmoj-image-preview:hover::after { | ||||||||||
| opacity: 1; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| .xmoj-image-modal { | ||||||||||
| display: none; | ||||||||||
|
|
@@ -5674,6 +5654,10 @@ int main() | |||||||||
| top: 20px; | ||||||||||
| right: 30px; | ||||||||||
| color: white; | ||||||||||
| background: none; | ||||||||||
| border: none; | ||||||||||
| padding: 0; | ||||||||||
| line-height: 1; | ||||||||||
| font-size: 40px; | ||||||||||
| font-weight: bold; | ||||||||||
| cursor: pointer; | ||||||||||
|
|
@@ -5691,8 +5675,11 @@ int main() | |||||||||
| ImageModal.className = "xmoj-image-modal"; | ||||||||||
| ImageModal.id = "xmoj-image-modal"; | ||||||||||
|
|
||||||||||
| let CloseButton = document.createElement("span"); | ||||||||||
| let CloseButton = document.createElement("button"); | ||||||||||
| CloseButton.className = "xmoj-image-modal-close"; | ||||||||||
| CloseButton.type = "button"; | ||||||||||
| CloseButton.setAttribute("aria-label", "关闭图片"); | ||||||||||
| CloseButton.title = "关闭图片"; | ||||||||||
| CloseButton.innerHTML = "×"; | ||||||||||
| ImageModal.appendChild(CloseButton); | ||||||||||
|
|
||||||||||
|
|
@@ -5804,31 +5791,44 @@ int main() | |||||||||
| }); | ||||||||||
|
|
||||||||||
| // Apply to all images on the page | ||||||||||
| let ApplyEnlargerToImages = () => { | ||||||||||
| let Images = document.querySelectorAll("img"); | ||||||||||
| Images.forEach((img) => { | ||||||||||
| if (!img.classList.contains("xmoj-image-preview") && | ||||||||||
| !img.parentElement.classList.contains("xmoj-image-modal") && | ||||||||||
| img.src && | ||||||||||
| !img.src.includes("gravatar") && | ||||||||||
| !img.src.includes("cravatar")) { | ||||||||||
|
|
||||||||||
| img.classList.add("xmoj-image-preview"); | ||||||||||
| img.style.position = "relative"; | ||||||||||
| img.addEventListener("click", (e) => { | ||||||||||
| e.stopPropagation(); | ||||||||||
| OpenImageModal(img.src); | ||||||||||
| }); | ||||||||||
| let ApplyEnlargerToImage = (img) => { | ||||||||||
| const effectiveSrc = img.currentSrc || img.src; | ||||||||||
| if (!img.classList.contains("xmoj-image-preview") && | ||||||||||
| !img.closest(".xmoj-image-modal") && | ||||||||||
| effectiveSrc && | ||||||||||
| !effectiveSrc.includes("gravatar") && | ||||||||||
| !effectiveSrc.includes("cravatar")) { | ||||||||||
|
|
||||||||||
| img.classList.add("xmoj-image-preview"); | ||||||||||
| if (!img.title) { | ||||||||||
| img.title = "点击放大"; | ||||||||||
| } | ||||||||||
| }); | ||||||||||
| img.addEventListener("click", (e) => { | ||||||||||
| e.stopPropagation(); | ||||||||||
| OpenImageModal(effectiveSrc); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: The modal opens a stale image URL because the click handler captures Prompt for AI agents
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The modal opens a stale image URL because Prompt for AI agents
Suggested change
|
||||||||||
| }); | ||||||||||
|
Comment on lines
+5802
to
+5809
|
||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| let ApplyEnlargerToImages = () => { | ||||||||||
| document.querySelectorAll("img").forEach(ApplyEnlargerToImage); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| // Apply to existing images | ||||||||||
| ApplyEnlargerToImages(); | ||||||||||
|
|
||||||||||
| // Apply to dynamically added images | ||||||||||
| let Observer = new MutationObserver((mutations) => { | ||||||||||
| ApplyEnlargerToImages(); | ||||||||||
| mutations.forEach((mutation) => { | ||||||||||
| mutation.addedNodes.forEach((node) => { | ||||||||||
| if (node.nodeType !== Node.ELEMENT_NODE) return; | ||||||||||
| if (node.tagName === "IMG") { | ||||||||||
| ApplyEnlargerToImage(node); | ||||||||||
| } else { | ||||||||||
| node.querySelectorAll("img").forEach(ApplyEnlargerToImage); | ||||||||||
| } | ||||||||||
| }); | ||||||||||
|
Comment on lines
5821
to
+5830
|
||||||||||
| }); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| Observer.observe(document.body, { | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CloseButton was changed from a to a , but the CSS for
.xmoj-image-modal-closedoesn’t reset default button styles (background/border/padding). This will likely render a native button chrome behind the “×” and affect layout/contrast. Consider addingbackground: none; border: 0; padding: 0; line-height: 1;(and optionallyappearance: none;) for.xmoj-image-modal-closenow that it’s a button.