MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 30: | Line 30: | ||
void button.offsetHeight; | void button.offsetHeight; | ||
button.style.transform = 'perspective(400px) scale(1) rotateX(0deg) rotateY(0deg)'; | button.style.transform = 'perspective(400px) scale(1) rotateX(0deg) rotateY(0deg)'; | ||
}); | |||
}); | |||
/* Open the first search suggestion on Enter press */ | |||
mw.hook('wikipage.content').add(function () { | |||
const searchInputs = document.querySelectorAll('input.cdx-text-input__input, input.searchform__input, input#searchInput'); | |||
searchInputs.forEach(function (input) { | |||
// Prevent binding duplicate event listeners | |||
if (input.dataset.quickEnterBound) return; | |||
input.dataset.quickEnterBound = 'true'; | |||
input.addEventListener('keydown', function (e) { | |||
if (e.key === 'Enter') { | |||
// Look for the first suggestion link rendered in Vector 2022 / Codex | |||
const firstResult = document.querySelector( | |||
'.cdx-menu-item--enabled a, .cdx-typeahead-search__menu a, .suggestions-results a, .oo-ui-menuOptionWidget:not(.oo-ui-widget-disabled) a' | |||
); | |||
if (firstResult && firstResult.getAttribute('href')) { | |||
e.preventDefault(); | |||
e.stopImmediatePropagation(); | |||
window.location.href = firstResult.getAttribute('href'); | |||
} | |||
} | |||
}, true); // Use capture to intercept before the default form submission fires | |||
}); | }); | ||
}); | }); | ||
Revision as of 14:15, 12 September 2026
/* Any JavaScript here will be loaded for all users on every page load. */
mw.hook('wikipage.content').add(function () {
const logo = document.querySelector('a.mw-logo');
if (logo) {
logo.setAttribute('href', 'https://fedoverse.com');
}
});
mw.hook('wikipage.content').add(function () {
const button = document.querySelector('.your-button-class');
if (!button) return;
const premiumEase = 'cubic-bezier(0.23, 1, 0.32, 1)';
button.addEventListener('mouseenter', () => {
button.style.transition = `transform 0.15s ${premiumEase}`;
});
button.addEventListener('mousemove', (e) => {
const rect = button.getBoundingClientRect();
const x = (e.clientX - rect.left - rect.width / 2) / (rect.width / 2);
const y = (e.clientY - rect.top - rect.height / 2) / (rect.height / 2);
button.style.transform = `perspective(400px) scale(1.05) rotateX(${y * -15}deg) rotateY(${x * 15}deg)`;
});
button.addEventListener('mouseleave', () => {
button.style.transition = `transform 0.65s ${premiumEase}`;
// Force the browser to commit the 0.65s transition before updating the transform
void button.offsetHeight;
button.style.transform = 'perspective(400px) scale(1) rotateX(0deg) rotateY(0deg)';
});
});
/* Open the first search suggestion on Enter press */
mw.hook('wikipage.content').add(function () {
const searchInputs = document.querySelectorAll('input.cdx-text-input__input, input.searchform__input, input#searchInput');
searchInputs.forEach(function (input) {
// Prevent binding duplicate event listeners
if (input.dataset.quickEnterBound) return;
input.dataset.quickEnterBound = 'true';
input.addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
// Look for the first suggestion link rendered in Vector 2022 / Codex
const firstResult = document.querySelector(
'.cdx-menu-item--enabled a, .cdx-typeahead-search__menu a, .suggestions-results a, .oo-ui-menuOptionWidget:not(.oo-ui-widget-disabled) a'
);
if (firstResult && firstResult.getAttribute('href')) {
e.preventDefault();
e.stopImmediatePropagation();
window.location.href = firstResult.getAttribute('href');
}
}
}, true); // Use capture to intercept before the default form submission fires
});
});