MediaWiki:Common.js: Difference between revisions
From Ragnafied Wiki
No edit summary |
No edit summary |
||
| Line 45: | Line 45: | ||
if (savedX !== null && savedY !== null) { | if (savedX !== null && savedY !== null) { | ||
$('#floatingMenu').css({ | $('#floatingMenu').css({ | ||
transform: ' | transform: 'translate3d(' + savedX + 'px, ' + savedY + 'px, 0)', | ||
right: 'auto', | right: 'auto', | ||
left: '0', | left: '0', | ||
| Line 66: | Line 66: | ||
var defaultX = windowWidth - menuWidth - 20; | var defaultX = windowWidth - menuWidth - 20; | ||
var defaultY = (windowHeight / 2) - (menuHeight / 2); | var defaultY = (windowHeight / 2) - (menuHeight / 2); | ||
// Clamp values | |||
defaultX = Math.max(0, Math.min(defaultX, windowWidth - menuWidth)); | |||
defaultY = Math.max(0, Math.min(defaultY, windowHeight - menuHeight)); | |||
$menu.css({ | $menu.css({ | ||
transform: ' | transform: 'translate3d(' + defaultX + 'px, ' + defaultY + 'px, 0)', | ||
right: 'auto', | right: 'auto', | ||
left: '0', | left: '0', | ||
| Line 75: | Line 79: | ||
saveMenuPosition(defaultX, defaultY); | saveMenuPosition(defaultX, defaultY); | ||
return { x: defaultX, y: defaultY }; | |||
} | } | ||
// | // FAST DRAG with translate3d for GPU acceleration | ||
var $menu = $('#floatingMenu'); | var $menu = $('#floatingMenu'); | ||
var $dragHandle = $('.drag-handle'); | var $dragHandle = $('.drag-handle'); | ||
var isDragging = false; | var isDragging = false; | ||
var currentX = 0, currentY = 0; | var currentX = 0, currentY = 0; | ||
// Get current transform values | // Get current transform values - FAST version | ||
function | function getCurrentPosition() { | ||
var transform = $menu.css('transform'); | var transform = $menu.css('transform'); | ||
if (transform === 'none') { | if (transform === 'none') { | ||
return { x: 0, y: 0 }; | return { x: 0, y: 0 }; | ||
} | } | ||
// Handle matrix and matrix3d | |||
var matrix = transform.match(/matrix.*\((.+)\)/); | var matrix = transform.match(/matrix.*\((.+)\)/); | ||
if (matrix) { | if (matrix) { | ||
var values = matrix[1].split(', '); | var values = matrix[1].split(', '); | ||
return { x: parseFloat(values[4]), y: parseFloat(values[5]) }; | if (values.length === 6) { | ||
// matrix(a, b, c, d, tx, ty) | |||
return { x: parseFloat(values[4]), y: parseFloat(values[5]) }; | |||
} else if (values.length === 16) { | |||
// matrix3d | |||
return { x: parseFloat(values[12]), y: parseFloat(values[13]) }; | |||
} | |||
} | } | ||
return { x: 0, y: 0 }; | return { x: 0, y: 0 }; | ||
| Line 100: | Line 110: | ||
// Set initial position | // Set initial position | ||
var initialPos = setDefaultPosition(); | |||
currentX = initialPos.x; | |||
currentY = initialPos.y; | |||
var | // Try to load saved position | ||
if (loadMenuPosition()) { | |||
var loadedPos = getCurrentPosition(); | |||
} | currentX = loadedPos.x; | ||
currentY = loadedPos.y; | |||
} | |||
$dragHandle.on('mousedown', function(e) { | $dragHandle.on('mousedown', function(e) { | ||
| Line 114: | Line 126: | ||
isDragging = true; | isDragging = true; | ||
// Get current position | // Get current position at drag start | ||
var pos = | var pos = getCurrentPosition(); | ||
currentX = pos.x; | |||
currentY = pos.y; | |||
// Store initial mouse position relative to menu corner | |||
var menuOffset = $menu.offset(); | |||
dragOffsetX = e.clientX - menuOffset.left; | |||
dragOffsetY = e.clientY - menuOffset.top; | |||
// Change cursor | // Change cursor immediately | ||
$dragHandle.css('cursor', 'grabbing'); | $dragHandle.css('cursor', 'grabbing'); | ||
$menu.css('cursor', 'grabbing'); | $menu.css('cursor', 'grabbing'); | ||
$('body').css('user-select', 'none'); | $('body').css('user-select', 'none'); | ||
// Prevent any text selection | |||
return false; | |||
}); | }); | ||
var dragOffsetX = 0, dragOffsetY = 0; | |||
var rafId = null; | |||
$(document).on('mousemove', function(e) { | $(document).on('mousemove', function(e) { | ||
if (isDragging) | if (!isDragging) return; | ||
e.preventDefault(); | |||
// Calculate new position | |||
var newX = e.clientX - | // Cancel any pending animation frame | ||
var newY = e.clientY - | if (rafId) cancelAnimationFrame(rafId); | ||
// Use requestAnimationFrame for smooth 60fps dragging | |||
rafId = requestAnimationFrame(function() { | |||
// Calculate new position based on mouse position and offset | |||
var newX = e.clientX - dragOffsetX; | |||
var newY = e.clientY - dragOffsetY; | |||
// Get boundaries | // Get boundaries | ||
| Line 140: | Line 166: | ||
var maxY = $(window).height() - $menu.outerHeight(); | var maxY = $(window).height() - $menu.outerHeight(); | ||
// | // Fast boundary clamping | ||
newX = | newX = newX < 0 ? 0 : (newX > maxX ? maxX : newX); | ||
newY = | newY = newY < 0 ? 0 : (newY > maxY ? maxY : newY); | ||
// Apply transform | // Apply transform immediately | ||
$menu.css({ | $menu.css({ | ||
transform: ' | transform: 'translate3d(' + newX + 'px, ' + newY + 'px, 0)' | ||
}); | }); | ||
currentX = newX; | |||
currentY = newY; | |||
} | }); | ||
}); | }); | ||
$(document).on('mouseup', function() { | $(document).on('mouseup', function() { | ||
if (isDragging) { | if (isDragging) { | ||
if (rafId) cancelAnimationFrame(rafId); | |||
isDragging = false; | isDragging = false; | ||
$dragHandle.css('cursor', ''); | $dragHandle.css('cursor', ''); | ||
| Line 164: | Line 188: | ||
$('body').css('user-select', ''); | $('body').css('user-select', ''); | ||
// Save position | // Save final position | ||
saveMenuPosition( | saveMenuPosition(currentX, currentY); | ||
} | } | ||
}); | }); | ||
| Line 173: | Line 197: | ||
resetButton.on('click', function(e) { | resetButton.on('click', function(e) { | ||
e.stopPropagation(); | e.stopPropagation(); | ||
var newPos = setDefaultPosition(); | |||
var | currentX = newPos.x; | ||
currentY = newPos.y; | |||
}); | }); | ||
$('.floating-menu-header span:first-child').after(resetButton); | $('.floating-menu-header span:first-child').after(resetButton); | ||
| Line 216: | Line 239: | ||
}); | }); | ||
// Handle window resize | // Handle window resize - reposition if needed | ||
$(window).on('resize', function() { | $(window).on('resize', function() { | ||
var | var maxX = $(window).width() - $menu.outerWidth(); | ||
var | var maxY = $(window).height() - $menu.outerHeight(); | ||
var newX = Math.min(currentX, maxX); | |||
var newY = Math.min(currentY, maxY); | |||
newX = Math.max(0, newX); | newX = Math.max(0, newX); | ||
newY = Math.max(0, newY); | newY = Math.max(0, newY); | ||
if (newX !== | if (newX !== currentX || newY !== currentY) { | ||
$menu.css({ | $menu.css({ | ||
transform: ' | transform: 'translate3d(' + newX + 'px, ' + newY + 'px, 0)' | ||
}); | }); | ||
currentX = newX; | |||
currentY = newY; | |||
saveMenuPosition( | saveMenuPosition(currentX, currentY); | ||
} | } | ||
}); | }); | ||
}); | }); | ||
// Rest of your existing code | // Rest of your existing code remains the same... | ||
$(document).ready(function() { | $(document).ready(function() { | ||
$('a[href^="#"]').on('click', function(e) { | $('a[href^="#"]').on('click', function(e) { | ||
Revision as of 20:02, 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="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
function saveMenuPosition(x, y) {
if (typeof(Storage) !== "undefined") {
localStorage.setItem('quickNavX', x);
localStorage.setItem('quickNavY', y);
}
}
function loadMenuPosition() {
if (typeof(Storage) !== "undefined") {
var savedX = localStorage.getItem('quickNavX');
var savedY = localStorage.getItem('quickNavY');
if (savedX !== null && savedY !== null) {
$('#floatingMenu').css({
transform: 'translate3d(' + savedX + 'px, ' + savedY + 'px, 0)',
right: 'auto',
left: '0',
top: '0'
});
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 defaultX = windowWidth - menuWidth - 20;
var defaultY = (windowHeight / 2) - (menuHeight / 2);
// Clamp values
defaultX = Math.max(0, Math.min(defaultX, windowWidth - menuWidth));
defaultY = Math.max(0, Math.min(defaultY, windowHeight - menuHeight));
$menu.css({
transform: 'translate3d(' + defaultX + 'px, ' + defaultY + 'px, 0)',
right: 'auto',
left: '0',
top: '0'
});
saveMenuPosition(defaultX, defaultY);
return { x: defaultX, y: defaultY };
}
// FAST DRAG with translate3d for GPU acceleration
var $menu = $('#floatingMenu');
var $dragHandle = $('.drag-handle');
var isDragging = false;
var currentX = 0, currentY = 0;
// Get current transform values - FAST version
function getCurrentPosition() {
var transform = $menu.css('transform');
if (transform === 'none') {
return { x: 0, y: 0 };
}
// Handle matrix and matrix3d
var matrix = transform.match(/matrix.*\((.+)\)/);
if (matrix) {
var values = matrix[1].split(', ');
if (values.length === 6) {
// matrix(a, b, c, d, tx, ty)
return { x: parseFloat(values[4]), y: parseFloat(values[5]) };
} else if (values.length === 16) {
// matrix3d
return { x: parseFloat(values[12]), y: parseFloat(values[13]) };
}
}
return { x: 0, y: 0 };
}
// Set initial position
var initialPos = setDefaultPosition();
currentX = initialPos.x;
currentY = initialPos.y;
// Try to load saved position
if (loadMenuPosition()) {
var loadedPos = getCurrentPosition();
currentX = loadedPos.x;
currentY = loadedPos.y;
}
$dragHandle.on('mousedown', function(e) {
e.preventDefault();
e.stopPropagation();
isDragging = true;
// Get current position at drag start
var pos = getCurrentPosition();
currentX = pos.x;
currentY = pos.y;
// Store initial mouse position relative to menu corner
var menuOffset = $menu.offset();
dragOffsetX = e.clientX - menuOffset.left;
dragOffsetY = e.clientY - menuOffset.top;
// Change cursor immediately
$dragHandle.css('cursor', 'grabbing');
$menu.css('cursor', 'grabbing');
$('body').css('user-select', 'none');
// Prevent any text selection
return false;
});
var dragOffsetX = 0, dragOffsetY = 0;
var rafId = null;
$(document).on('mousemove', function(e) {
if (!isDragging) return;
e.preventDefault();
// Cancel any pending animation frame
if (rafId) cancelAnimationFrame(rafId);
// Use requestAnimationFrame for smooth 60fps dragging
rafId = requestAnimationFrame(function() {
// Calculate new position based on mouse position and offset
var newX = e.clientX - dragOffsetX;
var newY = e.clientY - dragOffsetY;
// Get boundaries
var maxX = $(window).width() - $menu.outerWidth();
var maxY = $(window).height() - $menu.outerHeight();
// Fast boundary clamping
newX = newX < 0 ? 0 : (newX > maxX ? maxX : newX);
newY = newY < 0 ? 0 : (newY > maxY ? maxY : newY);
// Apply transform immediately
$menu.css({
transform: 'translate3d(' + newX + 'px, ' + newY + 'px, 0)'
});
currentX = newX;
currentY = newY;
});
});
$(document).on('mouseup', function() {
if (isDragging) {
if (rafId) cancelAnimationFrame(rafId);
isDragging = false;
$dragHandle.css('cursor', '');
$menu.css('cursor', '');
$('body').css('user-select', '');
// Save final position
saveMenuPosition(currentX, currentY);
}
});
// 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();
var newPos = setDefaultPosition();
currentX = newPos.x;
currentY = newPos.y;
});
$('.floating-menu-header span:first-child').after(resetButton);
$(window).scroll(function() {
var st = $(this).scrollTop();
// Progress Bar
var docHeight = $(document).height() - $(window).height();
var scrolled = (st / docHeight) * 100;
$('#scroll-progress').css("width", scrolled + "%");
// Top Button Fade
if (st > 300) { $('.back-to-top-fixed').fadeIn(); }
else { $('.back-to-top-fixed').fadeOut(); }
// 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 - reposition if needed
$(window).on('resize', function() {
var maxX = $(window).width() - $menu.outerWidth();
var maxY = $(window).height() - $menu.outerHeight();
var newX = Math.min(currentX, maxX);
var newY = Math.min(currentY, maxY);
newX = Math.max(0, newX);
newY = Math.max(0, newY);
if (newX !== currentX || newY !== currentY) {
$menu.css({
transform: 'translate3d(' + newX + 'px, ' + newY + 'px, 0)'
});
currentX = newX;
currentY = newY;
saveMenuPosition(currentX, currentY);
}
});
});
// Rest of your existing code remains the same...
$(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);
}
});
});
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$('#mw-head').addClass('sticky-header');
} else {
$('#mw-head').removeClass('sticky-header');
}
});
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;
});
}
});
}, 100);
});
$(document).ready(function() {
var tocToggle = document.getElementById('togglelink');
if (tocToggle && tocToggle.innerText !== 'show') {
tocToggle.click();
}
});
