MediaWiki:Mobile.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* ========================================================================== | /* ========================================================================== | ||
STANDALONE VANI-SEARCH INPUT (DEFEATS MINERVA FOCUS-STEALING & OVERLAY) | |||
========================================================================== */ | ========================================================================== */ | ||
(function() { | (function() { | ||
// 1. | function installCleanVaniSearch() { | ||
// 1. Mobile Minerva Header: Replace Minerva's rigged input with a clean standalone input | |||
var minervaForm = document.querySelector('form.minerva-search-form'); | |||
if (minervaForm && !minervaForm.dataset.vaniCleanInstalled) { | |||
minervaForm.dataset.vaniCleanInstalled = 'true'; | |||
minervaForm.setAttribute('action', '/wiki/Special:VaniSearch'); | |||
var searchBox = minervaForm.querySelector('.search-box'); | |||
if (searchBox) { | |||
// Wipe Minerva's decoy input and left icon so Minerva JS cannot hijack focus | |||
searchBox.innerHTML = ''; | |||
var cleanInput = document.createElement('input'); | |||
cleanInput.type = 'text'; | |||
cleanInput.name = 'search'; | |||
cleanInput.className = 'vani-clean-search-input'; | |||
cleanInput.placeholder = 'Search Vanipedia'; | |||
cleanInput.autocomplete = 'off'; | |||
var goBtn = document.createElement('button'); | |||
goBtn.type = 'button'; | |||
goBtn.className = 'vani-inline-go'; | |||
goBtn.innerHTML = '🔍'; | |||
goBtn.style.cssText = 'position:absolute !important; right:8px !important; top:50% !important; transform:translateY(-50%) !important; background:none !important; border:none !important; font-size:15px !important; cursor:pointer !important; padding:0 !important; line-height:1 !important; z-index:20 !important;'; | |||
function submitMobileVaniSearch(e) { | |||
if (e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
e.stopImmediatePropagation(); | |||
} | |||
var val = cleanInput.value.trim(); | |||
if (val !== '') { | |||
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val); | |||
} | |||
} | |||
goBtn.addEventListener('click', submitMobileVaniSearch, true); | |||
cleanInput.addEventListener('keydown', function(e) { | |||
// Stop Minerva from listening to keystrokes | |||
e.stopPropagation(); | |||
if (e.key === 'Enter' || e.keyCode === 13) { | |||
submitMobileVaniSearch(e); | |||
} | |||
}, true); | |||
// Stop clicks/focus on our input from bubbling up to Minerva's overlay launcher | |||
['click', 'focus', 'focusin', 'touchstart', 'input'].forEach(function(evt) { | |||
cleanInput.addEventListener(evt, function(e) { | |||
e.stopPropagation(); | |||
}, true); | |||
}); | |||
searchBox.appendChild(cleanInput); | |||
searchBox.appendChild(goBtn); | |||
} | } | ||
} | } | ||
// 2. Desktop Vector Header: Route Enter & add single right-side 🔍 icon | |||
var desktopForm = document.querySelector('#p-search form, form#searchform'); | |||
if (desktopForm && !desktopForm.classList.contains('minerva-search-form') && !desktopForm.dataset.vaniDesktopBound) { | |||
desktopForm.dataset.vaniDesktopBound = 'true'; | |||
desktopForm.setAttribute('action', '/wiki/Special:VaniSearch'); | |||
var dInput = desktopForm.querySelector('input[type="search"], input[name="search"], #searchInput'); | |||
if (dInput) { | |||
dInput.setAttribute('autocomplete', 'off'); | |||
var wrap = dInput.parentElement; | |||
if (wrap && !wrap.querySelector('.vani-inline-go')) { | |||
wrap.style.position = 'relative'; | |||
var dBtn = document.createElement('button'); | |||
dBtn.type = 'button'; | |||
dBtn.className = 'vani-inline-go'; | |||
dBtn.innerHTML = '🔍'; | |||
dBtn.style.cssText = 'position:absolute !important; right:8px !important; top:50% !important; transform:translateY(-50%) !important; background:none !important; border:none !important; font-size:15px !important; cursor:pointer !important; padding:0 !important; line-height:1 !important; z-index:20 !important;'; | |||
dBtn.addEventListener('click', function(e) { | |||
e.preventDefault(); | |||
var val = dInput.value.trim(); | |||
if (val !== '') { | |||
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val); | |||
} | |||
}); | |||
wrap.appendChild(dBtn); | |||
} | |||
dInput.addEventListener('keydown', function(e) { | |||
if (e.key === 'Enter' || e.keyCode === 13) { | |||
e.preventDefault(); | |||
e.stopImmediatePropagation(); | |||
var val = dInput.value.trim(); | |||
if (val !== '') { | |||
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val); | |||
} | |||
} | |||
}, true); | |||
} | |||
} | } | ||
} | } | ||
}, | } | ||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', installCleanVaniSearch); | |||
} else { | |||
installCleanVaniSearch(); | |||
} | |||
setTimeout(installCleanVaniSearch, 300); | |||
setTimeout(installCleanVaniSearch, 1000); | |||
})(); | })(); | ||
Revision as of 01:58, 13 November 2026
/* ==========================================================================
STANDALONE VANI-SEARCH INPUT (DEFEATS MINERVA FOCUS-STEALING & OVERLAY)
========================================================================== */
(function() {
function installCleanVaniSearch() {
// 1. Mobile Minerva Header: Replace Minerva's rigged input with a clean standalone input
var minervaForm = document.querySelector('form.minerva-search-form');
if (minervaForm && !minervaForm.dataset.vaniCleanInstalled) {
minervaForm.dataset.vaniCleanInstalled = 'true';
minervaForm.setAttribute('action', '/wiki/Special:VaniSearch');
var searchBox = minervaForm.querySelector('.search-box');
if (searchBox) {
// Wipe Minerva's decoy input and left icon so Minerva JS cannot hijack focus
searchBox.innerHTML = '';
var cleanInput = document.createElement('input');
cleanInput.type = 'text';
cleanInput.name = 'search';
cleanInput.className = 'vani-clean-search-input';
cleanInput.placeholder = 'Search Vanipedia';
cleanInput.autocomplete = 'off';
var goBtn = document.createElement('button');
goBtn.type = 'button';
goBtn.className = 'vani-inline-go';
goBtn.innerHTML = '🔍';
goBtn.style.cssText = 'position:absolute !important; right:8px !important; top:50% !important; transform:translateY(-50%) !important; background:none !important; border:none !important; font-size:15px !important; cursor:pointer !important; padding:0 !important; line-height:1 !important; z-index:20 !important;';
function submitMobileVaniSearch(e) {
if (e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
}
var val = cleanInput.value.trim();
if (val !== '') {
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val);
}
}
goBtn.addEventListener('click', submitMobileVaniSearch, true);
cleanInput.addEventListener('keydown', function(e) {
// Stop Minerva from listening to keystrokes
e.stopPropagation();
if (e.key === 'Enter' || e.keyCode === 13) {
submitMobileVaniSearch(e);
}
}, true);
// Stop clicks/focus on our input from bubbling up to Minerva's overlay launcher
['click', 'focus', 'focusin', 'touchstart', 'input'].forEach(function(evt) {
cleanInput.addEventListener(evt, function(e) {
e.stopPropagation();
}, true);
});
searchBox.appendChild(cleanInput);
searchBox.appendChild(goBtn);
}
}
// 2. Desktop Vector Header: Route Enter & add single right-side 🔍 icon
var desktopForm = document.querySelector('#p-search form, form#searchform');
if (desktopForm && !desktopForm.classList.contains('minerva-search-form') && !desktopForm.dataset.vaniDesktopBound) {
desktopForm.dataset.vaniDesktopBound = 'true';
desktopForm.setAttribute('action', '/wiki/Special:VaniSearch');
var dInput = desktopForm.querySelector('input[type="search"], input[name="search"], #searchInput');
if (dInput) {
dInput.setAttribute('autocomplete', 'off');
var wrap = dInput.parentElement;
if (wrap && !wrap.querySelector('.vani-inline-go')) {
wrap.style.position = 'relative';
var dBtn = document.createElement('button');
dBtn.type = 'button';
dBtn.className = 'vani-inline-go';
dBtn.innerHTML = '🔍';
dBtn.style.cssText = 'position:absolute !important; right:8px !important; top:50% !important; transform:translateY(-50%) !important; background:none !important; border:none !important; font-size:15px !important; cursor:pointer !important; padding:0 !important; line-height:1 !important; z-index:20 !important;';
dBtn.addEventListener('click', function(e) {
e.preventDefault();
var val = dInput.value.trim();
if (val !== '') {
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val);
}
});
wrap.appendChild(dBtn);
}
dInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.keyCode === 13) {
e.preventDefault();
e.stopImmediatePropagation();
var val = dInput.value.trim();
if (val !== '') {
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val);
}
}
}, true);
}
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', installCleanVaniSearch);
} else {
installCleanVaniSearch();
}
setTimeout(installCleanVaniSearch, 300);
setTimeout(installCleanVaniSearch, 1000);
})();