Jump to content

MediaWiki:Common.js: Difference between revisions

From Continuum Universes Wiki
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js');
$(function() {
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css', 'text/css');
  fetch('/api.php?action=query&meta=siteinfo&siprop=statistics&format=json')
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.css', 'text/css');
    .then(res => res.json())
mw.loader.load('/extensions/JavascriptSlideshow/js/slideshow.js');
     .then(data => {
 
      const current = data.query.statistics.articles;
mw.hook('wikipage.content').add(function($content) {
      const goal = 500;
     $content.find('.mw-jsslideshow').each(function() {
      const left = goal - current;
        const $slideshowContainer = $(this);
      const el = document.getElementById("article-countdown");
        const $slideshow = $('<div class="slideshow"></div>');
      if (el) {
 
         el.innerHTML = left > 0
        // Find all images inside mw-jsslideshow, including [[File:]] images
          ? `🚧 Only <strong>${left}</strong> articles to go until 500!`
        $slideshowContainer.find('img').each(function() {
          : `🎯 We've reached 500 articles! Celebrate good times, c'mon!`;
            const $img = $(this);
      }
            const $slide = $('<div></div>').append($img.clone()); // Wrap in slide div
            $slideshow.append($slide);
         });
 
        // Replace old content with the new slick-ready slideshow
        $slideshowContainer.empty().append($slideshow);
 
        // Initialize slick
        $slideshow.slick({
            infinite: true,
            slidesToShow: 1,
            slidesToScroll: 1,
            autoplay: true,
            autoplaySpeed: 5000,
            arrows: true,
            dots: true,
            adaptiveHeight: true
        });
 
        // Fix positioning on resize
        $(window).on('resize', function() {
            $slideshow.slick('setPosition');
        });
     });
     });
});
});
function waitForStartSlideshow(callback) {
// MediaWiki:Common.js
    if (typeof startSlideshow === 'function') {
mw.hook('rcfilters.ui.initialized').add(function () {
        callback();
  document.documentElement.classList.add('rcfilters-ready');
    } else {
        setTimeout(function() {
            waitForStartSlideshow(callback);
        }, 100); // Try every 100ms
    }
}
 
function initMissingSlideshows() {
    var counter = 1;
 
    $('.slideshow').each(function() {
        var $this = $(this);
        if (!$this.attr('id')) {
            var newId = 'slideshow-auto-' + (counter++);
            $this.attr('id', newId);
 
            if ($('#' + newId + '-spacer').length === 0) {
                $('<div>')
                    .attr('id', newId + '-spacer')
                    .insertAfter($this);
            }
 
            // Call the slideshow init AFTER we confirm startSlideshow exists
            waitForStartSlideshow(function() {
                startSlideshow(newId);
            });
        }
    });
}
 
$(document).ready(function() {
    mw.loader.load('/extensions/JavascriptSlideshow/js/slideshow.js');
 
    // Start initializing after ensuring the script is there
    waitForStartSlideshow(initMissingSlideshows);
});
 
$(document).ready(function() {
    var counter = 1;
 
    $('.slideshow').each(function() {
        var $this = $(this);
        if (!$this.attr('id')) {
            // Assign an auto id if missing
            var newId = 'slideshow-auto-' + (counter++);
            $this.attr('id', newId);
 
            // Add the missing spacer
            if ($('#' + newId + '-spacer').length === 0) {
                $('<div>')
                    .attr('id', newId + '-spacer')
                    .insertAfter($this);
            }
 
            // Force JavascriptSlideshow to initialize this slideshow
            startSlideshow(newId);
        }
    });
});
});

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');
});