MediaWiki:Common.js: Difference between revisions

From GamingAlliance - GTA RP Wiki
(Created page with "$(document).ready(function() { $('.tab').click(function() { $('.tab').removeClass('active'); $(this).addClass('active'); // Add logic to show/hide content if needed }); });")
 
No edit summary
 
Line 1: Line 1:
$(document).ready(function() {
$(document).ready(function() {
    // Tab switching
     $('.tab').click(function() {
     $('.tab').click(function() {
        // Remove active class from all tabs
         $('.tab').removeClass('active');
         $('.tab').removeClass('active');
        // Add active class to clicked tab
         $(this).addClass('active');
         $(this).addClass('active');
         // Add logic to show/hide content if needed
 
         // Content switching (if tabs control content)
        var tabId = $(this).data('tab'); // Assumes data-tab attribute (e.g., data-tab="tab1")
        if (tabId) {
            $('.tab-content').hide(); // Hide all tab content
            $('#' + tabId).show(); // Show content for active tab
        }
    });
 
    // Collapsible sections (only if native mw-collapsible is unavailable or customized)
    $('.mw-collapsible').each(function() {
        var $this = $(this);
        // Hide content initially
        $this.find('.mw-collapsible-content').hide();
        // Create toggle link if not present
        if (!$this.find('.mw-collapsible-toggle').length) {
            $this.prepend('<span class="mw-collapsible-toggle" style="cursor:pointer; color:blue; text-decoration:underline;">Expand</span>');
        }
        // Toggle on click
        $this.find('.mw-collapsible-toggle').click(function() {
            $this.toggleClass('mw-collapsed');
            var $content = $this.find('.mw-collapsible-content');
            $content.slideToggle();
            // Update toggle text
            $(this).text($content.is(':visible') ? 'Hide' : 'Expand');
        });
     });
     });
});
});

Latest revision as of 14:38, 11 May 2025

$(document).ready(function() {
    // Tab switching
    $('.tab').click(function() {
        // Remove active class from all tabs
        $('.tab').removeClass('active');
        // Add active class to clicked tab
        $(this).addClass('active');

        // Content switching (if tabs control content)
        var tabId = $(this).data('tab'); // Assumes data-tab attribute (e.g., data-tab="tab1")
        if (tabId) {
            $('.tab-content').hide(); // Hide all tab content
            $('#' + tabId).show(); // Show content for active tab
        }
    });

    // Collapsible sections (only if native mw-collapsible is unavailable or customized)
    $('.mw-collapsible').each(function() {
        var $this = $(this);
        // Hide content initially
        $this.find('.mw-collapsible-content').hide();
        // Create toggle link if not present
        if (!$this.find('.mw-collapsible-toggle').length) {
            $this.prepend('<span class="mw-collapsible-toggle" style="cursor:pointer; color:blue; text-decoration:underline;">Expand</span>');
        }
        // Toggle on click
        $this.find('.mw-collapsible-toggle').click(function() {
            $this.toggleClass('mw-collapsed');
            var $content = $this.find('.mw-collapsible-content');
            $content.slideToggle();
            // Update toggle text
            $(this).text($content.is(':visible') ? 'Hide' : 'Expand');
        });
    });
});