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 */
mw.loader.using(['jquery'], function ($) {
(function($) {
     'use strict';
     'use strict';
      
      
     function initializeTabs() {
     // Wait for DOM to be ready using MediaWiki hook
        // Main Race Tab Navigation
    mw.hook('dom.ready').add(function() {
        $('.tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
        // Tab Navigation System
            e.preventDefault();
        (function() {
            var $this = $(this);
            function initializeTabs() {
            var targetId = $this.data('target');
                // Main Race Tab Navigation
           
                $('.tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
            // Remove active class from all main tab buttons and panes
                    e.preventDefault();
            $this.closest('.tab-navigation')
                    var $this = $(this);
                .find('> .tab-nav > .tab-button').removeClass('active');
                    var targetId = $this.data('target');
            $this.closest('.tab-navigation')
                   
                .siblings('.tab-content')
                    // Remove active class from all main tab buttons and panes
                .find('> .tab-pane').removeClass('active');
                    $this.closest('.tab-navigation')
           
                        .find('> .tab-nav > .tab-button').removeClass('active');
            // Add active class to clicked button and corresponding pane
                    $this.closest('.tab-navigation')
            $this.addClass('active');
                        .siblings('.tab-content')
            $this.closest('.tab-navigation')
                        .find('> .tab-pane').removeClass('active');
                .siblings('.tab-content')
                   
                .find('> #' + targetId).addClass('active');
                    // Add active class to clicked button and corresponding pane
           
                    $this.addClass('active');
            // Reset sub-tabs to first tab when changing main tab
                    $this.closest('.tab-navigation')
            var $subTabNav = $('#' + targetId + ' .sub-tab-navigation');
                        .siblings('.tab-content')
            if ($subTabNav.length) {
                        .find('> #' + targetId).addClass('active');
                $subTabNav.find('> .tab-nav > .tab-button').removeClass('active');
                   
                $subTabNav.find('> .tab-nav > .tab-button').first().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');
                    }
                });
                  
                  
                 var firstSubTabId = $subTabNav.find('> .tab-nav > .tab-button').first().data('target');
                 // Sub-Tab Navigation
                $subTabNav.find('> .tab-content > .tab-pane').removeClass('active');
                $('.sub-tab-navigation > .tab-nav > .tab-button').on('click', function(e) {
                $subTabNav.find('> .tab-content > #' + firstSubTabId).addClass('active');
                    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
        });
             initializeTabs();
       
        // 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
             // Ensure at least one main tab and sub-tab is active
            $this.closest('.sub-tab-navigation')
            $('.tab-navigation').each(function() {
                .find('> .tab-nav > .tab-button').removeClass('active');
                var $mainNavigation = $(this);
            $this.closest('.sub-tab-navigation')
                if ($mainNavigation.find('> .tab-nav > .tab-button.active').length === 0) {
                .find('> .tab-content > .tab-pane').removeClass('active');
                    $mainNavigation.find('> .tab-nav > .tab-button').first().addClass('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');
                 var activeMainTabId = $mainNavigation.find('> .tab-nav > .tab-button.active').data('target');
                 $subNavigation.find('> .tab-content > .tab-pane').removeClass('active');
                 $mainNavigation.siblings('.tab-content')
                $subNavigation.find('> .tab-content > #' + activeSubTabId).addClass('active');
                    .find('> #' + activeMainTabId).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
                 // Handle sub-tabs within the active main tab
                 $(this).prepend('<span class="map-icon">🗺️ </span>');
                 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');
                }
            });
        })();


/* Enhanced Image Previews */
        // Add Tooltip functionality for map links
(function() {
        (function() {
    'use strict';
            $('span.material-button a').each(function() {
   
                var href = $(this).attr('href');
    $(document).ready(function() {
                if (href && href.indexOf('world-map') !== -1) {
        $('.thumbimage').on('mouseenter', function() {
                    $(this).parent().attr('title', 'Click to view location on map');
            $(this).css('transform', 'scale(1.05)');
                   
            $(this).css('transition', 'transform 0.3s ease');
                    // Optional: Add map icon
            $(this).css('box-shadow', '0 8px 16px rgba(0,0,0,0.2)');
                    $(this).prepend('<span class="map-icon">🗺️ </span>');
        }).on('mouseleave', function() {
                }
            $(this).css('transform', '');
            });
            $(this).css('box-shadow', '');
        })();
        });
    });
})();


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

Revision as of 06:27, 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() {
            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');
                    }
                });
                
                // 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');
                });
            }
            
            // Initialize tabs
            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');
                }
            });
        })();

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

        // Enhanced Image Previews
        (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() {
            // 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);
                    });
                });
            }
        })();
    });
});