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
mNo edit summary |
mNo edit summary |
||
Line 9: | Line 9: | ||
$('#mw-panel .portal > h3').each(function() { | $('#mw-panel .portal > h3').each(function() { | ||
var category = $(this).parent().attr('id'); | var category = $(this).parent().attr('id'); | ||
$(this).addClass('head').click(function() { toggleSidebarCategory(category); }); | $(this).addClass('head').click(function() { | ||
toggleSidebarCategory(category); | |||
}); | |||
}); | }); | ||
Line 18: | Line 20: | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function() { | ||
const icons = document.querySelectorAll('.masterlist-icon'); | |||
console.log('Icons found:', icons); | |||
// Load saved state from localStorage | |||
icon.addEventListener('click', function() { | icons.forEach(function(icon) { | ||
const itemId = icon.closest('.masterlist-item').dataset.id; | |||
const isClicked = localStorage.getItem('icon-' + itemId) === 'true'; | |||
if (isClicked) { | |||
icon.classList.add('clicked'); | |||
} | |||
}); | |||
// Add click event listeners to toggle clicked state and save to localStorage | |||
icons.forEach(function(icon) { | |||
icon.addEventListener('click', function() { | |||
const itemId = icon.closest('.masterlist-item').dataset.id; | |||
icon.classList.toggle('clicked'); | |||
localStorage.setItem('icon-' + itemId, icon.classList.contains('clicked')); | |||
}); | |||
}); | }); | ||
}); | }); |
Revision as of 17:26, 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('Icons found:', icons); // Load saved state from localStorage icons.forEach(function(icon) { const itemId = icon.closest('.masterlist-item').dataset.id; const isClicked = localStorage.getItem('icon-' + itemId) === 'true'; if (isClicked) { icon.classList.add('clicked'); } }); // Add click event listeners to toggle clicked state and save to localStorage icons.forEach(function(icon) { icon.addEventListener('click', function() { const itemId = icon.closest('.masterlist-item').dataset.id; icon.classList.toggle('clicked'); localStorage.setItem('icon-' + itemId, icon.classList.contains('clicked')); }); }); });