MediaWiki:Common.js: Difference between revisions
From Hidden Mickey Wiki
No edit summary |
No edit summary |
||
| Line 32: | Line 32: | ||
$('#searchInput').css('width', '600px'); // Adjust width as needed | $('#searchInput').css('width', '600px'); // Adjust width as needed | ||
}); | }); | ||
// Move search box to the left | |||
$(function () { | |||
var $search = $('#p-search, #simpleSearch'); // covers both IDs | |||
var $navbarLeft = $('#mw-navbar-left'); | |||
if ($search.length && $navbarLeft.length) { | |||
// Move search into the left navbar (after logo, at far right of that section) | |||
$navbarLeft.append($search); | |||
} | |||
}); | |||
/* === Settings dropdown at far left of mw-navbar-right === */ | /* === Settings dropdown at far left of mw-navbar-right === */ | ||
Revision as of 09:03, 19 September 2025
/* 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
});
// Move search box to the left
$(function () {
var $search = $('#p-search, #simpleSearch'); // covers both IDs
var $navbarLeft = $('#mw-navbar-left');
if ($search.length && $navbarLeft.length) {
// Move search into the left navbar (after logo, at far right of that section)
$navbarLeft.append($search);
}
});
/* === Settings dropdown at far left of mw-navbar-right === */
$(function () {
// Prevent duplicate
if ($('#mw-settings-dropdown').length) return;
// Create container
var $container = $('<div id="mw-settings-dropdown"></div>');
var $button = $('<button>Settings ▾</button>');
var $list = $('<ul></ul>');
// Define menu items
var menuItems = [
{ title: 'Preferences', page: 'Special:Preferences' },
{ title: 'Watchlist', page: 'Special:Watchlist' },
{ title: 'My talk', page: 'Special:MyTalk' }
];
// Populate dropdown
menuItems.forEach(function(item) {
var $li = $('<li></li>');
var $a = $('<a></a>').attr('href', mw.util.getUrl(item.page)).text(item.title);
$li.append($a);
$list.append($li);
});
$container.append($button).append($list);
// Insert into navbar-right if exists
var $navbar = $('#mw-navbar-right');
if ($navbar.length) {
// Prepend = place at far left of navbar-right
$navbar.prepend($container);
} else {
// fallback: absolute top-right
$container.css({ position: 'absolute', top: '10px', right: '10px' });
$('body').append($container);
}
// Toggle dropdown
$button.on('click', function(e) {
$list.toggle();
e.stopPropagation();
});
// Close dropdown when clicking outside
$(document).on('click', function() {
$list.hide();
});
$container.on('click', function(e) {
e.stopPropagation();
});
});