MediaWiki:Common.js: Difference between revisions

From Ultimate Dragon Ball Online Wiki

Ravenalien (talk | contribs)
No edit summary
Ravenalien (talk | contribs)
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. */
/* Tab Navigation System */
/* Tab Navigation System */
(function() {
(function($) {
     'use strict';
     'use strict';
      
      
     // Initialize when document is ready
     function initializeTabs() {
    $(document).ready(function() {
        // Main Race Tab Navigation
        // Small delay to ensure everything is rendered
        $('.tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
        setTimeout(function() {
            e.preventDefault();
             initializeTabs();
            var $this = $(this);
             initializeSubTabs();
            var targetId = $this.data('target');
           
            // Remove active class from all main tab buttons and panes
            $this.closest('.tab-navigation')
                .find('> .tab-nav > .tab-button').removeClass('active');
            $this.closest('.tab-navigation')
                .siblings('.tab-content')
                .find('> .tab-pane').removeClass('active');
           
            // Add active class to clicked button and corresponding pane
             $this.addClass('active');
             $this.closest('.tab-navigation')
                .siblings('.tab-content')
                .find('> #' + targetId).addClass('active');
              
              
             // Make sure at least one tab is active
             // Reset sub-tabs to first tab when changing main tab
            enforceActiveTabsOnLoad();
            var $subTabNav = $('#' + targetId + ' .sub-tab-navigation');
        }, 200);
             if ($subTabNav.length) {
    });
                $subTabNav.find('> .tab-nav > .tab-button').removeClass('active');
   
                 $subTabNav.find('> .tab-nav > .tab-button').first().addClass('active');
    // Make sure there's always an active tab
               
    function enforceActiveTabsOnLoad() {
                 var firstSubTabId = $subTabNav.find('> .tab-nav > .tab-button').first().data('target');
        // Ensure main tabs have active tab
                 $subTabNav.find('> .tab-content > .tab-pane').removeClass('active');
        $('.tab-navigation').each(function() {
                $subTabNav.find('> .tab-content > #' + firstSubTabId).addClass('active');
             var $container = $(this);
            if ($container.find('> .tab-nav > .tab-button.active').length === 0) {
                 $container.find('> .tab-nav > .tab-button').first().addClass('active');
                 var firstTabId = $container.find('> .tab-nav > .tab-button').first().data('target');
                 $container.find('#' + firstTabId).addClass('active');
             }
             }
           
            return false;
         });
         });
          
          
         // Ensure sub tabs have active tab
         // Sub-Tab Navigation
         $('.sub-tab-navigation').each(function() {
         $('.sub-tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
             var $container = $(this);
            e.preventDefault();
             if ($container.find('> .tab-nav > .tab-button.active').length === 0) {
             var $this = $(this);
                 $container.find('> .tab-nav > .tab-button').first().addClass('active');
             var targetId = $this.data('target');
                var firstTabId = $container.find('> .tab-nav > .tab-button').first().data('target');
           
                 $container.find('#' + firstTabId).addClass('active');
            // Remove active class from all sub-tab buttons and panes
            }
            $this.closest('.sub-tab-navigation')
        });
                 .find('> .tab-nav > .tab-button').removeClass('active');
    }
            $this.closest('.sub-tab-navigation')
   
                 .find('> .tab-content > .tab-pane').removeClass('active');
    function initializeTabs() {
        // Find all tab containers on the page
        $('.tab-navigation').each(function(index) {
            var tabContainerId = 'tab-container-' + index;
            $(this).attr('id', tabContainerId);
              
              
             var $container = $('#' + tabContainerId);
             // Add active class to clicked button and corresponding pane
             var $tabButtons = $container.find('> .tab-nav > .tab-button');
            $this.addClass('active');
            var $tabPanes = $container.find('> .tab-content > .tab-pane');
             $this.closest('.sub-tab-navigation')
                .find('> .tab-content > #' + targetId).addClass('active');
              
              
             // Add click handlers to tab buttons
             return false;
            $tabButtons.off('click').on('click', function(e) {
                e.preventDefault();
                var $this = $(this);
                var targetId = $this.data('target');
               
                // Remove active class from all buttons and panes in this container
                $container.find('> .tab-nav > .tab-button').removeClass('active');
                $container.find('> .tab-content > .tab-pane').removeClass('active');
               
                // Add active class to clicked button and corresponding pane
                $this.addClass('active');
                $container.find('#' + targetId).addClass('active');
               
                // If this tab has a sub-tab that's active, ensure it's visible
                var $activeSubTab = $container.find('#' + targetId + ' .sub-tab-navigation .tab-button.active');
                if ($activeSubTab.length) {
                    $activeSubTab.trigger('click');
                }
               
                return false;
            });
         });
         });
     }
     }
      
      
     // Initialize nested sub-tabs
     // Initialize tabs when document is ready
     function initializeSubTabs() {
     $(document).ready(function() {
         $('.sub-tab-navigation').each(function(index) {
        initializeTabs();
             var subTabContainerId = 'sub-tab-container-' + index;
       
            $(this).attr('id', subTabContainerId);
        // Ensure at least one main tab and sub-tab is active
         $('.tab-navigation').each(function() {
             var $mainNavigation = $(this);
            if ($mainNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                $mainNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
            }
              
              
             var $container = $('#' + subTabContainerId);
             var activeMainTabId = $mainNavigation.find('> .tab-nav > .tab-button.active').data('target');
            var $tabButtons = $container.find('> .tab-nav > .tab-button');
             $mainNavigation.siblings('.tab-content')
             var $tabPanes = $container.find('> .tab-content > .tab-pane');
                .find('> #' + activeMainTabId).addClass('active');
              
              
             // Add click handlers to tab buttons
             // Handle sub-tabs within the active main tab
             $tabButtons.off('click').on('click', function(e) {
             var $subNavigation = $('#' + activeMainTabId + ' .sub-tab-navigation');
                e.preventDefault();
            if ($subNavigation.length) {
                var $this = $(this);
                 if ($subNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                var targetId = $this.data('target');
                    $subNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
               
                // Remove active class from all buttons and panes in this container
                 $container.find('> .tab-nav > .tab-button').removeClass('active');
                $container.find('> .tab-content > .tab-pane').removeClass('active');
               
                // Add active class to clicked button and corresponding pane
                $this.addClass('active');
                $container.find('#' + targetId).addClass('active');
               
                // Store the active tab state in session storage for persistence
                try {
                    sessionStorage.setItem('activeSubTab-' + subTabContainerId, targetId);
                } catch (e) {
                    console.log('Unable to save tab state to session storage');
                 }
                 }
                  
                  
                return false;
                 var activeSubTabId = $subNavigation.find('> .tab-nav > .tab-button.active').data('target');
            });
                $subNavigation.find('> .tab-content > .tab-pane').removeClass('active');
           
                 $subNavigation.find('> .tab-content > #' + activeSubTabId).addClass('active');
            // Check if there's a stored active tab
            try {
                 var activeTabId = sessionStorage.getItem('activeSubTab-' + subTabContainerId);
                if (activeTabId && $container.find('#' + activeTabId).length > 0) {
                    $container.find('.tab-button[data-target="' + activeTabId + '"]').trigger('click');
                 }
            } catch (e) {
                console.log('Unable to retrieve tab state from session storage');
             }
             }
         });
         });
     }
     });
})();
})(jQuery);


