MediaWiki:Common.js: Difference between revisions
From Hidden Mickey Wiki
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 32: | Line 32: | ||
$('#searchInput').css('width', '600px'); // Adjust width as needed | $('#searchInput').css('width', '600px'); // Adjust width as needed | ||
}); | }); | ||
/* MediaWiki:Common.js */ | |||
// Debug check — make sure the file runs | |||
console.log("✅ Common.js is running!"); | |||
// Wait for the page to be ready | |||
$(document).ready(function () { | |||
// Avoid adding it multiple times | |||
if ($("#settings-menu").length) return; | |||
// Create a minimal dropdown | |||
var menuHtml = ` | |||
<div id="settings-menu" style="position:relative; display:inline-block; margin-left:15px;"> | |||
<button id="settings-button" style="padding:6px 12px; cursor:pointer;"> | |||
Settings ▼ | |||
</button> | |||
<div id="settings-dropdown" style=" | |||
display:none; | |||
position:absolute; | |||
background:#fff; | |||
border:1px solid #ccc; | |||
min-width:150px; | |||
z-index:9999; | |||
"> | |||
<a href="/wiki/Special:Preferences" style="display:block; padding:8px;">Preferences</a> | |||
<a href="/wiki/Special:UserLogout" style="display:block; padding:8px;">Log out</a> | |||
</div> | |||
</div> | |||
`; | |||
// Append to personal tools (usually top-right) | |||
$("#p-personal ul").first().append( | |||
$("<li>").append(menuHtml) | |||
); | |||
// Toggle dropdown visibility | |||
$(document).on("click", "#settings-button", function () { | |||
$("#settings-dropdown").toggle(); | |||
}); | |||
// Close dropdown when clicking elsewhere | |||
$(document).on("click", function (e) { | |||
if (!$(e.target).closest("#settings-menu").length) { | |||
}) | $("#settings-dropdown").hide(); | ||
} | |||
}); | |||
}); | |||
Revision as of 15:27, 18 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
});
/* MediaWiki:Common.js */
// Debug check — make sure the file runs
console.log("✅ Common.js is running!");
// Wait for the page to be ready
$(document).ready(function () {
// Avoid adding it multiple times
if ($("#settings-menu").length) return;
// Create a minimal dropdown
var menuHtml = `
<div id="settings-menu" style="position:relative; display:inline-block; margin-left:15px;">
<button id="settings-button" style="padding:6px 12px; cursor:pointer;">
Settings ▼
</button>
<div id="settings-dropdown" style="
display:none;
position:absolute;
background:#fff;
border:1px solid #ccc;
min-width:150px;
z-index:9999;
">
<a href="/wiki/Special:Preferences" style="display:block; padding:8px;">Preferences</a>
<a href="/wiki/Special:UserLogout" style="display:block; padding:8px;">Log out</a>
</div>
</div>
`;
// Append to personal tools (usually top-right)
$("#p-personal ul").first().append(
$("<li>").append(menuHtml)
);
// Toggle dropdown visibility
$(document).on("click", "#settings-button", function () {
$("#settings-dropdown").toggle();
});
// Close dropdown when clicking elsewhere
$(document).on("click", function (e) {
if (!$(e.target).closest("#settings-menu").length) {
$("#settings-dropdown").hide();
}
});
});