Jump to content

MediaWiki:Common.js: Difference between revisions

From Continuum Universes Wiki
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
(function() {
$(function() {
    function resizeAndCenterSlideshow(mwSlideshow) {
  fetch('/api.php?action=query&meta=siteinfo&siprop=statistics&format=json')
        const slideshow = mwSlideshow.querySelector('.slideshow');
    .then(res => res.json())
 
     .then(data => {
        if (!slideshow) return;
      const current = data.query.statistics.articles;
 
      const goal = 500;
        // Clear out any rogue inline styles
      const left = goal - current;
        slideshow.style.position = 'relative';  // Let it sit naturally inside mw-jsslideshow
      const el = document.getElementById("article-countdown");
        slideshow.style.left = '0';
      if (el) {
        slideshow.style.top = '';
         el.innerHTML = left > 0
        slideshow.style.transform = '';
          ? `🚧 Only <strong>${left}</strong> articles to go until 500!`
 
          : `🎯 We've reached 500 articles! Celebrate good times, c'mon!`;
        // Make sure mw-jsslideshow fits around slideshow
      }
        mwSlideshow.style.width = slideshow.scrollWidth + 'px';
     });
        mwSlideshow.style.height = slideshow.scrollHeight + 'px';
});
        mwSlideshow.style.margin = '0 auto';  // Center the whole box horizontally
// MediaWiki:Common.js
 
mw.hook('rcfilters.ui.initialized').add(function () {
        // Center each individual image inside each slide
  document.documentElement.classList.add('rcfilters-ready');
        slideshow.querySelectorAll('div').forEach(slide => {
});
            const img = slide.querySelector('img');
            if (img) {
                // Make sure each slide is full-width & centers its image
                slide.style.display = 'flex';
                slide.style.justifyContent = 'center';
                slide.style.alignItems = 'center';
                slide.style.width = slideshow.scrollWidth + 'px';
 
                img.style.maxWidth = '100%';
                img.style.height = 'auto';
                img.style.objectFit = 'contain';
            }
        });
     }
 
    function initSlideshowResizer() {
        document.querySelectorAll('.mw-jsslideshow').forEach(mwSlideshow => {
            resizeAndCenterSlideshow(mwSlideshow);
 
            // Optional: Resize on window resize
            window.addEventListener('resize', () => {
                resizeAndCenterSlideshow(mwSlideshow);
            });
 
            // Observe for changes (like slide swaps)
            const slideshow = mwSlideshow.querySelector('.slideshow');
            if (slideshow) {
                const observer = new MutationObserver(() => {
                    resizeAndCenterSlideshow(mwSlideshow);
                });
 
                observer.observe(slideshow, {
                    attributes: true,
                    attributeFilter: ['style'],
                    childList: true,
                    subtree: true
                });
            }
        });
    }
 
    // Init when ready
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        initSlideshowResizer();
    } else {
        document.addEventListener('DOMContentLoaded', initSlideshowResizer);
    }
   
   
    function cleanSlideshowStyles(slideshowContainer) {
        const slideshow = slideshowContainer.querySelector('.slideshow');
        if (slideshow) {
            // Remove inline styles on the main slideshow container
            slideshow.style.width = '';
            slideshow.style.height = '';
 
            // Remove inline styles on each slide div
            slideshow.querySelectorAll('div').forEach(slide => {
                slide.style.width = '';
                slide.style.height = '';
            });
         }
    }
 
    function initSlideshowFix() {
        // Locate all mw-jsslideshow instances
        document.querySelectorAll('.mw-jsslideshow').forEach(mwSlideshow => {
            // Clean styles on page load
            cleanSlideshowStyles(mwSlideshow);
 
            // Optional: Re-clean styles on window resize
            window.addEventListener('resize', () => {
                cleanSlideshowStyles(mwSlideshow);
            });
 
            // Hook into slide transitions if needed (depends on the specific JS driving the slideshow)
            const slideshow = mwSlideshow.querySelector('.slideshow');
            if (slideshow) {
                const observer = new MutationObserver(() => {
                    cleanSlideshowStyles(mwSlideshow);
                });
 
                observer.observe(slideshow, {
                    attributes: true,
                    attributeFilter: ['style'],
                    childList: false,
                    subtree: false
                });
            }
        });
    }
 
    // Run once DOM is ready (in case the slideshows are injected late)
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        initSlideshowFix();
     } else {
        document.addEventListener('DOMContentLoaded', initSlideshowFix);
    }
})();
/* Any JavaScript here will be loaded for all users on every page load. */
(function() {
    function cleanSlideshowStyles(slideshowContainer) {
        const slideshow = slideshowContainer.querySelector('.slideshow');
        if (slideshow) {
            // Remove inline styles on the main slideshow container
            slideshow.style.width = '';
            slideshow.style.height = '';
 
            // Remove inline styles on each slide div
            slideshow.querySelectorAll('div').forEach(slide => {
                slide.style.width = '';
                slide.style.height = '';
            });
        }
    }
 
    function initSlideshowFix() {
        // Locate all mw-jsslideshow instances
        document.querySelectorAll('.mw-jsslideshow').forEach(mwSlideshow => {
            // Clean styles on page load
            cleanSlideshowStyles(mwSlideshow);
 
            // Optional: Re-clean styles on window resize
            window.addEventListener('resize', () => {
                cleanSlideshowStyles(mwSlideshow);
            });
 
            // Hook into slide transitions if needed (depends on the specific JS driving the slideshow)
            const slideshow = mwSlideshow.querySelector('.slideshow');
            if (slideshow) {
                const observer = new MutationObserver(() => {
                    cleanSlideshowStyles(mwSlideshow);
                });
 
                observer.observe(slideshow, {
                    attributes: true,
                    attributeFilter: ['style'],
                    childList: false,
                    subtree: false
                });
            }
        });
    }
 
    // Run once DOM is ready (in case the slideshows are injected late)
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        initSlideshowFix();
    } else {
        document.addEventListener('DOMContentLoaded', initSlideshowFix);
    }
})();

Latest revision as of 02:36, 26 August 2025

$(function() {
  fetch('/api.php?action=query&meta=siteinfo&siprop=statistics&format=json')
    .then(res => res.json())
    .then(data => {
      const current = data.query.statistics.articles;
      const goal = 500;
      const left = goal - current;
      const el = document.getElementById("article-countdown");
      if (el) {
        el.innerHTML = left > 0
          ? `🚧 Only <strong>${left}</strong> articles to go until 500!`
          : `🎯 We've reached 500 articles! Celebrate good times, c'mon!`;
      }
    });
});
// MediaWiki:Common.js
mw.hook('rcfilters.ui.initialized').add(function () {
  document.documentElement.classList.add('rcfilters-ready');
});