MediaWiki:Common.js
From Hidden Mickey Wiki
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// JavaScript code to save checkbox state and restore it when the page loads
$(document).ready(function() {
// Function to save the state of checkboxes to localStorage
function saveCheckboxState() {
$('input[type="checkbox"]').each(function() {
localStorage.setItem($(this).attr('id'), $(this).prop('checked'));
});
}
// Function to load the state of checkboxes from localStorage
function loadCheckboxState() {
$('input[type="checkbox"]').each(function() {
const savedState = localStorage.getItem($(this).attr('id'));
if (savedState !== null) {
$(this).prop('checked', savedState === 'true');
}
});
}
// Load the saved checkbox state when the page is loaded
loadCheckboxState();
// Save the checkbox state whenever a checkbox is changed
$('input[type="checkbox"]').change(function() {
saveCheckboxState();
});
});
// Adjust the search box width
$(document).ready(function () {
$('#searchInput').css('width', '600px'); // Adjust width as needed
});
/* Settings dropdown test */
$(function() {
// Find the navbar container
var navbar = $('#mw-head'); // change selector if Medik uses a different container
if (!navbar.length) {
navbar = $('.medik-navbar'); // fallback, replace with actual Medik navbar class
}
// Inject the dropdown as a sibling to the user menu, not inside it
var settingsDropdown = `
<div class="mw-settings-dropdown">
<button class="mw-settings-btn">⚙ Settings ▼</button>
<div class="mw-settings-menu">
<a href="/wiki/Special:Preferences">Preferences</a>
</div>
</div>
`;
// Insert BEFORE the user menu container (#p-personal)
$('#p-personal').before(settingsDropdown);
});