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
 
(Není zobrazeno 32 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 () {
        var labels = {
            'mw-search-ns0':    'Stránky',
            'mw-search-ns10':  'Šablony',
            'mw-search-ns3008': 'Binolupa – Přírodovědecká fakulta'
        };
        Object.keys( labels ).forEach( function ( id ) {
            var l = document.querySelector( 'label[for="' + id + '"]' );
            if ( l ) l.textContent = labels[ id ];
        } );
    } );
}


/* Special:Search – profil=advanced, whitelist, přejmenování, default check (bez zacyklení) */
(function () {
  if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;


  // vynutit profil=advanced
//DPL PREFIX
  const url = new URL(location.href);
$(function () {
  if (url.searchParams.get('profile') !== 'advanced') {
    $('.dpl-short-title').each(function () {
    url.searchParams.set('profile', 'advanced');
        var container = $(this);
    location.replace(url.toString());
        var prefix = container.data('prefix');
    return;
  }


  const KEEP = new Set([
        container.find('a').each(function () {
    '(Hlavní)', 'Stránky',
            var link = $(this);
    'Aktuality',
            var text = link.text();
    'Š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() {
            if (prefix && text.startsWith(prefix)) {
    const tabs = document.querySelector('.mw-search-profile-tabs');
                link.text(text.substring(prefix.length));
    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);
//GA click download template
      row.classList.toggle('ns-hide', !keep);  // <<< skrýváme přes třídu
document.addEventListener('click', function (e) {
      if (!keep) { cb.checked = false; return; }
  var box = e.target.closest('.dl-box__link[data-ga-event]');
 
  if (!box || !e.target.closest('a')) return;
      if (DEFAULT_CHECK.has(orig)) cb.checked = true;
  var params = {
     });
    file_name: box.dataset.gaName,
    link_type: box.dataset.gaType,
    page_path: location.pathname,
    transport_type: 'beacon'
  };
   if (window.gtag) {
    gtag('event', box.dataset.gaEvent, params);
  } else if (window.dataLayer) {
    params.event = box.dataset.gaEvent;
     dataLayer.push(params);
   }
   }
 
});
  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 });
  })();
})();

Aktuální verze z 18. 11. 2026, 10:37

/* 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í – přejmenování popisků jmenných prostorů
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) {
    $( function () {
        var labels = {
            'mw-search-ns0':    'Stránky',
            'mw-search-ns10':   'Šablony',
            'mw-search-ns3008': 'Binolupa – Přírodovědecká fakulta'
        };
        Object.keys( labels ).forEach( function ( id ) {
            var l = document.querySelector( 'label[for="' + id + '"]' );
            if ( l ) l.textContent = labels[ id ];
        } );
    } );
}


//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));
            }
        });
    });
});

//GA click download template
document.addEventListener('click', function (e) {
  var box = e.target.closest('.dl-box__link[data-ga-event]');
  if (!box || !e.target.closest('a')) return;
  var params = {
    file_name: box.dataset.gaName,
    link_type: box.dataset.gaType,
    page_path: location.pathname,
    transport_type: 'beacon'
  };
  if (window.gtag) {
    gtag('event', box.dataset.gaEvent, params);
  } else if (window.dataLayer) {
    params.event = box.dataset.gaEvent;
    dataLayer.push(params);
  }
});