MediaWiki:Common.js

Uit Klimaatwiki

Opmerking: na het publiceren moet je misschien je browsercache legen om de veranderingen te zien.

  • Firefox / Safari: houd Shift ingedrukt terwijl u:je op Vernieuwen klikt of druk op Ctrl-F5 of Ctrl-R (⌘-Shift-R op een Mac)
  • Google Chrome: druk op Ctrl-Shift-R (⌘-Shift-R op een Mac)
  • Edge: houd Ctrl ingedrukt terwijl u:je op Vernieuwen klikt of druk op Ctrl-F5.
/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers */

/* ---------- Reading progress bar script ---------- */
$(function () {
    // Create the bar element and insert it into the DOM
    const $bar = $('<div>', { id: 'readingProgress' }).appendTo('body');

    // Function that updates the bar width based on scroll position
    const updateProgress = () => {
        const docHeight   = $(document).height();
        const winHeight   = $(window).height();
        const scrollTop   = $(window).scrollTop();

        // Calculate percentage of page scrolled
        const percent = ((scrollTop + winHeight) / docHeight) * 100;

        // Set the bar width (capped at 100%)
        $bar.css('width', Math.min(percent, 100) + '%');
    };

    // Run once on load (in case the page is short enough to be fully visible)
    updateProgress();

    // Update on scroll and on window resize (the latter can affect heights)
    $(window).on('scroll resize', updateProgress);
});