MediaWiki:Common.js: Porovnání verzí
Z Wiki JU
Bez shrnutí editace |
Bez shrnutí editace |
||
| Řádek 303: | Řádek 303: | ||
setTimeout(expandOnce, 0); | setTimeout(expandOnce, 0); | ||
setTimeout(expandOnce, 300); | setTimeout(expandOnce, 300); | ||
}); | |||
$(document).on('click', '.mw-editfooter-toggler', function () { | |||
// po kliknutí smaž případné uložení stavu, ať se nepřenáší dál | |||
try { | |||
Object.keys(localStorage).forEach(function (k) { | |||
if (/editfooter|mw-editfooter|collaps/i.test(k)) { | |||
localStorage.removeItem(k); | |||
} | |||
}); | |||
} catch (e) { /* nic */ } | |||
}); | }); | ||
Verze z 30. 10. 2025, 09:15
/* 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í
(function () {
'use strict';
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
// ══════════════════════════════════════════════════════════════
// KONFIGURACE
// ══════════════════════════════════════════════════════════════
// Povolené namespace (ID)
const ALLOWED_NS = new Set([0, 6, 10, 14, 3004, 3008]);
// Přejmenování labelů
const RENAME_MAP = new Map([
['(Hlavní)', 'Stránky'],
['PřF', 'Binolupa – Přírodovědecká fakulta'],
['Soubor', 'Soubory'],
['Šablona', 'Šablony']
]);
// ══════════════════════════════════════════════════════════════
// 1) UPRAVENÍ URL PŘI PRVNÍM NAČTENÍ
// ══════════════════════════════════════════════════════════════
function ensureUrlParams() {
const url = new URL(location.href);
let changed = false;
// Zajisti profile=advanced
if (url.searchParams.get('profile') !== 'advanced') {
url.searchParams.set('profile', 'advanced');
changed = true;
}
// Pokud není žádný ns parametr, nastav ns0=1
const hasNsParams = Array.from(url.searchParams.keys()).some(k => /^ns\d+$/.test(k));
if (!hasNsParams) {
url.searchParams.set('ns0', '1');
changed = true;
}
if (changed) {
location.replace(url.toString());
}
}
ensureUrlParams();
// ══════════════════════════════════════════════════════════════
// 2) ÚPRAVA NAMESPACE CHECKBOXŮ
// ══════════════════════════════════════════════════════════════
function processNamespaces() {
const container = document.querySelector('#mw-searchoptions');
if (!container || container.dataset.processed) return;
container.dataset.processed = '1';
// Skrýt profil tabs
const tabs = document.querySelector('.mw-search-profile-tabs');
if (tabs) tabs.style.display = 'none';
// Změnit nadpis
const heading = container.querySelector('legend');
if (heading) heading.textContent = 'Co chcete vyhledávat?';
// Načíst ns parametry z URL
const urlParams = new URLSearchParams(location.search);
const selectedNs = new Set();
for (const [key, val] of urlParams) {
const match = /^ns(\d+)$/.exec(key);
if (match && val === '1') {
selectedNs.add(parseInt(match[1], 10));
}
}
// Zpracovat checkboxy
container.querySelectorAll('input[type="checkbox"][id^="mw-search-ns"]').forEach(cb => {
const row = cb.closest('.oo-ui-fieldLayout');
if (!row) return;
// Získat NS ID z checkbox ID
const match = cb.id.match(/mw-search-ns(\d+)/);
if (!match) { row.remove(); return; }
const nsId = parseInt(match[1], 10);
// Filtrovat podle whitelistu
if (!ALLOWED_NS.has(nsId)) {
row.remove();
return;
}
// Přejmenovat label
const label = row.querySelector(`label[for="${cb.id}"]`);
if (label) {
const origText = label.textContent.trim();
if (RENAME_MAP.has(origText)) {
label.textContent = RENAME_MAP.get(origText);
}
}
// Nastavit checked stav podle URL
cb.checked = selectedNs.has(nsId);
});
// Skrýt "Zapamatovat si výběr" (pokud existuje)
const rememberCheckbox = container.querySelector('#mw-search-powersearch-remember');
if (rememberCheckbox) {
const rememberRow = rememberCheckbox.closest('.oo-ui-fieldLayout');
if (rememberRow) rememberRow.remove();
}
// Skrýt toggle buttony (Všechno/Nic)
const toggleBox = container.querySelector('#mw-search-togglebox');
if (toggleBox) toggleBox.style.display = 'none';
}
// ══════════════════════════════════════════════════════════════
// 3) SUBMIT HANDLER PRO OBA FORMULÁŘE
// ══════════════════════════════════════════════════════════════
function bindSearchSubmit() {
// Horní vyhledávací formulář
const topForm = document.querySelector('#searchform');
if (topForm && !topForm.dataset.bound) {
topForm.dataset.bound = '1';
topForm.addEventListener('submit', handleSubmit);
}
// Hlavní formulář s checkboxy
const mainForm = document.querySelector('#powersearch');
if (mainForm && !mainForm.dataset.bound) {
mainForm.dataset.bound = '1';
mainForm.addEventListener('submit', handleSubmit);
}
}
function handleSubmit(ev) {
ev.preventDefault();
// Najít vyhledávací input (může být v různých formulářích)
const searchInput = ev.target.querySelector('input[name="search"], input[name="searchtext"], input[type="search"]');
const query = searchInput ? searchInput.value.trim() : '';
// Sestavit URL
const targetUrl = new URL(mw.util.getUrl('Special:Search'), location.origin);
if (query) targetUrl.searchParams.set('search', query);
targetUrl.searchParams.set('profile', 'advanced');
targetUrl.searchParams.set('fulltext', '1');
// Přidat vybrané namespace z checkboxů
const container = document.querySelector('#mw-searchoptions');
if (container) {
container.querySelectorAll('input[type="checkbox"][id^="mw-search-ns"]:checked').forEach(cb => {
const match = cb.id.match(/mw-search-ns(\d+)/);
if (match) {
targetUrl.searchParams.set('ns' + match[1], '1');
}
});
}
// Přesměrovat
location.href = targetUrl.toString();
}
// ══════════════════════════════════════════════════════════════
// 4) SPUŠTĚNÍ
// ══════════════════════════════════════════════════════════════
function init() {
const container = document.querySelector('#mw-searchoptions');
const hasCheckboxes = container && container.querySelector('input[type="checkbox"][id^="mw-search-ns"]');
if (hasCheckboxes) {
processNamespaces();
bindSearchSubmit();
} else {
// Počkat na DOM (max 5 sekund)
const attempts = 50;
let count = 0;
const interval = setInterval(() => {
const c = document.querySelector('#mw-searchoptions');
const ready = c && c.querySelector('input[type="checkbox"][id^="mw-search-ns"]');
if (ready) {
clearInterval(interval);
processNamespaces();
bindSearchSubmit();
} else if (++count >= attempts) {
clearInterval(interval);
}
}, 100);
}
}
// Spustit po DOMContentLoaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
// Hook pro MediaWiki live preview
mw.hook('wikipage.content').add(init);
})();
//expanded podstránky automaticky
// Vždy vynutit expanded stav edit footeru (a zrušit jeho "zapamatování")
mw.hook('wikipage.content').add(function ($content) {
function expandOnce() {
$content.find('.mw-editfooter-toggler').each(function () {
var $btn = $(this);
var targetId = $btn.attr('aria-controls');
var $panel = targetId ? $('#' + CSS.escape(targetId)) : $btn.next();
// přepni do expanded bez spoléhání na "klik"
$btn.removeClass('mw-icon-arrow-collapsed')
.addClass('mw-icon-arrow-expanded')
.attr('aria-expanded', 'true');
if ($panel.length) {
$panel.show().attr('aria-hidden', 'false');
}
});
}
// 1) zkus smazat případnou uloženou preferenci (konzervativně podle názvu)
try {
Object.keys(localStorage).forEach(function (k) {
if (/editfooter|mw-editfooter|collaps/i.test(k)) {
localStorage.removeItem(k);
}
});
} catch (e) { /* nic */ }
// 2) vynutit expanded (okamžitě i po pozdním doskriptování)
expandOnce();
setTimeout(expandOnce, 0);
setTimeout(expandOnce, 300);
});
$(document).on('click', '.mw-editfooter-toggler', function () {
// po kliknutí smaž případné uložení stavu, ať se nepřenáší dál
try {
Object.keys(localStorage).forEach(function (k) {
if (/editfooter|mw-editfooter|collaps/i.test(k)) {
localStorage.removeItem(k);
}
});
} catch (e) { /* nic */ }
});