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. */
mw.loader.using(['jquery', 'mediawiki.util'], function ($, util) {
mw.loader.using(['jquery', 'mediawiki.util']).done(function ($) {
     'use strict';
     'use strict';


     // Wait for both DOM and stylesheets to be ready
     // Wait for wiki content to be ready
     $(window).on('load', function() {
     mw.hook('wikipage.content').add(function($content) {
         console.log('Window fully loaded, initializing tabs');
         console.log('Setting up tab navigation');
          
          
         // Ensure we're running after all MediaWiki resources are ready
         try {
        mw.hook('wikipage.content').add(function($content) {
             // Main tabs (Race selection)
             console.log('Wiki content ready, setting up tabs');
            $content.find('.tab-button').on('click', function(e) {
           
                e.preventDefault();
            try {
                var targetId = $(this).data('target');
                // Main tabs (Race selection)
                if (!targetId) return;
                $content.find('.tab-button').on('click', function(e) {
                    e.preventDefault();
                    console.log('Tab clicked:', $(this).data('target'));
                   
                    var targetId = $(this).data('target');
                    if (!targetId) {
                        console.error('No target ID found for tab');
                        return;
                    }


                    // Handle main tab navigation
                // Handle main tab navigation
                    if ($(this).closest('.tab-navigation').length) {
                if ($(this).closest('.tab-navigation').length) {
                        // Remove active class from all main tabs and contents
                    // Update main tabs
                        $('.tab-navigation .tab-button').removeClass('active');
                    $('.tab-navigation .tab-button').removeClass('active');
                        $('.tab-content .tab-pane').removeClass('active');
                    $('.tab-content .tab-pane').removeClass('active');
                       
                    $(this).addClass('active');
                        // Activate clicked tab and its content
                    $('#' + targetId).addClass('active');
                        $(this).addClass('active');
                        $('#' + targetId).addClass('active');


                        // Reset sub-tabs
                    // Reset sub-tabs
                        var $subNav = $('#' + targetId).find('.sub-tab-navigation');
                    var $subNav = $('#' + targetId).find('.sub-tab-navigation');
                        if ($subNav.length) {
                    if ($subNav.length) {
                            var $firstSubTab = $subNav.find('.tab-button').first();
                        var $firstSubTab = $subNav.find('.tab-button').first();
                            var firstSubTargetId = $firstSubTab.data('target');
                        $subNav.find('.tab-button').removeClass('active');
                           
                        $firstSubTab.addClass('active');
                            // Activate first sub-tab
                            $subNav.find('.tab-button').removeClass('active');
                            $firstSubTab.addClass('active');
                           
                            // Activate first sub-tab content
                            $subNav.find('.tab-pane').removeClass('active');
                            $('#' + firstSubTargetId).addClass('active');
                        }
                    }
                    // Handle sub-tab navigation
                    else if ($(this).closest('.sub-tab-navigation').length) {
                        var $subNav = $(this).closest('.sub-tab-navigation');
                          
                          
                         // Remove active class from sibling tabs and contents
                         var firstSubTargetId = $firstSubTab.data('target');
                        $subNav.find('.tab-button').removeClass('active');
                         $subNav.find('.tab-pane').removeClass('active');
                         $subNav.find('.tab-pane').removeClass('active');
                       
                         $('#' + firstSubTargetId).addClass('active');
                        // Activate clicked tab and its content
                        $(this).addClass('active');
                         $('#' + targetId).addClass('active');
                     }
                     }
                 });
                 }
                // Handle sub-tab navigation
                else if ($(this).closest('.sub-tab-navigation').length) {
                    var $subNav = $(this).closest('.sub-tab-navigation');
                    $subNav.find('.tab-button').removeClass('active');
                    $subNav.find('.tab-pane').removeClass('active');
                    $(this).addClass('active');
                    $('#' + targetId).addClass('active');
                }
            });


                // Set initial active states
            // Set initial active states
                $content.find('.tab-navigation').each(function() {
            $content.find('.tab-navigation').each(function() {
                    var $nav = $(this);
                var $nav = $(this);
                    var $buttons = $nav.find('.tab-button');
                var $activeButton = $nav.find('.tab-button.active');
                     var $activeButton = $buttons.filter('.active');
               
                if ($activeButton.length === 0) {
                     $activeButton = $nav.find('.tab-button').first().addClass('active');
                }
               
                var targetId = $activeButton.data('target');
                if (targetId) {
                    $('#' + targetId).addClass('active');
                      
                      
                     // If no active button, set first one active
                     // Handle sub-tabs
                    if ($activeButton.length === 0) {
                    var $subNav = $('#' + targetId).find('.sub-tab-navigation');
                        $activeButton = $buttons.first().addClass('active');
                    if ($subNav.length) {
                    }
                        var $firstSubTab = $subNav.find('.tab-button').first();
                   
                        $firstSubTab.addClass('active');
                    // Activate corresponding content
                       
                    if ($activeButton.length) {
                        var firstSubTargetId = $firstSubTab.data('target');
                        var targetId = $activeButton.data('target');
                        $('#' + firstSubTargetId).addClass('active');
                        if (targetId) {
                            $('#' + targetId).addClass('active');
                           
                            // Handle sub-tabs
                            var $subNav = $('#' + targetId).find('.sub-tab-navigation');
                            if ($subNav.length) {
                                var $firstSubTab = $subNav.find('.tab-button').first();
                                var firstSubTargetId = $firstSubTab.data('target');
                               
                                $firstSubTab.addClass('active');
                                $('#' + firstSubTargetId).addClass('active');
                            }
                        }
                     }
                     }
                }
            });
            // Add map tooltips
            $content.find('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>');
                }
            });
            // Image previews
            $content.find('.thumbimage').on('mouseenter mouseleave', function(e) {
                var styles = e.type === 'mouseenter' ? {
                    'transform': 'scale(1.05)',
                    'transition': 'transform 0.3s ease',
                    'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                } : {
                    'transform': '',
                    'box-shadow': ''
                };
                $(this).css(styles);
            });
            // Mobile optimization
            if (window.matchMedia("only screen and (max-width: 768px)").matches) {
                $content.find('.tab-nav').css({
                    'overflow-x': 'auto',
                    'white-space': 'nowrap',
                    '-webkit-overflow-scrolling': 'touch'
                 });
                 });
                  
                  
                // Add Tooltip functionality for map links
                 $content.find('.tab-button').css({
                 $content.find('span.material-button a').each(function() {
                     'display': 'inline-block',
                    var href = $(this).attr('href');
                     'float': 'none'
                    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
                $content.find('.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
                if (window.matchMedia("only screen and (max-width: 768px)").matches) {
                    $content.find('.tab-nav').css({
                        'overflow-x': 'auto',
                        'white-space': 'nowrap',
                        '-webkit-overflow-scrolling': 'touch'
                    });
                   
                    $content.find('.tab-button').css({
                        'display': 'inline-block',
                        'float': 'none'
                    });
                   
                    $content.find('.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);
                        });
                    });
                }
               
                console.log('Tab initialization complete');
            } catch (error) {
                console.error('Error in tab initialization:', error);
             }
             }
         });
         } catch (error) {
            console.error('Error in tab initialization:', error);
        }
     });
     });
});
});

