MediaWiki:Common.js: Difference between revisions
From Ragnafied Wiki
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
<span>📋 QUICK NAV</span> | <span>📋 QUICK NAV</span> | ||
<span class="arrow">▼</span> | <span class="arrow">▼</span> | ||
<span class="drag-handle" style="cursor: | <span class="drag-handle" style="cursor: grab; margin-left: auto; font-size: 12px; opacity: 0.7; user-select: none;" title="Drag to move">⋮⋮</span> | ||
</div> | </div> | ||
<div class="floating-menu-items"> | <div class="floating-menu-items"> | ||
| Line 30: | Line 30: | ||
var lastScrollTop = 0; | var lastScrollTop = 0; | ||
// Store position in localStorage | // Store position in localStorage | ||
function saveMenuPosition(left, top | function saveMenuPosition(left, top) { | ||
if (typeof(Storage) !== "undefined") { | if (typeof(Storage) !== "undefined") { | ||
localStorage.setItem('quickNavLeft', left); | |||
localStorage.setItem('quickNavTop', top); | localStorage.setItem('quickNavTop', top); | ||
} | } | ||
| Line 47: | Line 40: | ||
function loadMenuPosition() { | function loadMenuPosition() { | ||
if (typeof(Storage) !== "undefined") { | if (typeof(Storage) !== "undefined") { | ||
var savedLeft = localStorage.getItem('quickNavLeft'); | var savedLeft = localStorage.getItem('quickNavLeft'); | ||
var savedTop = localStorage.getItem('quickNavTop'); | var savedTop = localStorage.getItem('quickNavTop'); | ||
if ( | if (savedLeft !== null && savedTop !== null) { | ||
$('#floatingMenu').css({ | |||
left: savedLeft, | |||
top: savedTop, | |||
right: 'auto', | |||
bottom: 'auto' | |||
}); | |||
} | |||
return true; | return true; | ||
} | } | ||
| Line 76: | Line 57: | ||
function setDefaultPosition() { | function setDefaultPosition() { | ||
var $menu = $('#floatingMenu'); | var $menu = $('#floatingMenu'); | ||
var windowWidth = $(window).width(); | |||
var windowHeight = $(window).height(); | var windowHeight = $(window).height(); | ||
var menuWidth = $menu.outerWidth(); | |||
var menuHeight = $menu.outerHeight(); | var menuHeight = $menu.outerHeight(); | ||
// Default: right side with 20px margin, vertically centered | |||
var defaultLeft = windowWidth - menuWidth - 20; | |||
var defaultTop = (windowHeight / 2) - (menuHeight / 2); | var defaultTop = (windowHeight / 2) - (menuHeight / 2); | ||
// Keep within bounds | |||
defaultLeft = Math.max(5, Math.min(defaultLeft, windowWidth - menuWidth - 5)); | |||
defaultTop = Math.max(5, Math.min(defaultTop, windowHeight - menuHeight - 5)); | |||
$menu.css({ | $menu.css({ | ||
left: defaultLeft + 'px', | |||
top: defaultTop + 'px', | top: defaultTop + 'px', | ||
right: 'auto', | |||
bottom: 'auto' | bottom: 'auto' | ||
}); | }); | ||
| Line 92: | Line 80: | ||
// Save default position | // Save default position | ||
if (typeof(Storage) !== "undefined") { | if (typeof(Storage) !== "undefined") { | ||
localStorage.setItem(' | localStorage.setItem('quickNavLeft', defaultLeft + 'px'); | ||
localStorage.setItem('quickNavTop', defaultTop + 'px'); | localStorage.setItem('quickNavTop', defaultTop + 'px'); | ||
} | } | ||
} | } | ||
// Make menu draggable | // Make menu draggable - SMOOTH version | ||
var $menu = $('#floatingMenu'); | var $menu = $('#floatingMenu'); | ||
var $dragHandle = $('.drag-handle'); | var $dragHandle = $('.drag-handle'); | ||
var isDragging = false; | var isDragging = false; | ||
var | var dragStartX, dragStartY; | ||
var | var menuStartLeft, menuStartTop; | ||
// | // Set initial position | ||
setTimeout(function() { | setTimeout(function() { | ||
if (!loadMenuPosition()) { | if (!loadMenuPosition()) { | ||
| Line 116: | Line 104: | ||
isDragging = true; | isDragging = true; | ||
// | // Store starting positions | ||
dragStartX = e.clientX; | |||
dragStartY = e.clientY; | |||
menuStartLeft = parseInt($menu.css('left')); | |||
menuStartTop = parseInt($menu.css('top')); | |||
// Change cursor | // Change cursor | ||
$dragHandle.css('cursor', 'grabbing'); | |||
$menu.css('cursor', 'grabbing'); | $menu.css('cursor', 'grabbing'); | ||
// Disable text selection during drag | |||
$('body').css('user-select', 'none'); | |||
}); | }); | ||
| Line 139: | Line 122: | ||
e.preventDefault(); | e.preventDefault(); | ||
var | // Calculate new position | ||
var deltaX = e.clientX - dragStartX; | |||
var deltaY = e.clientY - dragStartY; | |||
var newLeft = menuStartLeft + deltaX; | |||
var | var newTop = menuStartTop + deltaY; | ||
newTop = | |||
// Apply boundaries (soft constraints - no sticking) | |||
var maxLeft = $(window).width() - $menu.outerWidth() - 5; | |||
var maxTop = $(window).height() - $menu.outerHeight() - 5; | |||
newLeft = Math.min(Math.max(5, newLeft), maxLeft); | |||
newTop = Math.min(Math.max(5, newTop), maxTop); | |||
// Apply position | |||
$menu.css({ | |||
left: newLeft + 'px', | |||
top: newTop + 'px', | |||
right: 'auto', | |||
bottom: 'auto' | |||
}); | |||
} | } | ||
}); | }); | ||
| Line 173: | Line 149: | ||
if (isDragging) { | if (isDragging) { | ||
isDragging = false; | isDragging = false; | ||
$dragHandle.css('cursor', 'grab'); | |||
$menu.css('cursor', ''); | $menu.css('cursor', ''); | ||
$('body').css('user-select', ''); | |||
// Save position | // Save position | ||
var currentLeft = $menu.css('left'); | var currentLeft = $menu.css('left'); | ||
var currentTop = $menu.css('top'); | var currentTop = $menu.css('top'); | ||
saveMenuPosition(currentLeft, currentTop); | |||
} | } | ||
}); | }); | ||
// Optional: Add a reset button | // Optional: Add a reset button | ||
var resetButton = $('<span class="reset-pos" style="cursor: pointer; margin-left: 5px; font-size: 10px; opacity: 0.6;" title="Reset position">↺</span>'); | var resetButton = $('<span class="reset-pos" style="cursor: pointer; margin-left: 5px; font-size: 10px; opacity: 0.6;" title="Reset position">↺</span>'); | ||
resetButton.on('click', function(e) { | resetButton.on('click', function(e) { | ||
| Line 208: | Line 180: | ||
else { $('.back-to-top-fixed').fadeOut(); } | else { $('.back-to-top-fixed').fadeOut(); } | ||
// D. Section Tracker | // D. Section Tracker | ||
var currentPath = window.location.pathname; | var currentPath = window.location.pathname; | ||
$('.floating-menu-items a').each(function() { | $('.floating-menu-items a').each(function() { | ||
| Line 221: | Line 193: | ||
// Toggle Events | // Toggle Events | ||
$('#menuHeader').click(function(e) { | $('#menuHeader').click(function(e) { | ||
if ($(e.target).hasClass('drag-handle') || $(e.target).hasClass('reset-pos')) { | if ($(e.target).hasClass('drag-handle') || $(e.target).hasClass('reset-pos')) { | ||
return; | return; | ||
| Line 233: | Line 204: | ||
}); | }); | ||
// | // Handle window resize | ||
$(window).on('resize', function() { | $(window).on('resize', function() { | ||
var | var $menu = $('#floatingMenu'); | ||
var | var currentLeft = parseInt($menu.css('left')); | ||
var currentTop = parseInt($menu.css('top')); | |||
var windowWidth = $(window).width(); | |||
var windowHeight = $(window).height(); | |||
var menuWidth = $menu.outerWidth(); | |||
var menuHeight = $menu.outerHeight(); | |||
// | // Adjust if out of bounds after resize | ||
if ( | var newLeft = Math.min(Math.max(5, currentLeft), windowWidth - menuWidth - 5); | ||
var newTop = Math.min(Math.max(5, currentTop), windowHeight - menuHeight - 5); | |||
if (newLeft !== currentLeft || newTop !== currentTop) { | |||
$menu.css({ | |||
left: newLeft + 'px', | |||
top: newTop + 'px' | |||
}); | |||
saveMenuPosition(newLeft + 'px', newTop + 'px'); | |||
} | } | ||
}); | }); | ||
| Line 271: | Line 254: | ||
console.log("Ragnawiki collapsible initializing..."); | console.log("Ragnawiki collapsible initializing..."); | ||
if (typeof mw !== 'undefined' && mw.loader) { | if (typeof mw !== 'undefined' && mw.loader) { | ||
mw.loader.using('jquery.makeCollapsible', function() { | mw.loader.using('jquery.makeCollapsible', function() { | ||
$.fn.makeCollapsible = function() { return this; }; | $.fn.makeCollapsible = function() { return this; }; | ||
}); | }); | ||
} | } | ||
$('.mw-collapsible-toggle').remove(); | $('.mw-collapsible-toggle').remove(); | ||
$('.mw-made-collapsible').removeClass('mw-made-collapsible'); | $('.mw-made-collapsible').removeClass('mw-made-collapsible'); | ||
setTimeout(function() { | setTimeout(function() { | ||
$('.mw-collapsible').each(function() { | $('.mw-collapsible').each(function() { | ||
var $container = $(this); | var $container = $(this); | ||
| Line 292: | Line 270: | ||
if ($header.length && $content.length) { | if ($header.length && $content.length) { | ||
$header.off('click.collapsible'); | $header.off('click.collapsible'); | ||
$container.removeClass('expanded mw-collapsed'); | $container.removeClass('expanded mw-collapsed'); | ||
$content.hide(); | $content.hide(); | ||
$header.on('click.collapsible', function(e) { | $header.on('click.collapsible', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
| Line 307: | Line 279: | ||
if ($container.hasClass('expanded')) { | if ($container.hasClass('expanded')) { | ||
$container.removeClass('expanded'); | $container.removeClass('expanded'); | ||
$content.slideUp(200); | $content.slideUp(200); | ||
} else { | } else { | ||
$container.addClass('expanded'); | $container.addClass('expanded'); | ||
$content.slideDown(200); | $content.slideDown(200); | ||
Revision as of 19:58, 13 April 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>
<span class="drag-handle" style="cursor: grab; margin-left: auto; font-size: 12px; opacity: 0.7; user-select: none;" title="Drag to move">⋮⋮</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;
// Store position in localStorage
function saveMenuPosition(left, top) {
if (typeof(Storage) !== "undefined") {
localStorage.setItem('quickNavLeft', left);
localStorage.setItem('quickNavTop', top);
}
}
function loadMenuPosition() {
if (typeof(Storage) !== "undefined") {
var savedLeft = localStorage.getItem('quickNavLeft');
var savedTop = localStorage.getItem('quickNavTop');
if (savedLeft !== null && savedTop !== null) {
$('#floatingMenu').css({
left: savedLeft,
top: savedTop,
right: 'auto',
bottom: 'auto'
});
return true;
}
}
return false;
}
function setDefaultPosition() {
var $menu = $('#floatingMenu');
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var menuWidth = $menu.outerWidth();
var menuHeight = $menu.outerHeight();
// Default: right side with 20px margin, vertically centered
var defaultLeft = windowWidth - menuWidth - 20;
var defaultTop = (windowHeight / 2) - (menuHeight / 2);
// Keep within bounds
defaultLeft = Math.max(5, Math.min(defaultLeft, windowWidth - menuWidth - 5));
defaultTop = Math.max(5, Math.min(defaultTop, windowHeight - menuHeight - 5));
$menu.css({
left: defaultLeft + 'px',
top: defaultTop + 'px',
right: 'auto',
bottom: 'auto'
});
// Save default position
if (typeof(Storage) !== "undefined") {
localStorage.setItem('quickNavLeft', defaultLeft + 'px');
localStorage.setItem('quickNavTop', defaultTop + 'px');
}
}
// Make menu draggable - SMOOTH version
var $menu = $('#floatingMenu');
var $dragHandle = $('.drag-handle');
var isDragging = false;
var dragStartX, dragStartY;
var menuStartLeft, menuStartTop;
// Set initial position
setTimeout(function() {
if (!loadMenuPosition()) {
setDefaultPosition();
}
}, 100);
$dragHandle.on('mousedown', function(e) {
e.preventDefault();
e.stopPropagation();
isDragging = true;
// Store starting positions
dragStartX = e.clientX;
dragStartY = e.clientY;
menuStartLeft = parseInt($menu.css('left'));
menuStartTop = parseInt($menu.css('top'));
// Change cursor
$dragHandle.css('cursor', 'grabbing');
$menu.css('cursor', 'grabbing');
// Disable text selection during drag
$('body').css('user-select', 'none');
});
$(document).on('mousemove', function(e) {
if (isDragging) {
e.preventDefault();
// Calculate new position
var deltaX = e.clientX - dragStartX;
var deltaY = e.clientY - dragStartY;
var newLeft = menuStartLeft + deltaX;
var newTop = menuStartTop + deltaY;
// Apply boundaries (soft constraints - no sticking)
var maxLeft = $(window).width() - $menu.outerWidth() - 5;
var maxTop = $(window).height() - $menu.outerHeight() - 5;
newLeft = Math.min(Math.max(5, newLeft), maxLeft);
newTop = Math.min(Math.max(5, newTop), maxTop);
// Apply position
$menu.css({
left: newLeft + 'px',
top: newTop + 'px',
right: 'auto',
bottom: 'auto'
});
}
});
$(document).on('mouseup', function() {
if (isDragging) {
isDragging = false;
$dragHandle.css('cursor', 'grab');
$menu.css('cursor', '');
$('body').css('user-select', '');
// Save position
var currentLeft = $menu.css('left');
var currentTop = $menu.css('top');
saveMenuPosition(currentLeft, currentTop);
}
});
// Optional: Add a reset button
var resetButton = $('<span class="reset-pos" style="cursor: pointer; margin-left: 5px; font-size: 10px; opacity: 0.6;" title="Reset position">↺</span>');
resetButton.on('click', function(e) {
e.stopPropagation();
setDefaultPosition();
});
$('.floating-menu-header span:first-child').after(resetButton);
$(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(); }
// D. Section Tracker
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(e) {
if ($(e.target).hasClass('drag-handle') || $(e.target).hasClass('reset-pos')) {
return;
}
$('#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);
});
// Handle window resize
$(window).on('resize', function() {
var $menu = $('#floatingMenu');
var currentLeft = parseInt($menu.css('left'));
var currentTop = parseInt($menu.css('top'));
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var menuWidth = $menu.outerWidth();
var menuHeight = $menu.outerHeight();
// Adjust if out of bounds after resize
var newLeft = Math.min(Math.max(5, currentLeft), windowWidth - menuWidth - 5);
var newTop = Math.min(Math.max(5, currentTop), windowHeight - menuHeight - 5);
if (newLeft !== currentLeft || newTop !== currentTop) {
$menu.css({
left: newLeft + 'px',
top: newTop + 'px'
});
saveMenuPosition(newLeft + 'px', newTop + 'px');
}
});
});
// 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...");
if (typeof mw !== 'undefined' && mw.loader) {
mw.loader.using('jquery.makeCollapsible', function() {
$.fn.makeCollapsible = function() { return this; };
});
}
$('.mw-collapsible-toggle').remove();
$('.mw-made-collapsible').removeClass('mw-made-collapsible');
setTimeout(function() {
$('.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) {
$header.off('click.collapsible');
$container.removeClass('expanded mw-collapsed');
$content.hide();
$header.on('click.collapsible', function(e) {
e.preventDefault();
e.stopPropagation();
if ($container.hasClass('expanded')) {
$container.removeClass('expanded');
$content.slideUp(200);
} else {
$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();
}
});
