MediaWiki:Common.js: Difference between revisions

From Ragnafied Wiki
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 1: Line 1:
$(document).ready(function() {
$(document).ready(function() {
     // ===========================================
     // ===========================================
     // 1. Back to Top Button - FIXED VERSION
     // Remove any existing elements first
     // ===========================================
     // ===========================================
    $('.floating-menu, .floating-menu-toggle, .back-to-top-fixed').remove();
      
      
     // Remove any existing back-to-top buttons first
     // ===========================================
    $('.back-to-top-fixed').remove();
     // Add both elements at once
      
     // ===========================================
     // Create the button with explicit inline styles
     var elementsHTML = `
     var topButtonHTML = `
        <!-- Quick Nav Menu -->
         <div class="back-to-top-fixed" id="back-to-top-btn" style="
         <div class="floating-menu" id="floatingMenu">
            position: fixed;
            <div class="floating-menu-header" id="menuHeader">
            bottom: 30px;
                <span>📋 QUICK NAV</span>
             right: 30px;
                <span class="arrow">▼</span>
             z-index: 9999;
             </div>
            display: none;
             <div class="floating-menu-items">
            opacity: 0;
                <a href="/index.php/Main_Page">🏠 Main Page</a>
            visibility: hidden;
                <a href="/index.php/First_Steps">🚀 First Steps</a>
            transition: opacity 0.3s ease, visibility 0.3s ease;
                <a href="/index.php/VIP">👑 VIP</a>
        ">
                <a href="/index.php/Enchant_Stones">💎 Enchant Stones</a>
            <a href="#" style="
                <a href="/index.php/Nyangvines">🐱 Nyangvines</a>
                 background: linear-gradient(135deg, #FF6A00, #D93800);
                <a href="/index.php/Custom_Systems">⚙️ Custom Systems</a>
                 color: white;
                <a href="/index.php/Monthly_Kachua">📅 Monthly Kachua</a>
                 width: 60px;
                 <a href="/index.php/Troubleshooting">🔧 Troubleshooting</a>
                height: 60px;
                 <a href="/index.php/Card_Trader_and_Kachua_Tokens">🃏 Card and Tokens</a>
                border-radius: 50%;
                 <a href="/index.php/Equipment_Enhancement">🛡️ EQ Enhancement</a>
                display: flex;
            </div>
                align-items: center;
        </div>
                justify-content: center;
       
                font-weight: bold;
        <!-- Mobile Menu Toggle -->
                font-size: 16px;
        <div class="floating-menu-toggle" id="menuToggle">☰</div>
                text-decoration: none;
       
                box-shadow: 0 4px 15px rgba(0,0,0,0.3);
        <!-- Back to Top Button -->
                border: 3px solid white;
        <div class="back-to-top-fixed" id="backToTop">
                transition: all 0.3s ease;
             <a href="#">↑ TOP</a>
                cursor: pointer;
             ">↑ TOP</a>
         </div>
         </div>
       
        <!-- Progress Bar -->
        <div id="scroll-progress"></div>
     `;
     `;
      
      
     // Append to body
     // Append all elements at once
     $('body').append(topButtonHTML);
     $('body').append(elementsHTML);
   
    // Debug: Check if button was added
    console.log('Back to top button added:', $('#back-to-top-btn').length);
      
      
     // ===========================================
     // ===========================================
     // 2. Alternative Button (if first one fails)
     // Log to confirm elements were added
     // ===========================================
     // ===========================================
     setTimeout(function() {
     console.log('Quick Nav added:', $('#floatingMenu').length);
        if ($('#back-to-top-btn').length === 0) {
    console.log('Back to Top added:', $('#backToTop').length);
            console.log('First button failed, adding alternative...');
    console.log('Progress Bar added:', $('#scroll-progress').length);
            $('body').append('<div style="position:fixed;bottom:30px;right:30px;z-index:99999;background:red;color:white;padding:10px;" id="emergency-top">TOP</div>');
        }
    }, 1000);
      
      
     // ===========================================
     // ===========================================
     // 3. Scroll Handler for Button Visibility
     // Scroll Handler
     // ===========================================
     // ===========================================
     var lastScrollTop = 0;
     var lastScrollTop = 0;
    var scrollTimeout;
      
      
     $(window).scroll(function() {
     $(window).scroll(function() {
         var st = $(this).scrollTop();
         var st = $(this).scrollTop();
          
          
         // Clear previous timeout
         // Progress Bar
         if (scrollTimeout) {
        var docHeight = $(document).height() - $(window).height();
             clearTimeout(scrollTimeout);
        var scrolled = (st / docHeight) * 100;
        $('#scroll-progress').css("width", scrolled + "%");
       
        // Back to Top Button
         if (st > 300) {  
             $('#backToTop').fadeIn(300);
        } else {
            $('#backToTop').fadeOut(300);  
         }
         }
          
          
         scrollTimeout = setTimeout(function() {
         // Hide Menu on Scroll Down (Desktop Only)
            // Show/hide based on scroll position
        if ($(window).width() > 768) {
             if (st > 300) {
             if (st > lastScrollTop && st > 500) {
                 $('#back-to-top-btn').css({
                 $('#floatingMenu').css('right', '-220px');
                    'display': 'block',
                    'opacity': '1',
                    'visibility': 'visible'
                }).fadeIn(300);
             } else {
             } else {
                 $('#back-to-top-btn').fadeOut(300, function() {
                 $('#floatingMenu').css('right', '20px');
                    $(this).css({
                        'display': 'none',
                        'opacity': '0',
                        'visibility': 'hidden'
                    });
                });
             }
             }
           
        }
            // Hide on scroll down (optional)
       
            if ($(window).width() > 768) {
        lastScrollTop = st;
                if (st > lastScrollTop && st > 500) {
    });
                    $('#back-to-top-btn').css('right', '-100px');
   
                } else {
    // ===========================================
                    $('#back-to-top-btn').css('right', '30px');
    // Toggle Events
                }
    // ===========================================
    $('#menuHeader').click(function() {
        $('#floatingMenu').toggleClass('collapsed');
    });
   
    $('#menuToggle').click(function(e) {  
        e.stopPropagation();
        $('#floatingMenu').toggleClass('mobile-visible');
       
        // Close menu when clicking outside
        $(document).one('click', function(e) {
            if (!$(e.target).closest('#floatingMenu, #menuToggle').length) {
                $('#floatingMenu').removeClass('mobile-visible');
             }
             }
           
        });
             lastScrollTop = st;
    });
         }, 50);
   
    // Close menu with Escape key
    $(document).keyup(function(e) {
        if (e.key === "Escape") {
             $('#floatingMenu').removeClass('mobile-visible');
         }
     });
     });
      
      
     // ===========================================
     // ===========================================
     // 4. Click Handler
     // Back to Top Click Handler
     // ===========================================
     // ===========================================
     $(document).on('click', '#back-to-top-btn a, #emergency-top', function(e) {
     $('#backToTop a').click(function(e) {
         e.preventDefault();
         e.preventDefault();
         $('html, body').animate({
         $('html, body').animate({scrollTop: 0}, 400);
            scrollTop: 0
        }, 600, 'swing');
          
          
         // Button feedback
         // Button feedback
Line 117: Line 124:
      
      
     // ===========================================
     // ===========================================
     // 5. Hover Effects
     // Section Tracker
     // ===========================================
     // ===========================================
     $(document).on('mouseenter', '#back-to-top-btn a', function() {
     function updateActiveSection() {
        $(this).css({
        var currentPath = window.location.pathname;
            'background': 'linear-gradient(135deg, #FF7A20, #F4B400)',
        $('.floating-menu-items a').each(function() {
             'transform': 'translateY(-5px) scale(1.1)',
            var href = $(this).attr('href');
             'box-shadow': '0 6px 20px rgba(0,0,0,0.4)'
             if (currentPath.includes(href) || currentPath === href) {
                $(this).addClass('reading-now');
             } else {
                $(this).removeClass('reading-now');
            }
         });
         });
     }).on('mouseleave', '#back-to-top-btn a', function() {
     }
        $(this).css({
   
            'background': 'linear-gradient(135deg, #FF6A00, #D93800)',
    updateActiveSection();
            'transform': 'translateY(0) scale(1)',
            'box-shadow': '0 4px 15px rgba(0,0,0,0.3)'
        });
    });
      
      
     // ===========================================
     // ===========================================
     // 6. Responsive Adjustments
     // Hover Effects
     // ===========================================
     // ===========================================
     $(window).resize(function() {
     $('#backToTop a').hover(
        if ($(window).width() <= 768) {
        function() {  
            $('#back-to-top-btn').css({
            $(this).css({
                 'bottom': '20px',
                'background': 'linear-gradient(135deg, #FF7A20, #F4B400)',
                 'right': '20px'
                 'transform': 'translateY(-5px) scale(1.1)',
                 'box-shadow': '0 6px 20px rgba(0,0,0,0.4)'
             });
             });
             $('#back-to-top-btn a').css({
        },
                 'width': '50px',
        function() {
                 'height': '50px',
             $(this).css({
                 'font-size': '14px'
                 'background': 'linear-gradient(135deg, #FF6A00, #D93800)',
                 'transform': 'translateY(0) scale(1)',
                 'box-shadow': '0 4px 15px rgba(0,0,0,0.3)'
             });
             });
        }
    );
   
    // ===========================================
    // Responsive Handler
    // ===========================================
    $(window).resize(function() {
        if ($(window).width() > 768) {
            $('#floatingMenu').removeClass('mobile-visible');
            $('#floatingMenu').css('right', '20px');
         } else {
         } else {
             $('#back-to-top-btn').css({
             $('#floatingMenu').css('right', '');
                'bottom': '30px',
                'right': '30px'
            });
            $('#back-to-top-btn a').css({
                'width': '60px',
                'height': '60px',
                'font-size': '16px'
            });
         }
         }
     }).resize(); // Trigger on load
     });
      
      
     // ===========================================
     // ===========================================
     // 7. Check if button is visible on page load
     // Initialize states
     // ===========================================
     // ===========================================
     setTimeout(function() {
     // Check if menu should start collapsed
         var btn = $('#back-to-top-btn');
    if (localStorage.getItem('quickNavCollapsed') === 'true') {
        console.log('Button exists:', btn.length > 0);
         $('#floatingMenu').addClass('collapsed');
        console.log('Button display:', btn.css('display'));
    }
        console.log('Button visibility:', btn.css('visibility'));
   
         console.log('Button opacity:', btn.css('opacity'));
    // Save collapse state
        console.log('Button position:', btn.offset());
    $('#menuHeader').click(function() {
       
         localStorage.setItem('quickNavCollapsed', $('#floatingMenu').hasClass('collapsed'));
        // Force show for testing (remove after confirming it works)
     });
        // btn.css({'display': 'block', 'opacity': '1', 'visibility': 'visible'});
     }, 2000);
      
      
     // ===========================================
     // ===========================================
     // 8. Alternative: Add to existing menu
     // Smooth Scrolling for Anchor Links
     // ===========================================
     // ===========================================
     // Add to floating menu as alternative
     $('a[href^="#"]').not('.no-smooth').on('click', function(e) {
    setTimeout(function() {
        e.preventDefault();
        if ($('.floating-menu-items').length && $('#back-to-top-btn').css('display') === 'none') {
        var target = $(this.hash);
            $('.floating-menu-items').append(
        if (target.length) {
                '<a href="#" id="menu-back-to-top" style="border-top: 1px solid #eee; margin-top: 10px;">⬆️ Back to Top</a>'
            $('html, body').animate({
            );
                scrollTop: target.offset().top - 60
           
             }, 500);
            $('#menu-back-to-top').click(function(e) {
                e.preventDefault();
                $('html, body').animate({scrollTop: 0}, 600);
             });
         }
         }
     }, 1000);
     });
   
    console.log('✅ All elements initialized successfully');
});
});

Revision as of 11:00, 21 February 2026

$(document).ready(function() {
    // ===========================================
    // Remove any existing elements first
    // ===========================================
    $('.floating-menu, .floating-menu-toggle, .back-to-top-fixed').remove();
    
    // ===========================================
    // Add both elements at once
    // ===========================================
    var elementsHTML = `
        <!-- Quick Nav Menu -->
        <div class="floating-menu" id="floatingMenu">
            <div class="floating-menu-header" id="menuHeader">
                <span>📋 QUICK NAV</span>
                <span class="arrow">▼</span>
            </div>
            <div class="floating-menu-items">
                <a href="/index.php/Main_Page">🏠 Main Page</a>
                <a href="/index.php/First_Steps">🚀 First Steps</a>
                <a href="/index.php/VIP">👑 VIP</a>
                <a href="/index.php/Enchant_Stones">💎 Enchant Stones</a>
                <a href="/index.php/Nyangvines">🐱 Nyangvines</a>
                <a href="/index.php/Custom_Systems">⚙️ Custom Systems</a>
                <a href="/index.php/Monthly_Kachua">📅 Monthly Kachua</a>
                <a href="/index.php/Troubleshooting">🔧 Troubleshooting</a>
                <a href="/index.php/Card_Trader_and_Kachua_Tokens">🃏 Card and Tokens</a>
                <a href="/index.php/Equipment_Enhancement">🛡️ EQ Enhancement</a>
            </div>
        </div>
        
        <!-- Mobile Menu Toggle -->
        <div class="floating-menu-toggle" id="menuToggle">☰</div>
        
        <!-- Back to Top Button -->
        <div class="back-to-top-fixed" id="backToTop">
            <a href="#">↑ TOP</a>
        </div>
        
        <!-- Progress Bar -->
        <div id="scroll-progress"></div>
    `;
    
    // Append all elements at once
    $('body').append(elementsHTML);
    
    // ===========================================
    // Log to confirm elements were added
    // ===========================================
    console.log('Quick Nav added:', $('#floatingMenu').length);
    console.log('Back to Top added:', $('#backToTop').length);
    console.log('Progress Bar added:', $('#scroll-progress').length);
    
    // ===========================================
    // Scroll Handler
    // ===========================================
    var lastScrollTop = 0;
    
    $(window).scroll(function() {
        var st = $(this).scrollTop();
        
        // Progress Bar
        var docHeight = $(document).height() - $(window).height();
        var scrolled = (st / docHeight) * 100;
        $('#scroll-progress').css("width", scrolled + "%");
        
        // Back to Top Button
        if (st > 300) { 
            $('#backToTop').fadeIn(300); 
        } else { 
            $('#backToTop').fadeOut(300); 
        }
        
        // Hide Menu on Scroll Down (Desktop Only)
        if ($(window).width() > 768) {
            if (st > lastScrollTop && st > 500) {
                $('#floatingMenu').css('right', '-220px');
            } else {
                $('#floatingMenu').css('right', '20px');
            }
        }
        
        lastScrollTop = st;
    });
    
    // ===========================================
    // Toggle Events
    // ===========================================
    $('#menuHeader').click(function() { 
        $('#floatingMenu').toggleClass('collapsed'); 
    });
    
    $('#menuToggle').click(function(e) { 
        e.stopPropagation();
        $('#floatingMenu').toggleClass('mobile-visible');
        
        // Close menu when clicking outside
        $(document).one('click', function(e) {
            if (!$(e.target).closest('#floatingMenu, #menuToggle').length) {
                $('#floatingMenu').removeClass('mobile-visible');
            }
        });
    });
    
    // Close menu with Escape key
    $(document).keyup(function(e) {
        if (e.key === "Escape") {
            $('#floatingMenu').removeClass('mobile-visible');
        }
    });
    
    // ===========================================
    // Back to Top Click Handler
    // ===========================================
    $('#backToTop a').click(function(e) {
        e.preventDefault();
        $('html, body').animate({scrollTop: 0}, 400);
        
        // Button feedback
        $(this).css('transform', 'scale(0.9)');
        setTimeout(() => {
            $(this).css('transform', 'scale(1)');
        }, 200);
    });
    
    // ===========================================
    // Section Tracker
    // ===========================================
    function updateActiveSection() {
        var currentPath = window.location.pathname;
        $('.floating-menu-items a').each(function() {
            var href = $(this).attr('href');
            if (currentPath.includes(href) || currentPath === href) {
                $(this).addClass('reading-now');
            } else {
                $(this).removeClass('reading-now');
            }
        });
    }
    
    updateActiveSection();
    
    // ===========================================
    // Hover Effects
    // ===========================================
    $('#backToTop a').hover(
        function() { 
            $(this).css({
                'background': 'linear-gradient(135deg, #FF7A20, #F4B400)',
                'transform': 'translateY(-5px) scale(1.1)',
                'box-shadow': '0 6px 20px rgba(0,0,0,0.4)'
            });
        },
        function() { 
            $(this).css({
                'background': 'linear-gradient(135deg, #FF6A00, #D93800)',
                'transform': 'translateY(0) scale(1)',
                'box-shadow': '0 4px 15px rgba(0,0,0,0.3)'
            });
        }
    );
    
    // ===========================================
    // Responsive Handler
    // ===========================================
    $(window).resize(function() {
        if ($(window).width() > 768) {
            $('#floatingMenu').removeClass('mobile-visible');
            $('#floatingMenu').css('right', '20px');
        } else {
            $('#floatingMenu').css('right', '');
        }
    });
    
    // ===========================================
    // Initialize states
    // ===========================================
    // Check if menu should start collapsed
    if (localStorage.getItem('quickNavCollapsed') === 'true') {
        $('#floatingMenu').addClass('collapsed');
    }
    
    // Save collapse state
    $('#menuHeader').click(function() {
        localStorage.setItem('quickNavCollapsed', $('#floatingMenu').hasClass('collapsed'));
    });
    
    // ===========================================
    // Smooth Scrolling for Anchor Links
    // ===========================================
    $('a[href^="#"]').not('.no-smooth').on('click', function(e) {
        e.preventDefault();
        var target = $(this.hash);
        if (target.length) {
            $('html, body').animate({
                scrollTop: target.offset().top - 60
            }, 500);
        }
    });
    
    console.log('✅ All elements initialized successfully');
});