MediaWiki:Common.js: Difference between revisions

From Ragnafied Wiki
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 93: Line 93:
});
});


// Custom collapsible for Ragnawiki
// Ragnawiki Collapsible - Clean implementation
$(document).ready(function() {
jQuery(document).ready(function($) {
     // Find all collapsible containers
     console.log("Ragnawiki collapsible initializing...");
    $('.mw-collapsible').each(function() {
   
        var $container = $(this);
    // Completely disable MediaWiki's built-in collapsible
       
    if (typeof mw !== 'undefined' && mw.loader) {
        // Find the header (first element with ragnawiki-card-header class)
         mw.loader.using('jquery.makeCollapsible', function() {
        var $header = $container.find('.ragnawiki-card-header').first();
             // Override the makeCollapsible function to do nothing
          
             $.fn.makeCollapsible = function() { return this; };
        if ($header.length) {
        });
            // Make header clickable
    }
            $header.css('cursor', 'pointer');
   
           
    // Remove any existing MediaWiki collapsible toggles and classes
             // Add click handler
    $('.mw-collapsible-toggle').remove();
             $header.on('click', function(e) {
    $('.mw-made-collapsible').removeClass('mw-made-collapsible');
                e.preventDefault();
               
                // Toggle collapsed class
                if ($container.hasClass('mw-collapsed')) {
                    $container.removeClass('mw-collapsed');
                } else {
                    $container.addClass('mw-collapsed');
                }
            });
           
            // Ensure content is hidden if container has mw-collapsed class
            if ($container.hasClass('mw-collapsed')) {
                $container.find('.mw-collapsible-content').hide();
            } else {
                $container.find('.mw-collapsible-content').show();
            }
        }
    });
      
      
     // Also handle nested collapsibles inside Past Heroes section
     // Small delay to ensure DOM is fully ready
     $('.ragnawiki-card .mw-collapsible').each(function() {
     setTimeout(function() {
        var $container = $(this);
        // Find all our collapsible containers
        var $header = $container.find('.ragnawiki-card-header').first();
        $('.mw-collapsible').each(function() {
       
            var $container = $(this);
        if ($header.length) {
            var $header = $container.find('.ragnawiki-card-header, .ragnawiki-nav-header').first();
            $header.css('cursor', 'pointer');
            var $content = $container.find('.mw-collapsible-content').first();
              
              
             $header.on('click', function(e) {
             if ($header.length && $content.length) {
                 e.preventDefault();
                 // Remove any existing click handlers
                $header.off('click.collapsible');
                  
                  
                 if ($container.hasClass('mw-collapsed')) {
                 // Set initial state
                    $container.removeClass('mw-collapsed');
                $container.removeClass('expanded mw-collapsed');
                } else {
                    $container.addClass('mw-collapsed');
                }
            });
           
            if ($container.hasClass('mw-collapsed')) {
                $container.find('.mw-collapsible-content').hide();
            } else {
                $container.find('.mw-collapsible-content').show();
            }
        }
    });
});
 
// Ragnawiki Custom Collapsible
(function() {
    function initRagnawikiCollapsible() {
        // Find all collapsible containers
        var containers = document.querySelectorAll('.mw-collapsible');
       
        containers.forEach(function(container) {
            // Find the header
            var header = container.querySelector('.ragnawiki-card-header');
           
            if (header && !header.hasAttribute('data-collapsible-initialized')) {
                header.setAttribute('data-collapsible-initialized', 'true');
                header.style.cursor = 'pointer';
                  
                  
                 var content = container.querySelector('.mw-collapsible-content');
                 // Start collapsed by default
                $content.hide();
                  
                  
                 if (content) {
                 // Add click handler
                     // Set initial state
                $header.on('click.collapsible', function(e) {
                     if (container.classList.contains('mw-collapsed')) {
                     e.preventDefault();
                         content.style.display = 'none';
                    e.stopPropagation();
                   
                     if ($container.hasClass('expanded')) {
                         // Collapse
                        $container.removeClass('expanded');
                        $content.slideUp(200);
                     } else {
                     } else {
                         content.style.display = 'block';
                         // Expand
                        $container.addClass('expanded');
                        $content.slideDown(200);
                     }
                     }
                      
                      
                     // Add click handler
                     return false;
                    header.addEventListener('click', function(e) {
                });
                        e.preventDefault();
               
                       
                console.log("Collapsible initialized for:", $header.text().trim());
                        if (container.classList.contains('mw-collapsed')) {
                            container.classList.remove('mw-collapsed');
                            content.style.display = 'block';
                        } else {
                            container.classList.add('mw-collapsed');
                            content.style.display = 'none';
                        }
                    });
                }
             }
             }
         });
         });
    }, 100);
});
/* Force Table of Contents to start collapsed */
$(document).ready(function() {
    var tocToggle = document.getElementById('togglelink');
    if (tocToggle && tocToggle.innerText !== 'show') {
        tocToggle.click();
     }
     }
   
});
    // Run when page loads
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initRagnawikiCollapsible);
    } else {
        initRagnawikiCollapsible();
    }
})();

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