|
|
| (Není zobrazeno 5 mezilehlých verzí od stejného uživatele.) |
| Řádek 61: |
Řádek 61: |
| })(); | | })(); |
|
| |
|
| //Vyhledávání | | // Vyhledávání – přejmenování popisků jmenných prostorů |
| | | if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) { |
| | | $( function () { |
| (function () {
| | var labels = { |
| 'use strict';
| | 'mw-search-ns0': 'Stránky', |
|
| | 'mw-search-ns10': 'Šablony', |
| if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
| | 'mw-search-ns3008': 'Binolupa – Přírodovědecká fakulta' |
| | | }; |
| // ══════════════════════════════════════════════════════════════
| | Object.keys( labels ).forEach( function ( id ) { |
| // KONFIGURACE
| | var l = document.querySelector( 'label[for="' + id + '"]' ); |
| // ══════════════════════════════════════════════════════════════
| | if ( l ) l.textContent = labels[ id ]; |
|
| | } ); |
| // 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);
| |
| });
| |
|
| |
|
|
| |
|
| Řádek 359: |
Řádek 94: |
| }); | | }); |
|
| |
|
| // FAQ CLICK | | //GA click download template |
| $(function () {
| | document.addEventListener('click', function (e) { |
| | | var box = e.target.closest('.dl-box__link[data-ga-event]'); |
| $('.faq-accordion').each(function () {
| | if (!box || !e.target.closest('a')) return; |
| | | var params = { |
| var $accordion = $(this);
| | file_name: box.dataset.gaName, |
| var $header = $accordion.find('.faq-accordion-header').first();
| | link_type: box.dataset.gaType, |
| | | page_path: location.pathname, |
| $header.attr({
| | transport_type: 'beacon' |
| 'role': 'button',
| | }; |
| 'tabindex': '0',
| | if (window.gtag) { |
| 'aria-expanded': $accordion.hasClass('mw-collapsed') ? 'false' : 'true'
| | gtag('event', box.dataset.gaEvent, params); |
| });
| | } else if (window.dataLayer) { |
| | | params.event = box.dataset.gaEvent; |
| function toggleFaq(event) {
| | dataLayer.push(params); |
| | | } |
| // Kliknutí na odkaz nebo původní MediaWiki toggle
| |
| // nemá spouštět druhé rozbalení/sbalení.
| |
| 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í kamkoliv na 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);
| |
| }
| |
| });
| |
| | |
| // Stav pro přístupnost
| |
| $accordion.on('afterExpand.mw-collapsible', function () {
| |
| $header.attr('aria-expanded', 'true');
| |
| });
| |
| | |
| $accordion.on('afterCollapse.mw-collapsible', function () {
| |
| $header.attr('aria-expanded', 'false');
| |
| });
| |
| | |
| });
| |
| | |
| }); | | }); |