Changes

1,345 bytes added ,  12:26, 19 August 2025
no edit summary
Line 6: Line 6:     
/* Other JS: */
 
/* Other JS: */
 +
 +
/* Minimal: when a collapsible block opens, just (re)load images inside */
 +
(function () {
 +
  function loadImgs(root) {
 +
    if (!root) return;
 +
    root.querySelectorAll('img').forEach(function (img) {
 +
      try {
 +
        if (img.dataset && img.dataset.src) img.src = img.dataset.src;
 +
        if (img.dataset && img.dataset.srcset) img.srcset = img.dataset.srcset;
 +
        img.loading = 'eager';
 +
        try { img.decoding = 'sync'; } catch(e){}
 +
        var s = img.currentSrc || img.src; if (s) { img.src = ''; img.src = s; }
 +
      } catch(e){}
 +
    });
 +
  }
 +
 +
  // Observe attribute flips (covers MF open/close)
 +
  var mo = new MutationObserver(function (muts) {
 +
    muts.forEach(function (m) {
 +
      var el = m.target;
 +
      if (!el) return;
 +
      var opened = el.classList && el.classList.contains('open-block');
 +
      if (!opened && el.getAttribute) opened = el.getAttribute('aria-expanded') === 'true';
 +
      if (opened) loadImgs(el);
 +
    });
 +
  });
 +
 +
  function attach() {
 +
    document.querySelectorAll('.mf-collapsible-block, .collapsible-block, .mw-collapsible')
 +
      .forEach(function (el) {
 +
        mo.observe(el, { attributes: true, attributeFilter: ['class','aria-expanded','style'] });
 +
      });
 +
  }
 +
 +
  if (document.readyState === 'loading') {
 +
    document.addEventListener('DOMContentLoaded', attach);
 +
  } else {
 +
    attach();
 +
  }
 +
})();