Revision as of 06:37, 26 February 2025

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using(['jquery', 'mediawiki.util']).done(function ($) {
    'use strict';

    // Wait for wiki content to be ready
    mw.hook('wikipage.content').add(function($content) {
        console.log('Setting up tab navigation');
        
        try {
            // Main tabs (Race selection)
            $content.find('.tab-button').on('click', function(e) {
                e.preventDefault();
                var targetId = $(this).data('target');
                if (!targetId) return;

                // Handle main tab navigation
                if ($(this).closest('.tab-navigation').length) {
                    // Update main tabs
                    $('.tab-navigation .tab-button').removeClass('active');
                    $('.tab-content .tab-pane').removeClass('active');
                    $(this).addClass('active');
                    $('#' + targetId).addClass('active');

                    // Reset sub-tabs
                    var $subNav = $('#' + targetId).find('.sub-tab-navigation');
                    if ($subNav.length) {
                        var $firstSubTab = $subNav.find('.tab-button').first();
                        $subNav.find('.tab-button').removeClass('active');
                        $firstSubTab.addClass('active');
                        
                        var firstSubTargetId = $firstSubTab.data('target');
                        $subNav.find('.tab-pane').removeClass('active');
                        $('#' + firstSubTargetId).addClass('active');
                    }
                }
                // Handle sub-tab navigation
                else if ($(this).closest('.sub-tab-navigation').length) {
                    var $subNav = $(this).closest('.sub-tab-navigation');
                    $subNav.find('.tab-button').removeClass('active');
                    $subNav.find('.tab-pane').removeClass('active');
                    $(this).addClass('active');
                    $('#' + targetId).addClass('active');
                }
            });

            // Set initial active states
            $content.find('.tab-navigation').each(function() {
                var $nav = $(this);
                var $activeButton = $nav.find('.tab-button.active');
                
                if ($activeButton.length === 0) {
                    $activeButton = $nav.find('.tab-button').first().addClass('active');
                }
                
                var targetId = $activeButton.data('target');
                if (targetId) {
                    $('#' + targetId).addClass('active');
                    
                    // Handle sub-tabs
                    var $subNav = $('#' + targetId).find('.sub-tab-navigation');
                    if ($subNav.length) {
                        var $firstSubTab = $subNav.find('.tab-button').first();
                        $firstSubTab.addClass('active');
                        
                        var firstSubTargetId = $firstSubTab.data('target');
                        $('#' + firstSubTargetId).addClass('active');
                    }
                }
            });

            // Add map tooltips
            $content.find('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>');
                }
            });

            // Image previews
            $content.find('.thumbimage').on('mouseenter mouseleave', function(e) {
                var styles = e.type === 'mouseenter' ? {
                    'transform': 'scale(1.05)',
                    'transition': 'transform 0.3s ease',
                    'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                } : {
                    'transform': '',
                    'box-shadow': ''
                };
                $(this).css(styles);
            });

            // Mobile optimization
            if (window.matchMedia("only screen and (max-width: 768px)").matches) {
                $content.find('.tab-nav').css({
                    'overflow-x': 'auto',
                    'white-space': 'nowrap',
                    '-webkit-overflow-scrolling': 'touch'
                });
                
                $content.find('.tab-button').css({
                    'display': 'inline-block',
                    'float': 'none'
                });
            }
        } catch (error) {
            console.error('Error in tab initialization:', error);
        }
    });
});