Skip to content

Commit 4b52dc3

Browse files
Allow magnifying images
1 parent 3627925 commit 4b52dc3

3 files changed

Lines changed: 119 additions & 1 deletion

File tree

‎source/_static/lightbox.css‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.rst-content img.lightbox-enabled {
2+
cursor: zoom-in;
3+
}
4+
5+
body.image-lightbox-open {
6+
overflow: hidden;
7+
}
8+
9+
.image-lightbox {
10+
position: fixed;
11+
inset: 0;
12+
z-index: 10000;
13+
display: flex;
14+
align-items: center;
15+
justify-content: center;
16+
padding: 2rem;
17+
background: rgba(0, 0, 0, 0.88);
18+
cursor: zoom-out;
19+
}
20+
21+
.image-lightbox[hidden] {
22+
display: none;
23+
}
24+
25+
.image-lightbox img {
26+
max-width: 100%;
27+
max-height: 100%;
28+
width: auto;
29+
height: auto;
30+
margin: 0;
31+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
32+
cursor: zoom-out;
33+
}

‎source/_static/lightbox.js‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
(function () {
2+
var skip =
3+
".platform, .platform-vendors, .partner-logos, .video-preview, .video-previews, table.docutils";
4+
5+
function eligible(img) {
6+
return img.closest(".rst-content") && !img.closest(skip) && !img.closest("a");
7+
}
8+
9+
function init() {
10+
var images = document.querySelectorAll(".rst-content img");
11+
var targets = [];
12+
images.forEach(function (img) {
13+
if (eligible(img)) {
14+
targets.push(img);
15+
}
16+
});
17+
if (!targets.length) {
18+
return;
19+
}
20+
21+
var overlay = document.createElement("div");
22+
overlay.className = "image-lightbox";
23+
overlay.hidden = true;
24+
overlay.setAttribute("role", "dialog");
25+
overlay.setAttribute("aria-modal", "true");
26+
overlay.setAttribute("aria-label", "Enlarged image");
27+
28+
var enlarged = document.createElement("img");
29+
enlarged.alt = "";
30+
overlay.appendChild(enlarged);
31+
document.body.appendChild(overlay);
32+
33+
var lastFocus = null;
34+
35+
function open(img) {
36+
lastFocus = document.activeElement;
37+
enlarged.src = img.currentSrc || img.src;
38+
enlarged.alt = img.alt || "";
39+
overlay.hidden = false;
40+
document.body.classList.add("image-lightbox-open");
41+
overlay.focus();
42+
}
43+
44+
function close() {
45+
overlay.hidden = true;
46+
enlarged.removeAttribute("src");
47+
enlarged.alt = "";
48+
document.body.classList.remove("image-lightbox-open");
49+
if (lastFocus && lastFocus.focus) {
50+
lastFocus.focus();
51+
}
52+
}
53+
54+
overlay.tabIndex = -1;
55+
overlay.addEventListener("click", close);
56+
document.addEventListener("keydown", function (event) {
57+
if (event.key === "Escape" && !overlay.hidden) {
58+
close();
59+
}
60+
});
61+
62+
targets.forEach(function (img) {
63+
img.classList.add("lightbox-enabled");
64+
img.tabIndex = 0;
65+
img.setAttribute("role", "button");
66+
img.setAttribute("aria-haspopup", "dialog");
67+
img.addEventListener("click", function () {
68+
open(img);
69+
});
70+
img.addEventListener("keydown", function (event) {
71+
if (event.key === "Enter" || event.key === " ") {
72+
event.preventDefault();
73+
open(img);
74+
}
75+
});
76+
});
77+
}
78+
79+
if (document.readyState === "loading") {
80+
document.addEventListener("DOMContentLoaded", init);
81+
} else {
82+
init();
83+
}
84+
})();

‎source/conf.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
html_theme = "sphinx_rtd_theme"
3535
html_static_path = ["_static"]
36-
html_css_files = ["overview-logos.css"]
36+
html_css_files = ["overview-logos.css", "lightbox.css"]
37+
html_js_files = ["lightbox.js"]
3738
html_title = "Coriolis Documentation"
3839
html_logo = "_static/images/coriolis-logo.svg"
3940
html_favicon = "_static/images/coriolis-logo.svg"

0 commit comments

Comments
 (0)