MediaWiki:Common.js: Porovnání verzí

Z Wiki JU
Ofara (diskuse | příspěvky)
Bez shrnutí editace
značka: revertováno
Ofara (diskuse | příspěvky)
Bez shrnutí editace
značka: revertováno
Řádek 63: Řádek 63:
//Vyhledávání
//Vyhledávání


/* Special:Search – profil=advanced, default zaškrtnutí + přejmenování + úprava UI */
/* Special:Search – profil=advanced, whitelist NS, default zaškrtnutí, přejmenování, úprava UI */
(function () {
(function () {
   if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
   if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;


   // 1) Profil = advanced
   // vynutit profil=advanced
   const u = new URL(location.href);
   const u = new URL(location.href);
   if (u.searchParams.get('profile') !== 'advanced') {
   if (u.searchParams.get('profile') !== 'advanced') {
Řádek 75: Řádek 75:
   }
   }


  // Pomocné – normalizace textu (OOUI občas vkládá NBSP apod.)
   const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();
   const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();
  // povolené názvy (před i po přejmenování)
  const KEEP = new Set([
    '(Hlavní)', 'Stránky',
    'Aktuality',
    'Šablona',
    'PřF', 'Binolupa – Přirodovědecká fakulta',
    'Soubor',
    'Kategorie'
  ]);


   function apply() {
   function apply() {
Řádek 82: Řádek 91:
     if (!root) return;
     if (!root) return;


     // 2) Schovat horní lištu profilů (Články / Multimédia / Všechno / Rozšířené)
     // schovat horní lištu profilů
     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';


     // 3) Projít řádky s checkboxy NS
     // projít všechny OOUI "řádky"
     root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => {
     root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => {
       const label = row.querySelector('label.oo-ui-labelElement-label');
       const label = row.querySelector('label.oo-ui-labelElement-label');
Řádek 92: Řádek 101:
       if (!label || !cb) return;
       if (!label || !cb) return;


       const text = norm(label.textContent);
      // ulož si původní popisek, ať můžeme spolehlivě matchovat i po přejmenování
      if (!row.dataset.origLabel) row.dataset.origLabel = norm(label.textContent);
      const orig = row.dataset.origLabel;
       const current = norm(label.textContent);
 
      // ponechat jen whitelisted
      const keep = KEEP.has(orig) || KEEP.has(current);
      row.style.display = keep ? '' : 'none';
 
      if (!keep) return;


       // PŘEJMENOVÁNÍ
       // přejmenování
       if (text === '(Hlavní)') label.textContent = 'Stránky';
       if (orig === '(Hlavní)') label.textContent = 'Stránky';
       if (text === 'PřF')      label.textContent = 'Binolupa – Přirodovědecká fakulta';
       if (orig === 'PřF')      label.textContent = 'Binolupa – Přirodovědecká fakulta';


       // DEFAULT ZAŠKRTNUTÍ (Hlavní + PřF)
       // default zaškrtnutí pro (Hlavní) a PřF (po přejmenování i před)
       if (text === '(Hlavní)' || text === 'PřF') {
       if (orig === '(Hlavní)' || orig === 'PřF') {
         if (!cb.checked) cb.checked = true;
         cb.checked = true;
       }
       }
     });
     });
   }
   }


   // Poprvé po načtení obsahu
   // poprvé po načtení
   mw.hook('wikipage.content').add(apply);
   mw.hook('wikipage.content').add(apply);


   // Aplikovat znovu při každém přestavění DOM (Všechno/Nic apod.)
   // re-apply při každém přestavení DOM (Všechno/Nic apod.)
   const mo = new MutationObserver(apply);
   const mo = new MutationObserver(() => apply());
   mo.observe(document.body, { childList: true, subtree: true });
   mo.observe(document.body, { childList: true, subtree: true });
})();
})();

Verze z 25. 9. 2025, 08:06

/* 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 NS, default zaškrtnutí, přejmenování, úprava UI */
(function () {
  if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;

  // vynutit profil=advanced
  const u = new URL(location.href);
  if (u.searchParams.get('profile') !== 'advanced') {
    u.searchParams.set('profile', 'advanced');
    location.replace(u.toString());
    return;
  }

  const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();

  // povolené názvy (před i po přejmenování)
  const KEEP = new Set([
    '(Hlavní)', 'Stránky',
    'Aktuality',
    'Šablona',
    'PřF', 'Binolupa – Přirodovědecká fakulta',
    'Soubor',
    'Kategorie'
  ]);

  function apply() {
    const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
    if (!root) return;

    // schovat horní lištu profilů
    const tabs = document.querySelector('.mw-search-profile-tabs');
    if (tabs) tabs.style.display = 'none';

    // projít všechny OOUI "řádky"
    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;

      // ulož si původní popisek, ať můžeme spolehlivě matchovat i po přejmenování
      if (!row.dataset.origLabel) row.dataset.origLabel = norm(label.textContent);
      const orig = row.dataset.origLabel;
      const current = norm(label.textContent);

      // ponechat jen whitelisted
      const keep = KEEP.has(orig) || KEEP.has(current);
      row.style.display = keep ? '' : 'none';

      if (!keep) return;

      // přejmenování
      if (orig === '(Hlavní)') label.textContent = 'Stránky';
      if (orig === 'PřF')      label.textContent = 'Binolupa – Přirodovědecká fakulta';

      // default zaškrtnutí pro (Hlavní) a PřF (po přejmenování i před)
      if (orig === '(Hlavní)' || orig === 'PřF') {
        cb.checked = true;
      }
    });
  }

  // poprvé po načtení
  mw.hook('wikipage.content').add(apply);

  // re-apply při každém přestavení DOM (Všechno/Nic apod.)
  const mo = new MutationObserver(() => apply());
  mo.observe(document.body, { childList: true, subtree: true });
})();