/* Add Tooltip functionality for map links */
/* Add Tooltip functionality for map links */

Revision as of 06:15, 26 February 2025

/* Any JavaScript here will be loaded for all users on every page load. */
/* Tab Navigation System */
(function($) {
    'use strict';
    
    function initializeTabs() {
        // Main Race Tab Navigation
        $('.tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
            e.preventDefault();
            var $this = $(this);
            var targetId = $this.data('target');
            
            // Remove active class from all main tab buttons and panes
            $this.closest('.tab-navigation')
                .find('> .tab-nav > .tab-button').removeClass('active');
            $this.closest('.tab-navigation')
                .siblings('.tab-content')
                .find('> .tab-pane').removeClass('active');
            
            // Add active class to clicked button and corresponding pane
            $this.addClass('active');
            $this.closest('.tab-navigation')
                .siblings('.tab-content')
                .find('> #' + targetId).addClass('active');
            
            // Reset sub-tabs to first tab when changing main tab
            var $subTabNav = $('#' + targetId + ' .sub-tab-navigation');
            if ($subTabNav.length) {
                $subTabNav.find('> .tab-nav > .tab-button').removeClass('active');
                $subTabNav.find('> .tab-nav > .tab-button').first().addClass('active');
                
                var firstSubTabId = $subTabNav.find('> .tab-nav > .tab-button').first().data('target');
                $subTabNav.find('> .tab-content > .tab-pane').removeClass('active');
                $subTabNav.find('> .tab-content > #' + firstSubTabId).addClass('active');
            }
            
            return false;
        });
        
        // Sub-Tab Navigation
        $('.sub-tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
            e.preventDefault();
            var $this = $(this);
            var targetId = $this.data('target');
            
            // Remove active class from all sub-tab buttons and panes
            $this.closest('.sub-tab-navigation')
                .find('> .tab-nav > .tab-button').removeClass('active');
            $this.closest('.sub-tab-navigation')
                .find('> .tab-content > .tab-pane').removeClass('active');
            
            // Add active class to clicked button and corresponding pane
            $this.addClass('active');
            $this.closest('.sub-tab-navigation')
                .find('> .tab-content > #' + targetId).addClass('active');
            
            return false;
        });
    }
    
    // Initialize tabs when document is ready
    $(document).ready(function() {
        initializeTabs();
        
        // Ensure at least one main tab and sub-tab is active
        $('.tab-navigation').each(function() {
            var $mainNavigation = $(this);
            if ($mainNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                $mainNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
            }
            
            var activeMainTabId = $mainNavigation.find('> .tab-nav > .tab-button.active').data('target');
            $mainNavigation.siblings('.tab-content')
                .find('> #' + activeMainTabId).addClass('active');
            
            // Handle sub-tabs within the active main tab
            var $subNavigation = $('#' + activeMainTabId + ' .sub-tab-navigation');
            if ($subNavigation.length) {
                if ($subNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                    $subNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
                }
                
                var activeSubTabId = $subNavigation.find('> .tab-nav > .tab-button.active').data('target');
                $subNavigation.find('> .tab-content > .tab-pane').removeClass('active');
                $subNavigation.find('> .tab-content > #' + activeSubTabId).addClass('active');
            }
        });
    });
})(jQuery);

