MediaWiki:Common.js: Difference between revisions

From Ragnafied Wiki
No edit summary
Tag: Reverted
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(document).ready(function() {
$(document).ready(function() {
    // ===========================================
     // 1. Define HTML for all elements
     // 1. Back to Top Button - FIXED VERSION
     var progressBarHTML = '<div id="scroll-progress"></div>';
     // ===========================================
     var topButtonHTML = '<div class="back-to-top-fixed" style="display:none;"><a href="#">↑ TOP</a></div>';
   
     var menuHTML = `
    // Remove any existing back-to-top buttons first
         <div class="floating-menu" id="floatingMenu">
     $('.back-to-top-fixed').remove();
            <div class="floating-menu-header" id="menuHeader">
   
                <span>📋 QUICK NAV</span>
    // Create the button with explicit inline styles
                <span class="arrow">▼</span>
     var topButtonHTML = `
             </div>
         <div class="back-to-top-fixed" id="back-to-top-btn" style="
             <div class="floating-menu-items">
            position: fixed;
                <a href="/index.php/Main_Page">🏠 Main Page</a>
            bottom: 30px;
                <a href="/index.php/First_Steps">🚀 First Steps</a>
             right: 30px;
                <a href="/index.php/VIP">👑 VIP</a>
             z-index: 9999;
                 <a href="/index.php/Enchant_Stones">💎 Enchant Stones</a>
            display: none;
                 <a href="/index.php/Nyangvines">🐱 Nyangvines</a>
            opacity: 0;
                 <a href="/index.php/Custom_Systems">⚙️ Custom Systems</a>
            visibility: hidden;
                 <a href="/index.php/Monthly_Kachua">📅 Monthly Kachua</a>
            transition: opacity 0.3s ease, visibility 0.3s ease;
                 <a href="/index.php/Troubleshooting">🔧 Troubleshooting</a>
        ">
                 <a href="/index.php/Card_Trader_and_Kachua_Tokens">🃏 Card and Tokens</a>
            <a href="#" style="
                 <a href="/index.php/Equipment_Enhancement">🛡️ EQ Enhancement</a>
                 background: linear-gradient(135deg, #FF6A00, #D93800);
            </div>
                 color: white;
                 width: 60px;
                 height: 60px;
                 border-radius: 50%;
                 display: flex;
                align-items: center;
                justify-content: center;
                font-weight: bold;
                font-size: 16px;
                text-decoration: none;
                box-shadow: 0 4px 15px rgba(0,0,0,0.3);
                 border: 3px solid white;
                transition: all 0.3s ease;
                cursor: pointer;
            ">↑ TOP</a>
         </div>
         </div>
        <div class="floating-menu-toggle" id="menuToggle">☰</div>
     `;
     `;
   
 
    // Append to body
     $('body').append(progressBarHTML + topButtonHTML + menuHTML);
     $('body').append(topButtonHTML);
 
   
    // 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)
    // ===========================================
    setTimeout(function() {
        if ($('#back-to-top-btn').length === 0) {
            console.log('First button failed, adding alternative...');
            $('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
    // ===========================================
     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
         // A. Progress Bar
         if (scrollTimeout) {
         var docHeight = $(document).height() - $(window).height();
             clearTimeout(scrollTimeout);
        var scrolled = (st / docHeight) * 100;
        $('#scroll-progress').css("width", scrolled + "%");
 
        // B. Top Button Fade
        if (st > 300) { $('.back-to-top-fixed').fadeIn(); }
        else { $('.back-to-top-fixed').fadeOut(); }
 
        // C. 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;
         scrollTimeout = setTimeout(function() {
 
            // Show/hide based on scroll position
         // D. Section Tracker: Highlights the link if the URL matches current page
             if (st > 300) {
        var currentPath = window.location.pathname;
                $('#back-to-top-btn').css({
        $('.floating-menu-items a').each(function() {
                    'display': 'block',
             if (currentPath.includes($(this).attr('href'))) {
                    'opacity': '1',
                 $(this).addClass('reading-now');
                    'visibility': 'visible'
                 }).fadeIn(300);
             } else {
             } else {
                 $('#back-to-top-btn').fadeOut(300, function() {
                 $(this).removeClass('reading-now');
                    $(this).css({
                        'display': 'none',
                        'opacity': '0',
                        'visibility': 'hidden'
                    });
                });
             }
             }
           
        });
            // Hide on scroll down (optional)
    });
            if ($(window).width() > 768) {
 
                if (st > lastScrollTop && st > 500) {
    // Toggle Events
                    $('#back-to-top-btn').css('right', '-100px');
    $('#menuHeader').click(function() { $('#floatingMenu').toggleClass('collapsed'); });
                } else {
    $('#menuToggle').click(function() { $('#floatingMenu').toggleClass('mobile-visible'); });
                    $('#back-to-top-btn').css('right', '30px');
    $('.back-to-top-fixed a').click(function(e) {
                }
        e.preventDefault();
            }
         $('html, body').animate({scrollTop: 0}, 400);
           
            lastScrollTop = st;
         }, 50);
     });
     });
   
});
    // ===========================================
 
    // 4. Click Handler
// Add smooth scrolling to anchor links
    // ===========================================
$(document).ready(function() {
     $(document).on('click', '#back-to-top-btn a, #emergency-top', function(e) {
     $('a[href^="#"]').on('click', function(e) {
         e.preventDefault();
         e.preventDefault();
         $('html, body').animate({
         var target = $(this.hash);
            scrollTop: 0
        if (target.length) {
        }, 600, 'swing');
            $('html, body').animate({
       
                scrollTop: target.offset().top - 50
        // Button feedback
             }, 500);
        $(this).css('transform', 'scale(0.9)');
         }
        setTimeout(() => {
             $(this).css('transform', 'scale(1)');
         }, 200);
     });
     });
});
// Sticky header on scroll
$(window).scroll(function() {
    if ($(window).scrollTop() > 100) {
        $('#mw-head').addClass('sticky-header');
    } else {
        $('#mw-head').removeClass('sticky-header');
    }
});
// Ragnawiki Collapsible - Clean implementation
jQuery(document).ready(function($) {
    console.log("Ragnawiki collapsible initializing...");
      
      
     // ===========================================
     // Completely disable MediaWiki's built-in collapsible
     // 5. Hover Effects
     if (typeof mw !== 'undefined' && mw.loader) {
    // ===========================================
         mw.loader.using('jquery.makeCollapsible', function() {
    $(document).on('mouseenter', '#back-to-top-btn a', function() {
             // Override the makeCollapsible function to do nothing
         $(this).css({
             $.fn.makeCollapsible = function() { return this; };
            'background': 'linear-gradient(135deg, #FF7A20, #F4B400)',
             'transform': 'translateY(-5px) scale(1.1)',
             'box-shadow': '0 6px 20px rgba(0,0,0,0.4)'
        });
    }).on('mouseleave', '#back-to-top-btn a', 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)'
         });
         });
     });
     }
   
    // ===========================================
    // 6. Responsive Adjustments
    // ===========================================
    $(window).resize(function() {
        if ($(window).width() <= 768) {
            $('#back-to-top-btn').css({
                'bottom': '20px',
                'right': '20px'
            });
            $('#back-to-top-btn a').css({
                'width': '50px',
                'height': '50px',
                'font-size': '14px'
            });
        } else {
            $('#back-to-top-btn').css({
                'bottom': '30px',
                'right': '30px'
            });
            $('#back-to-top-btn a').css({
                'width': '60px',
                'height': '60px',
                'font-size': '16px'
            });
        }
    }).resize(); // Trigger on load
      
      
     // ===========================================
     // Remove any existing MediaWiki collapsible toggles and classes
     // 7. Check if button is visible on page load
     $('.mw-collapsible-toggle').remove();
    // ===========================================
    $('.mw-made-collapsible').removeClass('mw-made-collapsible');
    setTimeout(function() {
        var btn = $('#back-to-top-btn');
        console.log('Button exists:', btn.length > 0);
        console.log('Button display:', btn.css('display'));
        console.log('Button visibility:', btn.css('visibility'));
        console.log('Button opacity:', btn.css('opacity'));
        console.log('Button position:', btn.offset());
       
        // Force show for testing (remove after confirming it works)
        // btn.css({'display': 'block', 'opacity': '1', 'visibility': 'visible'});
    }, 2000);
      
      
     // ===========================================
     // Small delay to ensure DOM is fully ready
    // 8. Alternative: Add to existing menu
    // ===========================================
    // Add to floating menu as alternative
     setTimeout(function() {
     setTimeout(function() {
         if ($('.floating-menu-items').length && $('#back-to-top-btn').css('display') === 'none') {
         // Find all our collapsible containers
             $('.floating-menu-items').append(
        $('.mw-collapsible').each(function() {
                '<a href="#" id="menu-back-to-top" style="border-top: 1px solid #eee; margin-top: 10px;">⬆️ Back to Top</a>'
            var $container = $(this);
            );
            var $header = $container.find('.ragnawiki-card-header, .ragnawiki-nav-header').first();
             var $content = $container.find('.mw-collapsible-content').first();
              
              
             $('#menu-back-to-top').click(function(e) {
             if ($header.length && $content.length) {
                e.preventDefault();
                // Remove any existing click handlers
                $('html, body').animate({scrollTop: 0}, 600);
                $header.off('click.collapsible');
             });
               
         }
                // Set initial state
     }, 1000);
                $container.removeClass('expanded mw-collapsed');
               
                // Start collapsed by default
                $content.hide();
               
                // Add click handler
                $header.on('click.collapsible', function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                   
                    if ($container.hasClass('expanded')) {
                        // Collapse
                        $container.removeClass('expanded');
                        $content.slideUp(200);
                    } else {
                        // Expand
                        $container.addClass('expanded');
                        $content.slideDown(200);
                    }
                   
                    return false;
                });
               
                console.log("Collapsible initialized for:", $header.text().trim());
             }
         });
     }, 100);
});
 
