MediaWiki:Common.js: Difference between revisions

From Ultimate Dragon Ball Online Wiki

Ravenalien (talk | contribs)
No edit summary
Ravenalien (talk | contribs)
No edit summary
 
(13 intermediate revisions by the same user not shown)
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. */
mw.loader.using(['jquery'], function ($) {
 
$(document).ready(function() {
     'use strict';
     'use strict';
      
      
     // Wait for DOM to be ready using MediaWiki hook
     // Main race tab click handler (works for both regular and image buttons)
     mw.hook('dom.ready').add(function() {
     $('.tab-navigation .tab-button, .tab-navigation .tab-button-image').click(function(e) {
        // Tab Navigation System
        e.preventDefault();
        (function() {
       
            function initializeTabs() {
        var targetId = $(this).data('target');
                // Main Race Tab Navigation
       
                $('.tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
        // Update main race tabs (for both button types)
                    e.preventDefault();
        $('.tab-navigation .tab-button, .tab-navigation .tab-button-image').removeClass('active');
                    var $this = $(this);
        $(this).addClass('active');
                    var targetId = $this.data('target');
       
                   
        // Update main content panes
                    // Remove active class from all main tab buttons and panes
        $('.tab-content > .tab-pane').removeClass('active');
                    $this.closest('.tab-navigation')
        $('#' + targetId).addClass('active');
                        .find('> .tab-nav > .tab-button').removeClass('active');
       
                    $this.closest('.tab-navigation')
        // Always activate the overview tab for the selected race
                        .siblings('.tab-content')
        var $subNav = $('#' + targetId + ' .sub-tab-navigation');
                        .find('> .tab-pane').removeClass('active');
        var $overviewTab;
                   
       
                    // Add active class to clicked button and corresponding pane
        // Check if using image tabs or regular tabs
                    $this.addClass('active');
        if ($subNav.find('.tab-button-image').length) {
                    $this.closest('.tab-navigation')
            $overviewTab = $subNav.find('.tab-button-image').first();
                        .siblings('.tab-content')
        } else {
                        .find('> #' + targetId).addClass('active');
            $overviewTab = $subNav.find('.tab-button').first();
                   
        }
                    // Reset sub-tabs to first tab when changing main tab
       
                    var $subTabNav = $('#' + targetId + ' .sub-tab-navigation');
        var overviewTargetId = $overviewTab.data('target');
                    if ($subTabNav.length) {
       
                        $subTabNav.find('> .tab-nav > .tab-button').removeClass('active');
        // Set overview tab and content as active
                        $subTabNav.find('> .tab-nav > .tab-button').first().addClass('active');
        $subNav.find('.tab-button, .tab-button-image').removeClass('active');
                       
        $overviewTab.addClass('active');
                        var firstSubTabId = $subTabNav.find('> .tab-nav > .tab-button').first().data('target');
       
                        $subTabNav.find('> .tab-content > .tab-pane').removeClass('active');
        $subNav.find('.tab-content .tab-pane').removeClass('active');
                        $subTabNav.find('> .tab-content > #' + firstSubTabId).addClass('active');
        $('#' + overviewTargetId).addClass('active');
                    }
    });
                });
   
               
    // Create collapsible sections
                // Sub-Tab Navigation
    $('.collapsible-header').click(function() {
                $('.sub-tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
        $(this).toggleClass('collapsed');
                    e.preventDefault();
        $(this).next('.collapsible-content').slideToggle(300);
                    var $this = $(this);
       
                    var targetId = $this.data('target');
        // Toggle the icon
                   
        var $icon = $(this).find('.collapse-icon');
                    // Remove active class from all sub-tab buttons and panes
        if ($icon.text() === '▼') {
                    $this.closest('.sub-tab-navigation')
            $icon.text('►');
                        .find('> .tab-nav > .tab-button').removeClass('active');
        } else {
                    $this.closest('.sub-tab-navigation')
            $icon.text('');
                        .find('> .tab-content > .tab-pane').removeClass('active');
        }
                   
    });
                    // Add active class to clicked button and corresponding pane
   
                    $this.addClass('active');
    // Initialize all sections as expanded
                    $this.closest('.sub-tab-navigation')
    $('.collapsible-header').each(function() {
                        .find('> .tab-content > #' + targetId).addClass('active');
        $(this).find('.collapse-icon').text('');
                 });
    });
   
    // Sub-class tab click handler (works for both regular and image buttons)
    $('.sub-tab-navigation .tab-button, .sub-tab-navigation .tab-button-image').click(function(e) {
        e.preventDefault();
        e.stopPropagation();
       
        var $this = $(this);
        var $subNav = $this.closest('.sub-tab-navigation');
        var targetId = $this.data('target');
       
        // Only update the buttons in this sub-tab navigation
        $subNav.find('.tab-button, .tab-button-image').removeClass('active');
        $this.addClass('active');
       
        // Find and update only the content panes within this sub-tab section
        $subNav.find('.tab-content .tab-pane').removeClass('active');
        $('#' + targetId).addClass('active');
       
        // Keep the parent tab-pane active
        $this.closest('.tab-pane').addClass('active');
    });
   
    // Initial setup
    function initializeTabs() {
        // Set first race tab active if none are
        var $mainNav = $('.tab-navigation');
        if (!$mainNav.find('.tab-button.active, .tab-button-image.active').length) {
            if ($mainNav.find('.tab-button-image').length) {
                var $firstMainTab = $mainNav.find('.tab-button-image').first();
                $firstMainTab.addClass('active');
            } else {
                var $firstMainTab = $mainNav.find('.tab-button').first();
                $firstMainTab.addClass('active');
            }
           
            var mainTargetId = $firstMainTab.data('target');
            $('#' + mainTargetId).addClass('active');
           
            // Set its overview tab active
            var $subNav = $('#' + mainTargetId + ' .sub-tab-navigation');
            var $overviewTab;
           
            // Check if using image tabs or regular tabs
            if ($subNav.find('.tab-button-image').length) {
                $overviewTab = $subNav.find('.tab-button-image').first();
            } else {
                 $overviewTab = $subNav.find('.tab-button').first();
             }
             }
              
              
             // Initialize tabs
             $overviewTab.addClass('active');
             initializeTabs();
            $('#' + $overviewTab.data('target')).addClass('active');
        }
       
        // For each race tab that's active
        $('.tab-navigation .tab-button.active, .tab-navigation .tab-button-image.active').each(function() {
            var mainTargetId = $(this).data('target');
             var $mainContent = $('#' + mainTargetId);
              
              
             // Ensure at least one main tab and sub-tab is active
             // Ensure overview tab is active if no sub-tab is active
             $('.tab-navigation').each(function() {
             var $subNav = $mainContent.find('.sub-tab-navigation');
                 var $mainNavigation = $(this);
            if ($subNav.length && !$subNav.find('.tab-button.active, .tab-button-image.active').length) {
                 if ($mainNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                 var $overviewTab;
                     $mainNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
               
                // Check if using image tabs or regular tabs
                 if ($subNav.find('.tab-button-image').length) {
                     $overviewTab = $subNav.find('.tab-button-image').first();
                } else {
                    $overviewTab = $subNav.find('.tab-button').first();
                 }
                 }
                  
                  
                 var activeMainTabId = $mainNavigation.find('> .tab-nav > .tab-button.active').data('target');
                 $overviewTab.addClass('active');
                 $mainNavigation.siblings('.tab-content')
                 $('#' + $overviewTab.data('target')).addClass('active');
                    .find('> #' + activeMainTabId).addClass('active');
            }
               
        });
                // Handle sub-tabs within the active main tab
    }
                var $subNavigation = $('#' + activeMainTabId + ' .sub-tab-navigation');
   
                if ($subNavigation.length) {
    // Run initial setup
                    if ($subNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
    initializeTabs();
                        $subNavigation.find('> .tab-nav > .tab-button').first().addClass('active');
   
                    }
    // Add animation effect when switching tabs
                   
    $('.tab-button, .tab-button-image').click(function() {
                    var activeSubTabId = $subNavigation.find('> .tab-nav > .tab-button.active').data('target');
        $('.tab-pane.active').css('animation', 'tabFadeIn 0.3s');
                    $subNavigation.find('> .tab-content > .tab-pane').removeClass('active');
        setTimeout(function() {
                    $subNavigation.find('> .tab-content > #' + activeSubTabId).addClass('active');
            $('.tab-pane.active').css('animation', '');
                }
        }, 300);
            });
    });
         })();
   
 
    // Add image button hover effect
        // Add Tooltip functionality for map links
    $('.tab-button-image').hover(function() {
        (function() {
        if (!$(this).hasClass('active')) {
            $('span.material-button a').each(function() {
            $(this).find('img').css('opacity', '0.8');
                var href = $(this).attr('href');
        }
                if (href && href.indexOf('world-map') !== -1) {
    }, function() {
                    $(this).parent().attr('title', 'Click to view location on map');
         $(this).find('img').css('opacity', '1');
                   
    });
                    // Optional: Add map icon
   
                    $(this).prepend('<span class="map-icon">🗺️ </span>');
    // Add map tooltips
                }
    $('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');
        // Enhanced Image Previews
            $(this).prepend('<span class="map-icon">🗺️ </span>');
        (function() {
        }
            $('.thumbimage').on('mouseenter', function() {
    });
                $(this).css('transform', 'scale(1.05)');
   
                $(this).css('transition', 'transform 0.3s ease');
    // Enhanced Image Previews
                $(this).css('box-shadow', '0 8px 16px rgba(0,0,0,0.2)');
    $('.thumbimage').hover(function() {
             }).on('mouseleave', function() {
        $(this).css({
                $(this).css('transform', '');
            'transform': 'scale(1.05)',
                $(this).css('box-shadow', '');
            'transition': 'transform 0.3s ease',
            'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
        });
    }, function() {
        $(this).css({
             'transform': '',
            'box-shadow': ''
        });
    });
   
    // Mobile Experience Optimization
    if (window.matchMedia("only screen and (max-width: 768px)").matches) {
        // Make tab navigation scrollable
        $('.tab-nav').css({
            'overflow-x': 'auto',
            'white-space': 'nowrap',
            '-webkit-overflow-scrolling': 'touch'
        });
       
        // Ensure tab buttons don't wrap
        $('.tab-button, .tab-button-image').css({
            'display': 'inline-block',
            'float': 'none'
        });
       
        // Adjust image button sizes for mobile
        $('.tab-button-image').css({
            'width': '100px',
            'height': '70px'
        });
       
        // Touch-friendly image previews
        $('.thumbimage, .tab-button-image').on('touchstart', function() {
            var $this = $(this);
            $this.css({
                'transform': 'scale(1.05)',
                'transition': 'transform 0.3s ease',
                'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
             });
             });
        })();
        // Improve Mobile Experience
        (function() {
            // Check if we're on a mobile device
            var isMobile = window.matchMedia("only screen and (max-width: 768px)").matches;
              
              
             if (isMobile) {
             setTimeout(function() {
                // Make tab navigation scrollable on mobile
                 $this.css({
                 $('.tab-nav').css({
                     'transform': '',
                     'overflow-x': 'auto',
                     'box-shadow': ''
                     'white-space': 'nowrap',
                    '-webkit-overflow-scrolling': 'touch'
                 });
                 });
               
            }, 1000);
                // Ensure tab buttons don't wrap
        });
                $('.tab-button').css({
    }
                    'display': 'inline-block',
   
                    'float': 'none'
    // Add preload for tab images to prevent flickering on first load
                });
    function preloadTabImages() {
               
        $('.tab-button-image img').each(function() {
                // Add slight delay to image hover effects for better mobile experience
            var img = new Image();
                $('.thumbimage').each(function() {
            img.src = $(this).attr('src');
                    var $this = $(this);
        });
                    $this.on('touchstart', function() {
    }
                        $this.css('transform', 'scale(1.05)');
   
                        $this.css('transition', 'transform 0.3s ease');
    // Run preload
                        $this.css('box-shadow', '0 8px 16px rgba(0,0,0,0.2)');
     preloadTabImages();
                       
                        setTimeout(function() {
                            $this.css('transform', '');
                            $this.css('box-shadow', '');
                        }, 1000);
                    });
                });
            }
        })();
     });
});
});

