We are actively looking for staff to help us build the wiki. If you are interested please join our Discord server and apply.
MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(Created page with "/** * Collapsible elements * * Add the "collapsible" class to an element and the child element with class "collapsible-content" * (or everything but the header row if a table) will be hidden when the element is collapsed. * * * Add the class "collapsed" to the element to make it start out collapsed. * * Add either "collapsetoggle-left" or "collapsetoggle-inline" to the element to choose the collapse * toggle alignment (defaults to right). * * Add an ID in the...") |
mNo edit summary |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
$(document).ready(function() { | |||
// Function to toggle the collapse | |||
function toggleSidebarCategory(category) { | |||
$('#' + category + ' > .body').slideToggle(); | |||
$('#' + category + ' > .head').toggleClass('collapsed'); | |||
} | |||
// Add toggle link to each category header | |||
$('#mw-panel .portal > h3').each(function() { | |||
var category = $(this).parent().attr('id'); | |||
$(this).addClass('head').click(function() { | |||
toggleSidebarCategory(category); | |||
}); | |||
}); | |||
// Hide all categories by default | |||
$('#mw-panel .portal > .body').hide(); | |||
$('#mw-panel .portal > h3').addClass('collapsed'); | |||
}); | |||
document.addEventListener('DOMContentLoaded', function() { | |||
const icons = document.querySelectorAll('.masterlist-icon'); | |||
console.log('Custom script loaded'); | |||
console.log('Icons found:', icons); | |||
icons.forEach(function(icon) { | |||
console.log('Icon:', icon); | |||
}); | |||
icons.forEach(function(icon) { | |||
const itemId = icon.closest('.masterlist-item').dataset.id; | |||
console.log('Item ID:', itemId); | |||
const isClicked = localStorage.getItem('icon-' + itemId) === 'true'; | |||
if (isClicked) { | |||
icon.classList.add('clicked'); | |||
} | |||
}); | |||
icons.forEach(function(icon) { | |||
icon.addEventListener('click', function(event) { | |||
event.preventDefault(); | |||
const itemId = icon.closest('.masterlist-item').dataset.id; | |||
console.log('Clicked Item ID:', itemId); | |||
icon.classList.toggle('clicked'); | |||
localStorage.setItem('icon-' + itemId, icon.classList.contains('clicked')); | |||
}); | |||
}); | |||
}); | |||
} |
Latest revision as of 18:44, 25 June 2024
$(document).ready(function() { // Function to toggle the collapse function toggleSidebarCategory(category) { $('#' + category + ' > .body').slideToggle(); $('#' + category + ' > .head').toggleClass('collapsed'); } // Add toggle link to each category header $('#mw-panel .portal > h3').each(function() { var category = $(this).parent().attr('id'); $(this).addClass('head').click(function() { toggleSidebarCategory(category); }); }); // Hide all categories by default $('#mw-panel .portal > .body').hide(); $('#mw-panel .portal > h3').addClass('collapsed'); }); document.addEventListener('DOMContentLoaded', function() { const icons = document.querySelectorAll('.masterlist-icon'); console.log('Custom script loaded'); console.log('Icons found:', icons); icons.forEach(function(icon) { console.log('Icon:', icon); }); icons.forEach(function(icon) { const itemId = icon.closest('.masterlist-item').dataset.id; console.log('Item ID:', itemId); const isClicked = localStorage.getItem('icon-' + itemId) === 'true'; if (isClicked) { icon.classList.add('clicked'); } }); icons.forEach(function(icon) { icon.addEventListener('click', function(event) { event.preventDefault(); const itemId = icon.closest('.masterlist-item').dataset.id; console.log('Clicked Item ID:', itemId); icon.classList.toggle('clicked'); localStorage.setItem('icon-' + itemId, icon.classList.contains('clicked')); }); }); });