Skip to content

Commit 500947a

Browse files
committed
Lightbox support for embed-resources
The base 64 image src will be used when the ligthbox is rendered. Fixes #6892
1 parent d905c3f commit 500947a

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/resources/filters/layout/lightbox.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,25 @@ function lightbox()
340340
local optionsJson = quarto.json.encode(options)
341341

342342
-- generate the initialization script with the correct options
343-
local scriptTag = "<script>var lightboxQuarto = GLightbox(" .. optionsJson .. ");</script>"
343+
local scriptContents = "var lightboxQuarto = GLightbox(" .. optionsJson .. ");\n"
344+
scriptContents = scriptContents .. [[
345+
window.onload = () => {
346+
lightboxQuarto.on('slide_before_load', (data) => {
347+
const { slideIndex, slideNode, slideConfig, player, trigger } = data;
348+
const href = trigger.getAttribute('href');
349+
if (href !== null) {
350+
const imgEl = window.document.querySelector(`a[href="${href}"] img`);
351+
if (imgEl !== null) {
352+
const srcAttr = imgEl.getAttribute("src");
353+
if (srcAttr && srcAttr.startsWith("data:")) {
354+
slideConfig.href = srcAttr;
355+
}
356+
}
357+
}
358+
});
359+
};
360+
]]
361+
local scriptTag = "<script>" .. scriptContents .. "</script>"
344362

345363
-- inject the rendering code
346364
quarto.doc.include_text("after-body", scriptTag)

0 commit comments

Comments
 (0)