MediaWiki:Common.js: Difference between revisions

From Ragnafied Wiki
No edit summary
Tag: Reverted
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(document).ready(function() {
$(document).ready(function() {
    // ===========================================
     // 1. Define HTML for all elements
    // Configuration
     var progressBarHTML = '<div id="scroll-progress"></div>';
    // ===========================================
    var topButtonHTML = '<div class="back-to-top-fixed" style="display:none;"><a href="#">↑ TOP</a></div>';
    const CONFIG = {
    var menuHTML = `
        scrollThreshold: 300,
        <div class="floating-menu" id="floatingMenu">
        menuHideThreshold: 500,
            <div class="floating-menu-header" id="menuHeader">
        desktopBreakpoint: 768,
                <span>📋 QUICK NAV</span>
        progressBar: true,
                <span class="arrow">▼</span>
        backToTop: true,
            </div>
        floatingMenu: true,
            <div class="floating-menu-items">
        smoothScroll: true,
                <a href="/index.php/Main_Page">🏠 Main Page</a>
        stickyHeader: true,
                <a href="/index.php/First_Steps">🚀 First Steps</a>
        readingTime: true,
                <a href="/index.php/VIP">👑 VIP</a>
        tableOfContents: true
                <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>
     // 1. Initialize UI Elements
                <a href="/index.php/Troubleshooting">🔧 Troubleshooting</a>
     // ===========================================
                <a href="/index.php/Card_Trader_and_Kachua_Tokens">🃏 Card and Tokens</a>
    function initializeUI() {
                <a href="/index.php/Equipment_Enhancement">🛡️ EQ Enhancement</a>
        // Progress Bar
            </div>
        if (CONFIG.progressBar) {
        </div>
            $('body').append('<div id="scroll-progress"></div>');
        <div class="floating-menu-toggle" id="menuToggle">☰</div>
        }
    `;
       
 
        // Back to Top Button
    $('body').append(progressBarHTML + topButtonHTML + menuHTML);
        if (CONFIG.backToTop) {
 
            var topButtonHTML = '<div class="back-to-top-fixed" style="display:none;"><a href="#">↑ TOP</a></div>';
            $('body').append(topButtonHTML);
        }
       
        // Floating Menu
        if (CONFIG.floatingMenu) {
            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(menuHTML);
        }
    }
   
    initializeUI();
   
    // ===========================================
    // 2. Scroll Event Handler
    // ===========================================
     var lastScrollTop = 0;
     var lastScrollTop = 0;
    var scrollTimer = null;
 
   
     $(window).scroll(function() {
     $(window).scroll(function() {
         var st = $(this).scrollTop();
         var st = $(this).scrollTop();
          
          
         // Throttle scroll events for better performance
         // A. Progress Bar
        if (scrollTimer) {
        var docHeight = $(document).height() - $(window).height();
            clearTimeout(scrollTimer);
        var scrolled = (st / docHeight) * 100;
        }
        $('#scroll-progress').css("width", scrolled + "%");
       
        scrollTimer = setTimeout(function() {
            // A. Progress Bar
            if (CONFIG.progressBar) {
                var docHeight = $(document).height() - $(window).height();
                var scrolled = (st / docHeight) * 100;
                $('#scroll-progress').css("width", scrolled + "%");
            }


            // B. Top Button Fade
        // B. Top Button Fade
            if (CONFIG.backToTop) {
        if (st > 300) { $('.back-to-top-fixed').fadeIn(); }
                if (st > CONFIG.scrollThreshold) {  
        else { $('.back-to-top-fixed').fadeOut(); }
                    $('.back-to-top-fixed').fadeIn();  
                } else {  
                    $('.back-to-top-fixed').fadeOut();  
                }
            }
 
            // C. Hide Menu on Scroll Down (Desktop Only)
            if (CONFIG.floatingMenu && $(window).width() > CONFIG.desktopBreakpoint) {
                if (st > lastScrollTop && st > CONFIG.menuHideThreshold) {
                    $('#floatingMenu').css('right', '-220px');
                } else {
                    $('#floatingMenu').css('right', '20px');
                }
            }
           
            lastScrollTop = st;
        }, 10); // 10ms throttle


         // D. Sticky Header
         // C. Hide Menu on Scroll Down (Desktop Only)
         if (CONFIG.stickyHeader) {
         if ($(window).width() > 768) {
             if (st > 100) {
             if (st > lastScrollTop && st > 500) {
                 $('#mw-head').addClass('sticky-header');
                 $('#floatingMenu').css('right', '-220px');
             } else {
             } else {
                 $('#mw-head').removeClass('sticky-header');
                 $('#floatingMenu').css('right', '20px');
             }
             }
         }
         }
    });
        lastScrollTop = st;
   
 
    // ===========================================
        // D. Section Tracker: Highlights the link if the URL matches current page
    // 3. Section Tracker (run on load and scroll)
    // ===========================================
    function updateActiveSection() {
         var currentPath = window.location.pathname;
         var currentPath = window.location.pathname;
         $('.floating-menu-items a').each(function() {
         $('.floating-menu-items a').each(function() {
             var href = $(this).attr('href');
             if (currentPath.includes($(this).attr('href'))) {
            if (currentPath.includes(href) || currentPath === href) {
                 $(this).addClass('reading-now');
                 $(this).addClass('reading-now');
             } else {
             } else {
Line 126: Line 60:
             }
             }
         });
         });
    }
   
    // Run on load and scroll
    updateActiveSection();
    $(window).on('scroll', updateActiveSection);
   
    // ===========================================
    // 4. Toggle Events
    // ===========================================
    $('#menuHeader').click(function() {
        $('#floatingMenu').toggleClass('collapsed');
     });
     });
      
 
     $('#menuToggle').click(function() {  
     // Toggle Events
        $('#floatingMenu').toggleClass('mobile-visible');
     $('#menuHeader').click(function() { $('#floatingMenu').toggleClass('collapsed'); });
        // Close menu when clicking outside
    $('#menuToggle').click(function() { $('#floatingMenu').toggleClass('mobile-visible'); });
        $(document).one('click', function(e) {
    $('.back-to-top-fixed a').click(function(e) {
            if (!$(e.target).closest('#floatingMenu, #menuToggle').length) {
        e.preventDefault();
                $('#floatingMenu').removeClass('mobile-visible');
         $('html, body').animate({scrollTop: 0}, 400);
            }
         });
     });
     });
   
});
    // Close menu with Escape key
 
     $(document).keyup(function(e) {
// Add smooth scrolling to anchor links
         if (e.key === "Escape") {
$(document).ready(function() {
             $('#floatingMenu').removeClass('mobile-visible');
     $('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
     // 5. Back to Top Button
     if (typeof mw !== 'undefined' && mw.loader) {
    // ===========================================
         mw.loader.using('jquery.makeCollapsible', function() {
    $('.back-to-top-fixed a').click(function(e) {
             // Override the makeCollapsible function to do nothing
         e.preventDefault();
             $.fn.makeCollapsible = function() { return this; };
        $('html, body').animate({scrollTop: 0}, 400, 'swing');
    });
   
    // ===========================================
    // 6. Smooth Scrolling for Anchor Links
    // ===========================================
    if (CONFIG.smoothScroll) {
        $('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, 'swing', function() {
                    // Update URL hash without jumping
                    if (history.pushState) {
                        history.pushState(null, null, this.hash);
                    }
                });
            }
         });
         });
     }
     }
      
      
     // ===========================================
     // Remove any existing MediaWiki collapsible toggles and classes
     // 7. Reading Time Estimator
     $('.mw-collapsible-toggle').remove();
    // ===========================================
    $('.mw-made-collapsible').removeClass('mw-made-collapsible');
    if (CONFIG.readingTime) {
        var content = $('#mw-content-text').text();
        var wordCount = content.split(/\s+/).length;
        var readingTime = Math.ceil(wordCount / 200);
       
        if (wordCount > 50) { // Only show for longer articles
            $('#firstHeading').append(
                '<span class="reading-time-badge" style="' +
                'font-size: 14px; ' +
                'font-weight: normal; ' +
                'margin-left: 15px; ' +
                'padding: 3px 10px; ' +
                'background: linear-gradient(135deg, #FF6A00, #D93800); ' +
                'color: white; ' +
                'border-radius: 20px; ' +
                'display: inline-block;' +
                '">📖 ' + readingTime + ' min read</span>'
            );
        }
    }
      
      
     // ===========================================
     // Small delay to ensure DOM is fully ready
     // 8. Table of Contents Improvements
     setTimeout(function() {
    // ===========================================
        // Find all our collapsible containers
    if (CONFIG.tableOfContents && $('#toc').length) {
        $('.mw-collapsible').each(function() {
        // Add sticky TOC toggle
            var $container = $(this);
        $('#toc').before(
            var $header = $container.find('.ragnawiki-card-header, .ragnawiki-nav-header').first();
             '<div id="toc-controls" style="margin-bottom: 10px;">' +
             var $content = $container.find('.mw-collapsible-content').first();
                 '<button id="toggle-toc" class="btn" style="' +
           
                 'background: linear-gradient(135deg, #FF6A00, #D93800); ' +
            if ($header.length && $content.length) {
                'color: white; ' +
                 // Remove any existing click handlers
                 'border: none; ' +
                 $header.off('click.collapsible');
                 'padding: 5px 15px; ' +
                  
                 'border-radius: 5px; ' +
                 // Set initial state
                 'cursor: pointer;' +
                 $container.removeClass('expanded mw-collapsed');
                 '">Hide Table of Contents</button>' +
                  
            '</div>'
                 // Start collapsed by default
        );
                $content.hide();
       
               
        $('#toggle-toc').click(function() {
                // Add click handler
            $('#toc ul').slideToggle(200);
                $header.on('click.collapsible', function(e) {
            $(this).text(function(i, text) {
                    e.preventDefault();
                return text === 'Hide Table of Contents' ?
                    e.stopPropagation();
                     'Show Table of Contents' : 'Hide Table of Contents';
                   
            });
                     if ($container.hasClass('expanded')) {
        });
                        // Collapse
       
                        $container.removeClass('expanded');
        // Add "Back to Top" links after each section
                        $content.slideUp(200);
        $('h2, h3').each(function() {
                    } else {
            if ($(this).attr('id')) {
                        // Expand
                $(this).append(
                        $container.addClass('expanded');
                    ' <a href="#top" class="section-top-link" style="' +
                        $content.slideDown(200);
                    'font-size: 12px; ' +
                     }
                     'margin-left: 10px; ' +
                      
                     'text-decoration: none; ' +
                     return false;
                     'opacity: 0.5; ' +
                 });
                    'transition: opacity 0.3s;' +
                    '">↑ top</a>'
                 );
                  
                  
                 $(this).find('.section-top-link').hover(
                 console.log("Collapsible initialized for:", $header.text().trim());
                    function() { $(this).css('opacity', '1'); },
                    function() { $(this).css('opacity', '0.5'); }
                );
             }
             }
         });
         });
    }, 100);
});
/* Force Table of Contents to start collapsed */
$(document).ready(function() {
    var tocToggle = document.getElementById('togglelink');
    if (tocToggle && tocToggle.innerText !== 'show') {
        tocToggle.click();
     }
     }
   
    // ===========================================
    // 9. Keyboard Navigation
    // ===========================================
    $(document).on('keydown', function(e) {
        // Alt + Q - Toggle floating menu
        if (e.altKey && e.key === 'q') {
            e.preventDefault();
            $('#floatingMenu').toggleClass('collapsed');
        }
       
        // Alt + T - Back to top
        if (e.altKey && e.key === 't') {
            e.preventDefault();
            $('html, body').animate({scrollTop: 0}, 400);
        }
       
        // Alt + H - Go to Main Page
        if (e.altKey && e.key === 'h') {
            e.preventDefault();
            window.location.href = '/index.php/Main_Page';
        }
    });
   
    // ===========================================
    // 10. Responsive Handling
    // ===========================================
    $(window).resize(function() {
        if ($(window).width() > CONFIG.desktopBreakpoint) {
            $('#floatingMenu').removeClass('mobile-visible');
            $('#floatingMenu').css('right', '20px');
        } else {
            $('#floatingMenu').css('right', '');
        }
    });
   
    // ===========================================
    // 11. Page Load Performance
    // ===========================================
    // Lazy load images if any
    $('img').each(function() {
        var img = $(this);
        var src = img.attr('src');
        if (src && !img.hasClass('loaded')) {
            img.on('load', function() {
                $(this).addClass('loaded');
            });
        }
    });
   
    // ===========================================
    // 12. Error Handling
    // ===========================================
    $(window).on('error', function(e) {
        console.log('JavaScript error:', e.message);
    });
});
});
// ===========================================
// 13. Sticky Header CSS (add to your CSS file)
// ===========================================
/*
.sticky-header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1000 !important;
    background: white !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
    animation: slideDown 0.3s ease;
}
@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}
*/

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