/* Add Tooltip functionality for map links */
(function() {
    'use strict';
    
    $(document).ready(function() {
        $('span.material-button a').each(function() {
            var href = $(this).attr('href');
            if (href && href.indexOf('world-map') !== -1) {
                $(this).parent().attr('title', 'Click to view location on map');
                
                // Optional: Add map icon
                $(this).prepend('<span class="map-icon">🗺️ </span>');
            }
        });
    });
})();

/* Enhanced Image Previews */
(function() {
    'use strict';
    
    $(document).ready(function() {
        $('.thumbimage').on('mouseenter', function() {
            $(this).css('transform', 'scale(1.05)');
            $(this).css('transition', 'transform 0.3s ease');
            $(this).css('box-shadow', '0 8px 16px rgba(0,0,0,0.2)');
        }).on('mouseleave', function() {
            $(this).css('transform', '');
            $(this).css('box-shadow', '');
        });
    });
})();


/* Improve Mobile Experience */
(function() {
    'use strict';
    
    $(document).ready(function() {
        // Check if we're on a mobile device
        var isMobile = window.matchMedia("only screen and (max-width: 768px)").matches;
        
        if (isMobile) {
            // Make tab navigation scrollable on mobile
            $('.tab-nav').css({
                'overflow-x': 'auto',
                'white-space': 'nowrap',
                '-webkit-overflow-scrolling': 'touch'
            });
            
            // Ensure tab buttons don't wrap
            $('.tab-button').css({
                'display': 'inline-block',
                'float': 'none'
            });
            
            // Add slight delay to image hover effects for better mobile experience
            $('.thumbimage').each(function() {
                var $this = $(this);
                $this.on('touchstart', function() {
                    $this.css('transform', 'scale(1.05)');
                    $this.css('transition', 'transform 0.3s ease');
                    $this.css('box-shadow', '0 8px 16px rgba(0,0,0,0.2)');
                    
                    setTimeout(function() {
                        $this.css('transform', '');
                        $this.css('box-shadow', '');
                    }, 1000);
                });
            });
        }
    });
})();