Latest revision as of 20:37, 1 March 2025

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

$(document).ready(function() {
    'use strict';
    
    // Main race tab click handler (works for both regular and image buttons)
    $('.tab-navigation .tab-button, .tab-navigation .tab-button-image').click(function(e) {
        e.preventDefault();
        
        var targetId = $(this).data('target');
        
        // Update main race tabs (for both button types)
        $('.tab-navigation .tab-button, .tab-navigation .tab-button-image').removeClass('active');
        $(this).addClass('active');
        
        // Update main content panes
        $('.tab-content > .tab-pane').removeClass('active');
        $('#' + targetId).addClass('active');
        
        // Always activate the overview tab for the selected race
        var $subNav = $('#' + targetId + ' .sub-tab-navigation');
        var $overviewTab;
        
        // Check if using image tabs or regular tabs
        if ($subNav.find('.tab-button-image').length) {
            $overviewTab = $subNav.find('.tab-button-image').first();
        } else {
            $overviewTab = $subNav.find('.tab-button').first();
        }
        
        var overviewTargetId = $overviewTab.data('target');
        
        // Set overview tab and content as active
        $subNav.find('.tab-button, .tab-button-image').removeClass('active');
        $overviewTab.addClass('active');
        
        $subNav.find('.tab-content .tab-pane').removeClass('active');
        $('#' + overviewTargetId).addClass('active');
    });
    
    // Create collapsible sections
    $('.collapsible-header').click(function() {
        $(this).toggleClass('collapsed');
        $(this).next('.collapsible-content').slideToggle(300);
        
        // Toggle the icon
        var $icon = $(this).find('.collapse-icon');
        if ($icon.text() === '▼') {
            $icon.text('►');
        } else {
            $icon.text('▼');
        }
    });
    
    // Initialize all sections as expanded
    $('.collapsible-header').each(function() {
        $(this).find('.collapse-icon').text('▼');
    });
    
    // Sub-class tab click handler (works for both regular and image buttons)
    $('.sub-tab-navigation .tab-button, .sub-tab-navigation .tab-button-image').click(function(e) {
        e.preventDefault();
        e.stopPropagation();
        
        var $this = $(this);
        var $subNav = $this.closest('.sub-tab-navigation');
        var targetId = $this.data('target');
        
        // Only update the buttons in this sub-tab navigation
        $subNav.find('.tab-button, .tab-button-image').removeClass('active');
        $this.addClass('active');
        
        // Find and update only the content panes within this sub-tab section
        $subNav.find('.tab-content .tab-pane').removeClass('active');
        $('#' + targetId).addClass('active');
        
        // Keep the parent tab-pane active
        $this.closest('.tab-pane').addClass('active');
    });
    
    // Initial setup
    function initializeTabs() {
        // Set first race tab active if none are
        var $mainNav = $('.tab-navigation');
        if (!$mainNav.find('.tab-button.active, .tab-button-image.active').length) {
            if ($mainNav.find('.tab-button-image').length) {
                var $firstMainTab = $mainNav.find('.tab-button-image').first();
                $firstMainTab.addClass('active');
            } else {
                var $firstMainTab = $mainNav.find('.tab-button').first();
                $firstMainTab.addClass('active');
            }
            
            var mainTargetId = $firstMainTab.data('target');
            $('#' + mainTargetId).addClass('active');
            
            // Set its overview tab active
            var $subNav = $('#' + mainTargetId + ' .sub-tab-navigation');
            var $overviewTab;
            
            // Check if using image tabs or regular tabs
            if ($subNav.find('.tab-button-image').length) {
                $overviewTab = $subNav.find('.tab-button-image').first();
            } else {
                $overviewTab = $subNav.find('.tab-button').first();
            }
            
            $overviewTab.addClass('active');
            $('#' + $overviewTab.data('target')).addClass('active');
        }
        
        // For each race tab that's active
        $('.tab-navigation .tab-button.active, .tab-navigation .tab-button-image.active').each(function() {
            var mainTargetId = $(this).data('target');
            var $mainContent = $('#' + mainTargetId);
            
            // Ensure overview tab is active if no sub-tab is active
            var $subNav = $mainContent.find('.sub-tab-navigation');
            if ($subNav.length && !$subNav.find('.tab-button.active, .tab-button-image.active').length) {
                var $overviewTab;
                
                // Check if using image tabs or regular tabs
                if ($subNav.find('.tab-button-image').length) {
                    $overviewTab = $subNav.find('.tab-button-image').first();
                } else {
                    $overviewTab = $subNav.find('.tab-button').first();
                }
                
                $overviewTab.addClass('active');
                $('#' + $overviewTab.data('target')).addClass('active');
            }
        });
    }
    
    // Run initial setup
    initializeTabs();
    
    // Add animation effect when switching tabs
    $('.tab-button, .tab-button-image').click(function() {
        $('.tab-pane.active').css('animation', 'tabFadeIn 0.3s');
        setTimeout(function() {
            $('.tab-pane.active').css('animation', '');
        }, 300);
    });
    
    // Add image button hover effect
    $('.tab-button-image').hover(function() {
        if (!$(this).hasClass('active')) {
            $(this).find('img').css('opacity', '0.8');
        }
    }, function() {
        $(this).find('img').css('opacity', '1');
    });
    
    // Add map tooltips
    $('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
    $('.thumbimage').hover(function() {
        $(this).css({
            'transform': 'scale(1.05)',
            'transition': 'transform 0.3s ease',
            'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
        });
    }, function() {
        $(this).css({
            'transform': '',
            'box-shadow': ''
        });
    });
    
    // Mobile Experience Optimization
    if (window.matchMedia("only screen and (max-width: 768px)").matches) {
        // Make tab navigation scrollable
        $('.tab-nav').css({
            'overflow-x': 'auto',
            'white-space': 'nowrap',
            '-webkit-overflow-scrolling': 'touch'
        });
        
        // Ensure tab buttons don't wrap
        $('.tab-button, .tab-button-image').css({
            'display': 'inline-block',
            'float': 'none'
        });
        
        // Adjust image button sizes for mobile
        $('.tab-button-image').css({
            'width': '100px',
            'height': '70px'
        });
        
        // Touch-friendly image previews
        $('.thumbimage, .tab-button-image').on('touchstart', function() {
            var $this = $(this);
            $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);
        });
    }
    
    // Add preload for tab images to prevent flickering on first load
    function preloadTabImages() {
        $('.tab-button-image img').each(function() {
            var img = new Image();
            img.src = $(this).attr('src');
        });
    }
    
    // Run preload
    preloadTabImages();
});