MediaWiki:Common.js: Difference between revisions
From Ragnafied Wiki
No edit summary |
No edit summary Tag: Reverted |
||
| Line 92: | Line 92: | ||
} | } | ||
}); | }); | ||
// Dark mode toggle | |||
$(document).ready(function() { | |||
$('body').append( | |||
'<div id="dark-mode-toggle" title="Toggle Dark Mode">🌙</div>' | |||
); | |||
// Check for saved preference | |||
if (localStorage.getItem('darkMode') === 'enabled') { | |||
enableDarkMode(); | |||
} | |||
$('#dark-mode-toggle').on('click', function() { | |||
if ($('body').hasClass('dark-mode')) { | |||
disableDarkMode(); | |||
} else { | |||
enableDarkMode(); | |||
} | |||
}); | |||
}); | |||
function enableDarkMode() { | |||
$('body').addClass('dark-mode'); | |||
localStorage.setItem('darkMode', 'enabled'); | |||
// Add CSS dynamically | |||
var darkModeCSS = ` | |||
body.dark-mode { | |||
background-color: #1a1a1a; | |||
color: #e0e0e0; | |||
} | |||
body.dark-mode #content { | |||
background-color: #2d2d2d; | |||
} | |||
body.dark-mode a { | |||
color: #8cb4ff; | |||
} | |||
body.dark-mode #mw-head { | |||
background-color: #333; | |||
} | |||
`; | |||
if (!$('#dark-mode-styles').length) { | |||
$('head').append('<style id="dark-mode-styles">' + darkModeCSS + '</style>'); | |||
} | |||
} | |||
function disableDarkMode() { | |||
$('body').removeClass('dark-mode'); | |||
localStorage.setItem('darkMode', 'disabled'); | |||
} | |||
Revision as of 00:29, 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');
}
});
// Dark mode toggle
$(document).ready(function() {
$('body').append(
'<div id="dark-mode-toggle" title="Toggle Dark Mode">🌙</div>'
);
// Check for saved preference
if (localStorage.getItem('darkMode') === 'enabled') {
enableDarkMode();
}
$('#dark-mode-toggle').on('click', function() {
if ($('body').hasClass('dark-mode')) {
disableDarkMode();
} else {
enableDarkMode();
}
});
});
function enableDarkMode() {
$('body').addClass('dark-mode');
localStorage.setItem('darkMode', 'enabled');
// Add CSS dynamically
var darkModeCSS = `
body.dark-mode {
background-color: #1a1a1a;
color: #e0e0e0;
}
body.dark-mode #content {
background-color: #2d2d2d;
}
body.dark-mode a {
color: #8cb4ff;
}
body.dark-mode #mw-head {
background-color: #333;
}
`;
if (!$('#dark-mode-styles').length) {
$('head').append('<style id="dark-mode-styles">' + darkModeCSS + '</style>');
}
}
function disableDarkMode() {
$('body').removeClass('dark-mode');
localStorage.setItem('darkMode', 'disabled');
}
