MediaWiki:Common.js: Porovnání verzí
Z Wiki JU
Bez shrnutí editace značka: revertováno |
Bez shrnutí editace značka: revertováno |
||
| Řádek 63: | Řádek 63: | ||
//Vyhledávání | //Vyhledávání | ||
/* Special:Search – profil=advanced, whitelist | /* Special:Search – profil=advanced, whitelist, přejmenování, default check (bez zacyklení) */ | ||
(function () { | (function () { | ||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return; | if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return; | ||
// | // vynutit profil=advanced | ||
const url = new URL(location.href); | const url = new URL(location.href); | ||
if (url.searchParams.get('profile') !== 'advanced') { | if (url.searchParams.get('profile') !== 'advanced') { | ||
| Řádek 75: | Řádek 75: | ||
} | } | ||
const KEEP = new Set([ | const KEEP = new Set([ | ||
'(Hlavní)', 'Stránky', | '(Hlavní)', 'Stránky', | ||
| Řádek 85: | Řádek 83: | ||
'Kategorie' | 'Kategorie' | ||
]); | ]); | ||
const DEFAULT_CHECK = new Set(['(Hlavní)', 'PřF']); | const DEFAULT_CHECK = new Set(['(Hlavní)', 'PřF']); | ||
const RENAME = new Map([ | const RENAME = new Map([ | ||
['(Hlavní)', 'Stránky'], | ['(Hlavní)', 'Stránky'], | ||
['PřF', 'Binolupa – Přirodovědecká fakulta'] | ['PřF', 'Binolupa – Přirodovědecká fakulta'] | ||
]); | ]); | ||
const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim(); | const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim(); | ||
function apply() { | |||
function | |||
const tabs = document.querySelector('.mw-search-profile-tabs'); | const tabs = document.querySelector('.mw-search-profile-tabs'); | ||
if (tabs) tabs.style.display = 'none'; | if (tabs) tabs.style.display = 'none'; | ||
const root = | const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions'); | ||
if (!root) return; | |||
if (!root) | |||
root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => { | root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => { | ||
const | const label = row.querySelector('label.oo-ui-labelElement-label'); | ||
const cb = row.querySelector('input[type="checkbox"]'); | const cb = row.querySelector('input[type="checkbox"]'); | ||
if (! | if (!label || !cb) return; | ||
if (!row.dataset.origLabel) row.dataset.origLabel = norm(label.textContent); | |||
if (!row.dataset.origLabel) row.dataset.origLabel = norm( | |||
const orig = row.dataset.origLabel; | const orig = row.dataset.origLabel; | ||
if (RENAME.has(orig)) label.textContent = RENAME.get(orig); | |||
if (RENAME.has(orig)) | const current = norm(label.textContent); | ||
const current = norm( | |||
const keep = KEEP.has(orig) || KEEP.has(current); | const keep = KEEP.has(orig) || KEEP.has(current); | ||
row.classList.toggle('ns-hide', !keep); // <<< skrýváme přes třídu | |||
if (!keep) { cb.checked = false; return; } | |||
if (DEFAULT_CHECK.has(orig)) cb.checked = true; | if (DEFAULT_CHECK.has(orig)) cb.checked = true; | ||
}); | }); | ||
} | } | ||
mw.hook('wikipage.content').add(apply); | |||
// | // pozoruj jen kontejner vyhledávacích voleb | ||
(function observeContainer () { | |||
const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions'); | |||
if (!root) { setTimeout(observeContainer, 100); return; } | |||
(function observeContainer() { | new MutationObserver(apply).observe(root, { childList: true, subtree: true }); | ||
const root = | |||
if (!root) { | |||
})(); | })(); | ||
})(); | })(); | ||
Verze z 25. 9. 2025, 08:19
/* Zde uvedený JavaScript bude použit pro všechny uživatele při načtení každé stránky */
//Zpětná vazba
$(function () {
// Zruš jQuery UI vzhled tlačítka
$('.articleFeedbackv5-submit').button('destroy');
});
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('.extern-download').forEach(el => {
el.style.cursor = 'pointer';
el.style.color = '#0645AD';
el.style.textDecoration = 'underline';
el.addEventListener('click', () => {
const a = document.createElement('a');
a.href = el.getAttribute('data-url');
a.setAttribute('download', '');
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
});
});
(function () {
var NOTE_ID = 'af5-note';
var NOTE_HTML =
'<div id="' + NOTE_ID + '" class="articleFeedbackv5-note">' +
'<b>Tento formulář slouží pouze jako zpětná vazba pro tuto stránku.</b> ' +
'Řešíte-li nějaký problém, napište e-mail na ' +
'<a href="/Servicedesk/Seznam_e-mailových_adres_pro_zadávání_požadavků">službu,</a> které se Váš problém týká.' +
'</div>';
function injectNote(root) {
var $title = (root ? $(root) : $(document))
.find('.articleFeedbackv5-title-wrap')
.first();
if (!$title.length) return false; // nadpis není
if (document.getElementById(NOTE_ID)) return true; // už vloženo
$title.after(NOTE_HTML); // vložit pod nadpis
return true;
}
if (injectNote()) return;
var obs = new MutationObserver(function (mutations) {
for (var m of mutations) {
if (injectNote(m.target)) {
obs.disconnect();
break;
}
}
});
obs.observe(document.body, { childList: true, subtree: true });
setTimeout(function () { injectNote(); obs.disconnect(); }, 5000);
})();
//Vyhledávání
/* Special:Search – profil=advanced, whitelist, přejmenování, default check (bez zacyklení) */
(function () {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
// vynutit profil=advanced
const url = new URL(location.href);
if (url.searchParams.get('profile') !== 'advanced') {
url.searchParams.set('profile', 'advanced');
location.replace(url.toString());
return;
}
const KEEP = new Set([
'(Hlavní)', 'Stránky',
'Aktuality',
'Šablona',
'PřF', 'Binolupa – Přirodovědecká fakulta',
'Soubor',
'Kategorie'
]);
const DEFAULT_CHECK = new Set(['(Hlavní)', 'PřF']);
const RENAME = new Map([
['(Hlavní)', 'Stránky'],
['PřF', 'Binolupa – Přirodovědecká fakulta']
]);
const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();
function apply() {
const tabs = document.querySelector('.mw-search-profile-tabs');
if (tabs) tabs.style.display = 'none';
const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
if (!root) return;
root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => {
const label = row.querySelector('label.oo-ui-labelElement-label');
const cb = row.querySelector('input[type="checkbox"]');
if (!label || !cb) return;
if (!row.dataset.origLabel) row.dataset.origLabel = norm(label.textContent);
const orig = row.dataset.origLabel;
if (RENAME.has(orig)) label.textContent = RENAME.get(orig);
const current = norm(label.textContent);
const keep = KEEP.has(orig) || KEEP.has(current);
row.classList.toggle('ns-hide', !keep); // <<< skrýváme přes třídu
if (!keep) { cb.checked = false; return; }
if (DEFAULT_CHECK.has(orig)) cb.checked = true;
});
}
mw.hook('wikipage.content').add(apply);
// pozoruj jen kontejner vyhledávacích voleb
(function observeContainer () {
const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
if (!root) { setTimeout(observeContainer, 100); return; }
new MutationObserver(apply).observe(root, { childList: true, subtree: true });
})();
})();