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'], function ($) {
mw.loader.using(['jquery', 'mediawiki.util'], function ($, util) {
     'use strict';
     'use strict';
   
    // Wait for DOM to be ready using MediaWiki hook
    mw.hook('dom.ready').add(function() {
        console.log('Tab navigation script loaded');


         function initializeTabs() {
    // Wait for both DOM and stylesheets to be ready
    $(window).on('load', function() {
         console.log('Window fully loaded, initializing tabs');
       
        // Ensure we're running after all MediaWiki resources are ready
        mw.hook('wikipage.content').add(function($content) {
            console.log('Wiki content ready, setting up tabs');
           
             try {
             try {
                 // Main tabs (Race selection)
                 // Main tabs (Race selection)
                 $('.tab-button').on('click', function(e) {
                 $content.find('.tab-button').on('click', function(e) {
                     e.preventDefault();
                     e.preventDefault();
                     console.log('Tab clicked:', $(this).data('target'));
                     console.log('Tab clicked:', $(this).data('target'));
Line 24: Line 27:
                         // Remove active class from all main tabs and contents
                         // Remove active class from all main tabs and contents
                         $('.tab-navigation .tab-button').removeClass('active');
                         $('.tab-navigation .tab-button').removeClass('active');
                         $('.tab-navigation').siblings('.tab-content').children('.tab-pane').removeClass('active');
                         $('.tab-content .tab-pane').removeClass('active');
                          
                          
                         // Activate clicked tab and its content
                         // Activate clicked tab and its content
                         $(this).addClass('active');
                         $(this).addClass('active');
                         $('#' + targetId).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();
                            var firstSubTargetId = $firstSubTab.data('target');
                           
                            // 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
                     // Handle sub-tab navigation
Line 44: Line 62:
                 });
                 });


                 // Set initial active states if not already set
                 // Set initial active states
                 $('.tab-navigation, .sub-tab-navigation').each(function() {
                 $content.find('.tab-navigation').each(function() {
                     var $nav = $(this);
                     var $nav = $(this);
                     var $buttons = $nav.find('.tab-button');
                     var $buttons = $nav.find('.tab-button');
Line 60: Line 78:
                         if (targetId) {
                         if (targetId) {
                             $('#' + targetId).addClass('active');
                             $('#' + 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');
                            }
                         }
                         }
                     }
                     }
                 });
                 });
                  
                  
                 console.log('Tab initialization complete');
                 // Add Tooltip functionality for map links
            } catch (error) {
                $content.find('span.material-button a').each(function() {
                console.error('Error initializing tabs:', error);
                    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>');
                    }
                });


        // Initialize tabs
                 // Enhanced Image Previews
        initializeTabs();
                $content.find('.thumbimage').on('mouseenter', function() {
       
                    $(this).css({
        // Add Tooltip functionality for map links
                        'transform': 'scale(1.05)',
        try {
                        'transition': 'transform 0.3s ease',
            $('span.material-button a').each(function() {
                        'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                var href = $(this).attr('href');
                    });
                if (href && href.indexOf('world-map') !== -1) {
                }).on('mouseleave', function() {
                    $(this).parent().attr('title', 'Click to view location on map');
                    $(this).css({
                    $(this).prepend('<span class="map-icon">🗺️ </span>');
                        'transform': '',
                 }
                        'box-shadow': ''
            });
                    });
        } catch (error) {
            console.error('Error setting up tooltips:', error);
        }
 
        // Enhanced Image Previews
        try {
            $('.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': ''
                });
            });
        } catch (error) {
            console.error('Error setting up image previews:', error);
        }


        // Improve Mobile Experience
                // Improve Mobile Experience
        try {
                if (window.matchMedia("only screen and (max-width: 768px)").matches) {
            if (window.matchMedia("only screen and (max-width: 768px)").matches) {
                    $content.find('.tab-nav').css({
                $('.tab-nav').css({
                        'overflow-x': 'auto',
                    'overflow-x': 'auto',
                        'white-space': 'nowrap',
                    'white-space': 'nowrap',
                        '-webkit-overflow-scrolling': 'touch'
                    '-webkit-overflow-scrolling': 'touch'
                    });
                });
                   
               
                    $content.find('.tab-button').css({
                $('.tab-button').css({
                        'display': 'inline-block',
                    'display': 'inline-block',
                        'float': 'none'
                    'float': 'none'
                    });
                });
                   
               
                    $content.find('.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)',
                            'transition': 'transform 0.3s ease',
                            'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                        });
                       
                        setTimeout(function() {
                             $this.css({
                             $this.css({
                                 'transform': '',
                                 'transform': 'scale(1.05)',
                                 'box-shadow': ''
                                'transition': 'transform 0.3s ease',
                                 'box-shadow': '0 8px 16px rgba(0,0,0,0.2)'
                             });
                             });
                        }, 1000);
                           
                            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 setting up mobile experience:', error);
        }
     });
     });
});
});

Revision as of 06:35, 26 February 2025

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

    // Wait for both DOM and stylesheets to be ready
    $(window).on('load', function() {
        console.log('Window fully loaded, initializing tabs');
        
        // Ensure we're running after all MediaWiki resources are ready
        mw.hook('wikipage.content').add(function($content) {
            console.log('Wiki content ready, setting up tabs');
            
            try {
                // Main tabs (Race selection)
                $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
                    if ($(this).closest('.tab-navigation').length) {
                        // Remove active class from all main tabs and contents
                        $('.tab-navigation .tab-button').removeClass('active');
                        $('.tab-content .tab-pane').removeClass('active');
                        
                        // Activate clicked tab and its content
                        $(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();
                            var firstSubTargetId = $firstSubTab.data('target');
                            
                            // 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
                        $subNav.find('.tab-button').removeClass('active');
                        $subNav.find('.tab-pane').removeClass('active');
                        
                        // Activate clicked tab and its content
                        $(this).addClass('active');
                        $('#' + targetId).addClass('active');
                    }
                });

                // Set initial active states
                $content.find('.tab-navigation').each(function() {
                    var $nav = $(this);
                    var $buttons = $nav.find('.tab-button');
                    var $activeButton = $buttons.filter('.active');
                    
                    // If no active button, set first one active
                    if ($activeButton.length === 0) {
                        $activeButton = $buttons.first().addClass('active');
                    }
                    
                    // Activate corresponding content
                    if ($activeButton.length) {
                        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();
                                var firstSubTargetId = $firstSubTab.data('target');
                                
                                $firstSubTab.addClass('active');
                                $('#' + firstSubTargetId).addClass('active');
                            }
                        }
                    }
                });
                
                // Add Tooltip functionality for map links
                $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>');
                    }
                });

                // 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);
            }
        });
    });
});