MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Add The World and Skills dropdowns in Compendium sidebar |
Update Compendium sidebar dropdowns to hover-over flyout submenus |
||
| Line 1: | Line 1: | ||
/* UO Renaissance Wiki Common.js */ | /* UO Renaissance Wiki Common.js */ | ||
(function() { | (function() { | ||
// Add Hover Flyout Submenus for The World & Skills inside Compendium | |||
var compendiumPortal = document.getElementById('p-Compendium'); | |||
if (! | if (compendiumPortal) { | ||
function attachSidebarSubmenu(liSelector, titleMatch, items) { | |||
var li = compendiumPortal.querySelector(liSelector) || | |||
compendiumPortal.querySelector('a[href*="' + titleMatch + '"]')?.closest('li'); | |||
if (!li || li.querySelector('.uor-sidebar-submenu')) return; | |||
li.classList.add('uor-sidebar-has-submenu'); | |||
var | var link = li.querySelector(':scope > a'); | ||
var | if (link && !link.querySelector('.uor-submenu-arrow')) { | ||
var arrow = document.createElement('span'); | |||
arrow.className = 'uor-submenu-arrow'; | |||
arrow.innerHTML = '▸'; | |||
arrow.title = 'View Sections'; | |||
} | arrow.addEventListener('click', function(e) { | ||
e.preventDefault(); | |||
e.stopPropagation(); | |||
li.classList.toggle('is-open'); | |||
}); | |||
link.appendChild(arrow); | |||
} | } | ||
var submenu = document.createElement('ul'); | |||
submenu.className = 'uor-sidebar-submenu'; | |||
var html = ''; | |||
for (var i = 0; i < items.length; i++) { | |||
html += '<li><a href="' + items[i].href + '">' + items[i].label + '</a></li>'; | |||
} | |||
submenu.innerHTML = html; | |||
li.appendChild(submenu); | |||
} | |||
// 1. The World Submenu | |||
attachSidebarSubmenu('li#n-The-World', '/wiki/index.php/The_World', [ | |||
{ label: 'Towns', href: '/wiki/index.php/The_World#Towns' }, | |||
{ label: 'Dungeons', href: '/wiki/index.php/The_World#Dungeons' }, | |||
{ label: 'Points of Interest', href: '/wiki/index.php/The_World#Points_of_Interest' } | |||
]); | |||
// 2. Skills | // 2. Skills Submenu | ||
attachSidebarSubmenu('li#n-Skills', '/wiki/index.php/Skills', [ | |||
{ label: 'Combat', href: '/wiki/index.php/Skills#Combat' }, | |||
{ label: 'Crafting', href: '/wiki/index.php/Skills#Crafting' }, | |||
{ label: 'Creatures', href: '/wiki/index.php/Skills#Creatures' }, | |||
{ label: 'Lore & Knowledge', href: '/wiki/index.php/Skills#Lore_&_Knowledge' }, | |||
{ label: 'Miscellaneous', href: '/wiki/index.php/Skills#Miscellaneous' }, | |||
{ label: 'Rogue', href: '/wiki/index.php/Skills#Rogue' }, | |||
{ label: 'Spells & Magic', href: '/wiki/index.php/Spells' } | |||
]); | |||
document.addEventListener('click', function(e) { | |||
if (!e.target.closest('.uor-sidebar-has-submenu')) { | |||
var openMenus = document.querySelectorAll('.uor-sidebar-has-submenu.is-open'); | |||
for (var i = 0; i < openMenus.length; i++) { | |||
openMenus[i].classList.remove('is-open'); | |||
} | } | ||
} | } | ||
}); | |||
} | } | ||
})(); | })(); | ||
Revision as of 13:38, 8 September 2026
/* UO Renaissance Wiki Common.js */
(function() {
// Add Hover Flyout Submenus for The World & Skills inside Compendium
var compendiumPortal = document.getElementById('p-Compendium');
if (compendiumPortal) {
function attachSidebarSubmenu(liSelector, titleMatch, items) {
var li = compendiumPortal.querySelector(liSelector) ||
compendiumPortal.querySelector('a[href*="' + titleMatch + '"]')?.closest('li');
if (!li || li.querySelector('.uor-sidebar-submenu')) return;
li.classList.add('uor-sidebar-has-submenu');
var link = li.querySelector(':scope > a');
if (link && !link.querySelector('.uor-submenu-arrow')) {
var arrow = document.createElement('span');
arrow.className = 'uor-submenu-arrow';
arrow.innerHTML = '▸';
arrow.title = 'View Sections';
arrow.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
li.classList.toggle('is-open');
});
link.appendChild(arrow);
}
var submenu = document.createElement('ul');
submenu.className = 'uor-sidebar-submenu';
var html = '';
for (var i = 0; i < items.length; i++) {
html += '<li><a href="' + items[i].href + '">' + items[i].label + '</a></li>';
}
submenu.innerHTML = html;
li.appendChild(submenu);
}
// 1. The World Submenu
attachSidebarSubmenu('li#n-The-World', '/wiki/index.php/The_World', [
{ label: 'Towns', href: '/wiki/index.php/The_World#Towns' },
{ label: 'Dungeons', href: '/wiki/index.php/The_World#Dungeons' },
{ label: 'Points of Interest', href: '/wiki/index.php/The_World#Points_of_Interest' }
]);
// 2. Skills Submenu
attachSidebarSubmenu('li#n-Skills', '/wiki/index.php/Skills', [
{ label: 'Combat', href: '/wiki/index.php/Skills#Combat' },
{ label: 'Crafting', href: '/wiki/index.php/Skills#Crafting' },
{ label: 'Creatures', href: '/wiki/index.php/Skills#Creatures' },
{ label: 'Lore & Knowledge', href: '/wiki/index.php/Skills#Lore_&_Knowledge' },
{ label: 'Miscellaneous', href: '/wiki/index.php/Skills#Miscellaneous' },
{ label: 'Rogue', href: '/wiki/index.php/Skills#Rogue' },
{ label: 'Spells & Magic', href: '/wiki/index.php/Spells' }
]);
document.addEventListener('click', function(e) {
if (!e.target.closest('.uor-sidebar-has-submenu')) {
var openMenus = document.querySelectorAll('.uor-sidebar-has-submenu.is-open');
for (var i = 0; i < openMenus.length; i++) {
openMenus[i].classList.remove('is-open');
}
}
});
}
})();