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 7: Line 7:
         // Tab Navigation System
         // Tab Navigation System
         (function() {
         (function() {
             function initializeTabs() {
             // Main Race Tab Navigation
                // Main Race Tab Navigation
            $(document).on('click', '.tab-navigation > .tab-nav > .tab-button', function(e) {
                $('.tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
                e.preventDefault();
                    e.preventDefault();
                var $this = $(this);
                    var $this = $(this);
                var targetId = $this.data('target');
                    var targetId = $this.data('target');
               
                   
                // Remove active class from all main tab buttons
                    // Remove active class from all main tab buttons and panes
                $this.closest('.tab-nav').find('.tab-button').removeClass('active');
                    $this.closest('.tab-navigation')
                // Add active class to clicked button
                        .find('> .tab-nav > .tab-button').removeClass('active');
                $this.addClass('active');
                    $this.closest('.tab-navigation')
               
                        .siblings('.tab-content')
                // Remove active class from all main tab panes
                        .find('> .tab-pane').removeClass('active');
                $this.closest('.tab-navigation').next('.tab-content').find('> .tab-pane').removeClass('active');
                   
                // Add active class to target pane
                    // Add active class to clicked button and corresponding pane
                $('#' + targetId).addClass('active');
                    $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');
                    }
                });
                  
                  
                 // Sub-Tab Navigation
                 // Reset sub-tabs to first tab when changing main tab
                 $('.sub-tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
                 var $subTabNav = $('#' + targetId + ' .sub-tab-navigation');
                     e.preventDefault();
                if ($subTabNav.length) {
                    var $this = $(this);
                    // Reset sub-tab buttons
                     var targetId = $this.data('target');
                    var $firstSubButton = $subTabNav.find('> .tab-nav > .tab-button').first();
                     $subTabNav.find('> .tab-nav > .tab-button').removeClass('active');
                     $firstSubButton.addClass('active');
                      
                      
                     // Remove active class from all sub-tab buttons and panes
                     // Reset sub-tab panes
                     $this.closest('.sub-tab-navigation')
                     var firstSubTabId = $firstSubButton.data('target');
                        .find('> .tab-nav > .tab-button').removeClass('active');
                     $subTabNav.find('> .tab-content > .tab-pane').removeClass('active');
                     $this.closest('.sub-tab-navigation')
                     $('#' + firstSubTabId).addClass('active');
                        .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');
                 });
             }
              
              
             // Initialize tabs
             // Sub-Tab Navigation
             initializeTabs();
             $(document).on('click', '.sub-tab-navigation > .tab-nav > .tab-button', function(e) {
                e.preventDefault();
                var $this = $(this);
                var targetId = $this.data('target');
               
                // Remove active class from all sub-tab buttons and add to clicked
                $this.closest('.tab-nav').find('.tab-button').removeClass('active');
                $this.addClass('active');
               
                // Remove active class from all sub-tab panes and add to target
                $this.closest('.sub-tab-navigation').find('.tab-content > .tab-pane').removeClass('active');
                $('#' + targetId).addClass('active');
            });
              
              
             // Ensure at least one main tab and sub-tab is active
             // Ensure initial tab states are set
             $('.tab-navigation').each(function() {
             $('.tab-navigation').each(function() {
                 var $mainNavigation = $(this);
                 var $mainNav = $(this);
                 if ($mainNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                 var $mainButtons = $mainNav.find('> .tab-nav > .tab-button');
                     $mainNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
               
                // If no main tab is active, activate the first one
                if (!$mainButtons.filter('.active').length) {
                     $mainButtons.first().addClass('active');
                 }
                 }
                  
                  
                 var activeMainTabId = $mainNavigation.find('> .tab-nav > .tab-button.active').data('target');
                // Get active main tab's target
                 $mainNavigation.siblings('.tab-content')
                 var activeMainTabId = $mainButtons.filter('.active').data('target');
                     .find('> #' + activeMainTabId).addClass('active');
                 if (activeMainTabId) {
               
                    // Show active main tab's content
                // Handle sub-tabs within the active main tab
                     $('#' + activeMainTabId).addClass('active');
                var $subNavigation = $('#' + activeMainTabId + ' .sub-tab-navigation');
                   
                if ($subNavigation.length) {
                    // Handle sub-tabs within active main tab
                    if ($subNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                    var $subNav = $('#' + activeMainTabId + ' .sub-tab-navigation');
                         $subNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
                    if ($subNav.length) {
                        var $subButtons = $subNav.find('> .tab-nav > .tab-button');
                       
                        // If no sub-tab is active, activate the first one
                        if (!$subButtons.filter('.active').length) {
                            $subButtons.first().addClass('active');
                        }
                       
                         // Show active sub-tab's content
                        var activeSubTabId = $subButtons.filter('.active').data('target');
                        if (activeSubTabId) {
                            $('#' + activeSubTabId).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');
                 }
                 }
             });
             });
Line 92: Line 95:
                 if (href && href.indexOf('world-map') !== -1) {
                 if (href && href.indexOf('world-map') !== -1) {
                     $(this).parent().attr('title', 'Click to view location on map');
                     $(this).parent().attr('title', 'Click to view location on map');
                   
                    // Optional: Add map icon
                     $(this).prepend('<span class="map-icon">🗺️ </span>');
                     $(this).prepend('<span class="map-icon">🗺️ </span>');
                 }
                 }
Line 102: Line 103:
         (function() {
         (function() {
             $('.thumbimage').on('mouseenter', function() {
             $('.thumbimage').on('mouseenter', function() {
                 $(this).css('transform', 'scale(1.05)');
                 $(this).css({
                $(this).css('transition', 'transform 0.3s ease');
                    'transform': 'scale(1.05)',
                $(this).css('box-shadow', '0 8px 16px rgba(0,0,0,0.2)');
                    'transition': 'transform 0.3s ease',
                    'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                });
             }).on('mouseleave', function() {
             }).on('mouseleave', function() {
                 $(this).css('transform', '');
                 $(this).css({
                $(this).css('box-shadow', '');
                    'transform': '',
                    'box-shadow': ''
                });
             });
             });
         })();
         })();
Line 113: Line 118:
         // Improve Mobile Experience
         // Improve Mobile Experience
         (function() {
         (function() {
             // Check if we're on a mobile device
             if (window.matchMedia("only screen and (max-width: 768px)").matches) {
            var isMobile = window.matchMedia("only screen and (max-width: 768px)").matches;
           
            if (isMobile) {
                // Make tab navigation scrollable on mobile
                 $('.tab-nav').css({
                 $('.tab-nav').css({
                     'overflow-x': 'auto',
                     'overflow-x': 'auto',
Line 124: Line 125:
                 });
                 });
                  
                  
                // Ensure tab buttons don't wrap
                 $('.tab-button').css({
                 $('.tab-button').css({
                     'display': 'inline-block',
                     'display': 'inline-block',
Line 130: Line 130:
                 });
                 });
                  
                  
                // Add slight delay to image hover effects for better mobile experience
                 $('.thumbimage').each(function() {
                 $('.thumbimage').each(function() {
                     var $this = $(this);
                     var $this = $(this);
                     $this.on('touchstart', function() {
                     $this.on('touchstart', function() {
                         $this.css('transform', 'scale(1.05)');
                         $this.css({
                        $this.css('transition', 'transform 0.3s ease');
                            'transform': 'scale(1.05)',
                        $this.css('box-shadow', '0 8px 16px rgba(0,0,0,0.2)');
                            'transition': 'transform 0.3s ease',
                            'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                        });
                          
                          
                         setTimeout(function() {
                         setTimeout(function() {
                             $this.css('transform', '');
                             $this.css({
                            $this.css('box-shadow', '');
                                'transform': '',
                                'box-shadow': ''
                            });
                         }, 1000);
                         }, 1000);
                     });
                     });

Revision as of 06:29, 26 February 2025

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using(['jquery'], function ($) {
    'use strict';
    
    // Wait for DOM to be ready using MediaWiki hook
    mw.hook('dom.ready').add(function() {
        // Tab Navigation System
        (function() {
            // Main Race Tab Navigation
            $(document).on('click', '.tab-navigation > .tab-nav > .tab-button', function(e) {
                e.preventDefault();
                var $this = $(this);
                var targetId = $this.data('target');
                
                // Remove active class from all main tab buttons
                $this.closest('.tab-nav').find('.tab-button').removeClass('active');
                // Add active class to clicked button
                $this.addClass('active');
                
                // Remove active class from all main tab panes
                $this.closest('.tab-navigation').next('.tab-content').find('> .tab-pane').removeClass('active');
                // Add active class to target pane
                $('#' + targetId).addClass('active');
                
                // Reset sub-tabs to first tab when changing main tab
                var $subTabNav = $('#' + targetId + ' .sub-tab-navigation');
                if ($subTabNav.length) {
                    // Reset sub-tab buttons
                    var $firstSubButton = $subTabNav.find('> .tab-nav > .tab-button').first();
                    $subTabNav.find('> .tab-nav > .tab-button').removeClass('active');
                    $firstSubButton.addClass('active');
                    
                    // Reset sub-tab panes
                    var firstSubTabId = $firstSubButton.data('target');
                    $subTabNav.find('> .tab-content > .tab-pane').removeClass('active');
                    $('#' + firstSubTabId).addClass('active');
                }
            });
            
            // Sub-Tab Navigation
            $(document).on('click', '.sub-tab-navigation > .tab-nav > .tab-button', function(e) {
                e.preventDefault();
                var $this = $(this);
                var targetId = $this.data('target');
                
                // Remove active class from all sub-tab buttons and add to clicked
                $this.closest('.tab-nav').find('.tab-button').removeClass('active');
                $this.addClass('active');
                
                // Remove active class from all sub-tab panes and add to target
                $this.closest('.sub-tab-navigation').find('.tab-content > .tab-pane').removeClass('active');
                $('#' + targetId).addClass('active');
            });
            
            // Ensure initial tab states are set
            $('.tab-navigation').each(function() {
                var $mainNav = $(this);
                var $mainButtons = $mainNav.find('> .tab-nav > .tab-button');
                
                // If no main tab is active, activate the first one
                if (!$mainButtons.filter('.active').length) {
                    $mainButtons.first().addClass('active');
                }
                
                // Get active main tab's target
                var activeMainTabId = $mainButtons.filter('.active').data('target');
                if (activeMainTabId) {
                    // Show active main tab's content
                    $('#' + activeMainTabId).addClass('active');
                    
                    // Handle sub-tabs within active main tab
                    var $subNav = $('#' + activeMainTabId + ' .sub-tab-navigation');
                    if ($subNav.length) {
                        var $subButtons = $subNav.find('> .tab-nav > .tab-button');
                        
                        // If no sub-tab is active, activate the first one
                        if (!$subButtons.filter('.active').length) {
                            $subButtons.first().addClass('active');
                        }
                        
                        // Show active sub-tab's content
                        var activeSubTabId = $subButtons.filter('.active').data('target');
                        if (activeSubTabId) {
                            $('#' + activeSubTabId).addClass('active');
                        }
                    }
                }
            });
        })();

        // Add Tooltip functionality for map links
        (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');
                    $(this).prepend('<span class="map-icon">🗺️ </span>');
                }
            });
        })();

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

        // Improve Mobile Experience
        (function() {
            if (window.matchMedia("only screen and (max-width: 768px)").matches) {
                $('.tab-nav').css({
                    'overflow-x': 'auto',
                    'white-space': 'nowrap',
                    '-webkit-overflow-scrolling': 'touch'
                });
                
                $('.tab-button').css({
                    'display': 'inline-block',
                    'float': 'none'
                });
                
                $('.thumbimage').each(function() {
                    var $this = $(this);
                    $this.on('touchstart', function() {
                        $this.css({
                            'transform': 'scale(1.05)',
                            'transition': 'transform 0.3s ease',
                            'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                        });
                        
                        setTimeout(function() {
                            $this.css({
                                'transform': '',
                                'box-shadow': ''
                            });
                        }, 1000);
                    });
                });
            }
        })();
    });
});