MediaWiki:Mobile.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* | /* Minerva Mobile & Desktop VaniSearch Replacement */ | ||
(function() { | (function() { | ||
function | function installVaniSearch() { | ||
var | // 1. Mobile (Minerva header) | ||
if ( | var minervaHeader = document.querySelector('.minerva-header'); | ||
if (minervaHeader) { | |||
// Remove any invisible Minerva overlay states that block clicking/typing | |||
document.documentElement.classList.remove('overlay-enabled'); | |||
document.body.classList.remove('search-enabled', 'overlay-enabled'); | |||
var b = minervaHeader.querySelector('.branding-box'); | |||
if (b) b.style.setProperty('display', 'none', 'important'); | |||
var f = minervaHeader.querySelector('.minerva-search-form'); | |||
if (f && !document.getElementById('vani-mobile-search-input')) { | |||
var d = document.createElement('div'); | |||
d.className = 'vani-mobile-search-wrap'; | |||
d.style.cssText = 'flex:1 1 auto !important; display:flex !important; align-items:center !important; position:relative !important; margin:0 10px !important; z-index:999999 !important; pointer-events:auto !important;'; | |||
var inp = document.createElement('input'); | |||
inp.type = 'text'; | |||
inp.id = 'vani-mobile-search-input'; | |||
inp.name = 'search'; | |||
inp.placeholder = 'Search Vanipedia'; | |||
inp.autocomplete = 'off'; | |||
inp.style.cssText = 'width:100% !important; height:32px !important; background:#1f3e45 !important; color:#ffffff !important; -webkit-text-fill-color:#ffffff !important; border:1.5px solid #f5d77f !important; border-radius:16px !important; padding:2px 32px 2px 12px !important; font-size:15px !important; outline:none !important; box-sizing:border-box !important; pointer-events:auto !important; user-select:text !important; -webkit-user-select:text !important;'; | |||
var btn = document.createElement('button'); | |||
btn.type = 'button'; | |||
btn.innerHTML = '🔍'; | |||
btn.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:10 !important; pointer-events:auto !important;'; | |||
var go = function(e) { | |||
if (e) { e.preventDefault(); e.stopPropagation(); } | |||
var val = inp.value.trim(); | |||
if (val !== '') { | |||
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val); | |||
} | |||
}; | |||
btn.addEventListener('click', go, true); | |||
inp.addEventListener('keydown', function(e) { | |||
e.stopPropagation(); | |||
if (e.key === 'Enter' || e.keyCode === 13) go(e); | |||
}, true); | |||
d.appendChild(inp); | |||
d.appendChild(btn); | |||
f.replaceWith(d); | |||
} | } | ||
} | } | ||
// 2. Desktop (Vector header) | |||
var desktopForm = document.querySelector('#p-search form, form#searchform'); | |||
if (desktopForm && !desktopForm.classList.contains('minerva-search-form') && !desktopForm.dataset.vaniBound) { | |||
desktopForm.dataset.vaniBound = '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') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', | document.addEventListener('DOMContentLoaded', installVaniSearch); | ||
} else { | } else { | ||
installVaniSearch(); | |||
} | } | ||
setTimeout( | setTimeout(installVaniSearch, 250); | ||
setTimeout( | setTimeout(installVaniSearch, 800); | ||
})(); | })(); | ||
Revision as of 02:21, 13 November 2026
/* Minerva Mobile & Desktop VaniSearch Replacement */
(function() {
function installVaniSearch() {
// 1. Mobile (Minerva header)
var minervaHeader = document.querySelector('.minerva-header');
if (minervaHeader) {
// Remove any invisible Minerva overlay states that block clicking/typing
document.documentElement.classList.remove('overlay-enabled');
document.body.classList.remove('search-enabled', 'overlay-enabled');
var b = minervaHeader.querySelector('.branding-box');
if (b) b.style.setProperty('display', 'none', 'important');
var f = minervaHeader.querySelector('.minerva-search-form');
if (f && !document.getElementById('vani-mobile-search-input')) {
var d = document.createElement('div');
d.className = 'vani-mobile-search-wrap';
d.style.cssText = 'flex:1 1 auto !important; display:flex !important; align-items:center !important; position:relative !important; margin:0 10px !important; z-index:999999 !important; pointer-events:auto !important;';
var inp = document.createElement('input');
inp.type = 'text';
inp.id = 'vani-mobile-search-input';
inp.name = 'search';
inp.placeholder = 'Search Vanipedia';
inp.autocomplete = 'off';
inp.style.cssText = 'width:100% !important; height:32px !important; background:#1f3e45 !important; color:#ffffff !important; -webkit-text-fill-color:#ffffff !important; border:1.5px solid #f5d77f !important; border-radius:16px !important; padding:2px 32px 2px 12px !important; font-size:15px !important; outline:none !important; box-sizing:border-box !important; pointer-events:auto !important; user-select:text !important; -webkit-user-select:text !important;';
var btn = document.createElement('button');
btn.type = 'button';
btn.innerHTML = '🔍';
btn.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:10 !important; pointer-events:auto !important;';
var go = function(e) {
if (e) { e.preventDefault(); e.stopPropagation(); }
var val = inp.value.trim();
if (val !== '') {
window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val);
}
};
btn.addEventListener('click', go, true);
inp.addEventListener('keydown', function(e) {
e.stopPropagation();
if (e.key === 'Enter' || e.keyCode === 13) go(e);
}, true);
d.appendChild(inp);
d.appendChild(btn);
f.replaceWith(d);
}
}
// 2. Desktop (Vector header)
var desktopForm = document.querySelector('#p-search form, form#searchform');
if (desktopForm && !desktopForm.classList.contains('minerva-search-form') && !desktopForm.dataset.vaniBound) {
desktopForm.dataset.vaniBound = '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', installVaniSearch);
} else {
installVaniSearch();
}
setTimeout(installVaniSearch, 250);
setTimeout(installVaniSearch, 800);
})();