Common.js: Porovnání verzí
Z Wiki JU
Bez shrnutí editace |
Bez shrnutí editace |
||
| (Nejsou zobrazeny 3 mezilehlé verze od stejného uživatele.) | |||
| Řádek 359: | Řádek 359: | ||
}); | }); | ||
// FAQ ACCORDION | |||
$(function () { | $(function () { | ||
/* | |||
* Kliknutí na celou hlavičku FAQ. | |||
*/ | |||
$('.faq-accordion').each(function () { | $('.faq-accordion').each(function () { | ||
| Řádek 375: | Řádek 378: | ||
function toggleFaq(event) { | function toggleFaq(event) { | ||
// Odkazy a standardní MediaWiki přepínač | |||
// si obslouží svoje kliknutí samy. | |||
if ($(event.target).closest('a, .mw-collapsible-toggle').length) { | if ($(event.target).closest('a, .mw-collapsible-toggle').length) { | ||
return; | return; | ||
| Řádek 386: | Řádek 391: | ||
} | } | ||
// Kliknutí na celou hlavičku. | |||
$header.on('click', function (event) { | $header.on('click', function (event) { | ||
toggleFaq(event); | toggleFaq(event); | ||
}); | }); | ||
// Ovládání klávesnicí. | |||
$header.on('keydown', function (event) { | $header.on('keydown', function (event) { | ||
if (event.key === 'Enter' || event.key === ' ') { | if (event.key === 'Enter' || event.key === ' ') { | ||
| Řádek 397: | Řádek 404: | ||
}); | }); | ||
// Přístupnost. | |||
$accordion.on('afterExpand.mw-collapsible', function () { | $accordion.on('afterExpand.mw-collapsible', function () { | ||
$header.attr('aria-expanded', 'true'); | $header.attr('aria-expanded', 'true'); | ||
| Řádek 404: | Řádek 412: | ||
$header.attr('aria-expanded', 'false'); | $header.attr('aria-expanded', 'false'); | ||
}); | }); | ||
}); | |||
/* | |||
* Skrytí prázdných bloků, které MediaWiki vytvoří | |||
* mezi dvěma FAQ. | |||
* | |||
* Prvky se NEMAŽOU, pouze se skryjí. | |||
* Tím se nerozbije mw-collapsible. | |||
*/ | |||
$('table.faq-accordion').each(function () { | |||
var faq = this; | |||
var node = faq.nextSibling; | |||
var spacers = []; | |||
var nextFaqFound = false; | |||
while (node) { | |||
// Další FAQ = mezera mezi FAQ byla nalezena. | |||
if ( | |||
node.nodeType === 1 && | |||
node.matches && | |||
node.matches('table.faq-accordion') | |||
) { | |||
nextFaqFound = true; | |||
break; | |||
} | |||
// Prázdný textový uzel ignorujeme. | |||
if ( | |||
node.nodeType === 3 && | |||
node.textContent.trim() === '' | |||
) { | |||
node = node.nextSibling; | |||
continue; | |||
} | |||
// Skrytý technický nadpis pro obsah ignorujeme. | |||
if ( | |||
node.nodeType === 1 && | |||
node.matches && | |||
node.matches('h3, h4, h5, h6') && | |||
node.querySelector('.faq-toc-marker') | |||
) { | |||
node = node.nextSibling; | |||
continue; | |||
} | |||
/* | |||
* Některé novější verze MediaWiki obalují | |||
* nadpis do .mw-heading. | |||
*/ | |||
if ( | |||
node.nodeType === 1 && | |||
node.classList && | |||
node.classList.contains('mw-heading') && | |||
node.querySelector('.faq-toc-marker') | |||
) { | |||
node = node.nextSibling; | |||
continue; | |||
} | |||
// Prázdný odstavec nebo <br>. | |||
if ( | |||
node.nodeType === 1 && | |||
( | |||
node.tagName === 'P' || | |||
node.tagName === 'BR' | |||
) && | |||
node.textContent.trim() === '' | |||
) { | |||
spacers.push(node); | |||
node = node.nextSibling; | |||
continue; | |||
} | |||
// Narazili jsme na skutečný obsah. | |||
break; | |||
} | |||
/* | |||
* Skryjeme je pouze tehdy, pokud za nimi | |||
* skutečně následuje další FAQ. | |||
*/ | |||
if (nextFaqFound) { | |||
spacers.forEach(function (spacer) { | |||
spacer.classList.add('faq-empty-spacer'); | |||
}); | |||
} | |||
}); | }); | ||
}); | }); | ||
Aktuální verze z 6. 10. 2026, 11:33
/* 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, 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 – i pro přihlášené
mw.loader.using(['mediawiki.util', 'mediawiki.storage']).then(function () {
var SEL_TOGGLER = '.mw-editfooter-toggler';
function expandAll($root) {
var $scope = $root || $(document);
$scope.find(SEL_TOGGLER).each(function () {
var $btn = $(this);
var targetId = $btn.attr('aria-controls');
var $panel = targetId ? $('#' + CSS.escape(targetId)) : $btn.next();
// přepni do expanded
$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) Zruš „zapamatovaný“ stav (lokální i MW storage – někteří skini/gadgety to ukládají)
try {
[localStorage, sessionStorage].forEach(function (store) {
Object.keys(store).forEach(function (k) {
if (/(editfooter|mw\-editfooter|mw\-collapsible)/i.test(k)) {
store.removeItem(k);
}
});
});
if (mw.storage && mw.storage.remove) {
// nejlepší snaha – kdyby to někdo ukládal přes mw.storage
['editfooter', 'mw-editfooter', 'mw-collapsible'].forEach(function (k) {
try { mw.storage.remove(k); } catch (e) {}
});
}
} catch (e) {}
// 2) Vynucení po různých fázích načtení (přebije později běžící skripta)
mw.hook('wikipage.content').add(function ($content) { expandAll($content); });
$(function () { expandAll(); }); // DOM ready
$(window).on('load', function () { expandAll(); }); // po všem
// 3) „Hlídač“ – pokud něco zase přepne do collapsed, rovnou to vrátíme
var obs = new MutationObserver(function (mutations) {
mutations.forEach(function (m) {
if (
m.type === 'attributes' &&
m.target.matches &&
m.target.matches(SEL_TOGGLER) &&
m.target.getAttribute('aria-expanded') !== 'true'
) {
expandAll($(m.target).closest('body'));
}
});
});
// začneme sledovat všechny togglery (i když přibudou později)
function observeNow() {
document.querySelectorAll(SEL_TOGGLER).forEach(function (el) {
obs.observe(el, { attributes: true, attributeFilter: ['class', 'aria-expanded'] });
});
}
observeNow();
setTimeout(observeNow, 0);
setTimeout(observeNow, 300);
});
//DPL PREFIX
$(function () {
$('.dpl-short-title').each(function () {
var container = $(this);
var prefix = container.data('prefix');
container.find('a').each(function () {
var link = $(this);
var text = link.text();
if (prefix && text.startsWith(prefix)) {
link.text(text.substring(prefix.length));
}
});
});
});
// FAQ ACCORDION
$(function () {
/*
* Kliknutí na celou hlavičku FAQ.
*/
$('.faq-accordion').each(function () {
var $accordion = $(this);
var $header = $accordion.find('.faq-accordion-header').first();
$header.attr({
'role': 'button',
'tabindex': '0',
'aria-expanded': $accordion.hasClass('mw-collapsed') ? 'false' : 'true'
});
function toggleFaq(event) {
// Odkazy a standardní MediaWiki přepínač
// si obslouží svoje kliknutí samy.
if ($(event.target).closest('a, .mw-collapsible-toggle').length) {
return;
}
var $toggle = $accordion.find('.mw-collapsible-toggle').first();
if ($toggle.length) {
$toggle.trigger('click');
}
}
// Kliknutí na celou hlavičku.
$header.on('click', function (event) {
toggleFaq(event);
});
// Ovládání klávesnicí.
$header.on('keydown', function (event) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
toggleFaq(event);
}
});
// Přístupnost.
$accordion.on('afterExpand.mw-collapsible', function () {
$header.attr('aria-expanded', 'true');
});
$accordion.on('afterCollapse.mw-collapsible', function () {
$header.attr('aria-expanded', 'false');
});
});
/*
* Skrytí prázdných bloků, které MediaWiki vytvoří
* mezi dvěma FAQ.
*
* Prvky se NEMAŽOU, pouze se skryjí.
* Tím se nerozbije mw-collapsible.
*/
$('table.faq-accordion').each(function () {
var faq = this;
var node = faq.nextSibling;
var spacers = [];
var nextFaqFound = false;
while (node) {
// Další FAQ = mezera mezi FAQ byla nalezena.
if (
node.nodeType === 1 &&
node.matches &&
node.matches('table.faq-accordion')
) {
nextFaqFound = true;
break;
}
// Prázdný textový uzel ignorujeme.
if (
node.nodeType === 3 &&
node.textContent.trim() === ''
) {
node = node.nextSibling;
continue;
}
// Skrytý technický nadpis pro obsah ignorujeme.
if (
node.nodeType === 1 &&
node.matches &&
node.matches('h3, h4, h5, h6') &&
node.querySelector('.faq-toc-marker')
) {
node = node.nextSibling;
continue;
}
/*
* Některé novější verze MediaWiki obalují
* nadpis do .mw-heading.
*/
if (
node.nodeType === 1 &&
node.classList &&
node.classList.contains('mw-heading') &&
node.querySelector('.faq-toc-marker')
) {
node = node.nextSibling;
continue;
}
// Prázdný odstavec nebo <br>.
if (
node.nodeType === 1 &&
(
node.tagName === 'P' ||
node.tagName === 'BR'
) &&
node.textContent.trim() === ''
) {
spacers.push(node);
node = node.nextSibling;
continue;
}
// Narazili jsme na skutečný obsah.
break;
}
/*
* Skryjeme je pouze tehdy, pokud za nimi
* skutečně následuje další FAQ.
*/
if (nextFaqFound) {
spacers.forEach(function (spacer) {
spacer.classList.add('faq-empty-spacer');
});
}
});
});