/* Force Table of Contents to start collapsed */
$(document).ready(function() {
    var tocToggle = document.getElementById('togglelink');
    if (tocToggle && tocToggle.innerText !== 'show') {
        tocToggle.click();
    }
});
});

Latest revision as of 19:39, 21 February 2026

$(document).ready(function() {
    // 1. Define HTML for all elements
    var progressBarHTML = '<div id="scroll-progress"></div>';
    var topButtonHTML = '<div class="back-to-top-fixed" style="display:none;"><a href="#">↑ TOP</a></div>';
    var menuHTML = `
        <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>
        <div class="floating-menu-toggle" id="menuToggle">☰</div>
    `;

    $('body').append(progressBarHTML + topButtonHTML + menuHTML);

    var lastScrollTop = 0;

    $(window).scroll(function() {
        var st = $(this).scrollTop();
        
        // A. Progress Bar
        var docHeight = $(document).height() - $(window).height();
        var scrolled = (st / docHeight) * 100;
        $('#scroll-progress').css("width", scrolled + "%");

        // B. Top Button Fade
        if (st > 300) { $('.back-to-top-fixed').fadeIn(); } 
        else { $('.back-to-top-fixed').fadeOut(); }

        // C. 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;

        // D. Section Tracker: Highlights the link if the URL matches current page
        var currentPath = window.location.pathname;
        $('.floating-menu-items a').each(function() {
            if (currentPath.includes($(this).attr('href'))) {
                $(this).addClass('reading-now');
            } else {
                $(this).removeClass('reading-now');
            }
        });
    });

    // Toggle Events
    $('#menuHeader').click(function() { $('#floatingMenu').toggleClass('collapsed'); });
    $('#menuToggle').click(function() { $('#floatingMenu').toggleClass('mobile-visible'); });
    $('.back-to-top-fixed a').click(function(e) {
        e.preventDefault();
        $('html, body').animate({scrollTop: 0}, 400);
    });
});

