MediaWiki:Common.js: Difference between revisions

From PoliticalSG
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: $(function () { $('#toc').addClass('sidebar-toc'); $('#toc ul').addClass('treeview'); // Highlight current section (optional) $(window).on('scroll', function () { var currentSection = null; $('#toc li').each(function () { var section = $(this).find('a').attr('href'); if ($(section).offset().top <= $(window).scrollTop()) {...")
 
No edit summary
 
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
    $('#toc').addClass('sidebar-toc');
    $('#toc ul').addClass('treeview');
   
    // Highlight current section (optional)
    $(window).on('scroll', function () {
        var currentSection = null;
        $('#toc li').each(function () {
            var section = $(this).find('a').attr('href');
            if ($(section).offset().top <= $(window).scrollTop()) {
                currentSection = section;
            }
        });
        $('#toc li').removeClass('active');
        if (currentSection) {
            $('#toc a[href="' + currentSection + '"]').parent().addClass('active');
        }
    });
});

Latest revision as of 17:39, 16 November 2024

/* Any JavaScript here will be loaded for all users on every page load. */