@@ -381,29 +381,36 @@ function lightbox()
381381 -- generate the initialization script with the correct options
382382 local scriptContents = " var lightboxQuarto = GLightbox(" .. optionsJson .. " );\n "
383383 scriptContents = scriptContents .. [[
384- window.onload = () => {
385- lightboxQuarto.on('slide_before_load', (data) => {
386- const { slideIndex, slideNode, slideConfig, player, trigger } = data;
387- const href = trigger.getAttribute('href');
388- if (href !== null) {
389- const imgEl = window.document.querySelector(`a[href="${href}"] img`);
390- if (imgEl !== null) {
391- const srcAttr = imgEl.getAttribute("src");
392- if (srcAttr && srcAttr.startsWith("data:")) {
393- slideConfig.href = srcAttr;
384+ (function() {
385+ let previousOnload = window.onload;
386+ window.onload = () => {
387+ if (previousOnload) {
388+ previousOnload();
389+ }
390+ lightboxQuarto.on('slide_before_load', (data) => {
391+ const { slideIndex, slideNode, slideConfig, player, trigger } = data;
392+ const href = trigger.getAttribute('href');
393+ if (href !== null) {
394+ const imgEl = window.document.querySelector(`a[href="${href}"] img`);
395+ if (imgEl !== null) {
396+ const srcAttr = imgEl.getAttribute("src");
397+ if (srcAttr && srcAttr.startsWith("data:")) {
398+ slideConfig.href = srcAttr;
399+ }
394400 }
401+ }
402+ });
403+
404+ lightboxQuarto.on('slide_after_load', (data) => {
405+ const { slideIndex, slideNode, slideConfig, player, trigger } = data;
406+ if (window.Quarto?.typesetMath) {
407+ window.Quarto.typesetMath(slideNode);
395408 }
396- }
397- });
398-
399- lightboxQuarto.on('slide_after_load', (data) => {
400- const { slideIndex, slideNode, slideConfig, player, trigger } = data;
401- if (window.Quarto?.typesetMath) {
402- window.Quarto.typesetMath(slideNode);
403- }
404- });
405-
406- };
409+ });
410+
411+ };
412+
413+ })();
407414 ]]
408415 local scriptTag = " <script>" .. scriptContents .. " </script>"
409416
0 commit comments