// Add smooth scrolling to anchor links
$(document).ready(function() {
    $('a[href^="#"]').on('click', function(e) {
        e.preventDefault();
        var target = $(this.hash);
        if (target.length) {
            $('html, body').animate({
                scrollTop: target.offset().top - 50
            }, 500);
        }
    });
});

// Sticky header on scroll
$(window).scroll(function() {
    if ($(window).scrollTop() > 100) {
        $('#mw-head').addClass('sticky-header');
    } else {
        $('#mw-head').removeClass('sticky-header');
    }
});

// Ragnawiki Collapsible - Clean implementation
jQuery(document).ready(function($) {
    console.log("Ragnawiki collapsible initializing...");
    
    // Completely disable MediaWiki's built-in collapsible
    if (typeof mw !== 'undefined' && mw.loader) {
        mw.loader.using('jquery.makeCollapsible', function() {
            // Override the makeCollapsible function to do nothing
            $.fn.makeCollapsible = function() { return this; };
        });
    }
    
    // Remove any existing MediaWiki collapsible toggles and classes
    $('.mw-collapsible-toggle').remove();
    $('.mw-made-collapsible').removeClass('mw-made-collapsible');
    
    // Small delay to ensure DOM is fully ready
    setTimeout(function() {
        // Find all our collapsible containers
        $('.mw-collapsible').each(function() {
            var $container = $(this);
            var $header = $container.find('.ragnawiki-card-header, .ragnawiki-nav-header').first();
            var $content = $container.find('.mw-collapsible-content').first();
            
            if ($header.length && $content.length) {
                // Remove any existing click handlers
                $header.off('click.collapsible');
                
                // Set initial state
                $container.removeClass('expanded mw-collapsed');
                
                // Start collapsed by default
                $content.hide();
                
                // Add click handler
                $header.on('click.collapsible', function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                    
                    if ($container.hasClass('expanded')) {
                        // Collapse
                        $container.removeClass('expanded');
                        $content.slideUp(200);
                    } else {
                        // Expand
                        $container.addClass('expanded');
                        $content.slideDown(200);
                    }
                    
                    return false;
                });
                
                console.log("Collapsible initialized for:", $header.text().trim());
            }
        });
    }, 100);
});

/* Force Table of Contents to start collapsed */
$(document).ready(function() {
    var tocToggle = document.getElementById('togglelink');
    if (tocToggle && tocToggle.innerText !== 'show') {
        tocToggle.click();
    }
});