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 51 mezilehlých verzí od stejného uživatele.)
Řádek 1: Řádek 1:
/* Zde uvedený JavaScript bude použit pro všechny uživatele při načtení každé stránky */
/* Zde uvedený JavaScript bude použit pro všechny uživatele při načtení každé stránky */
//Zpětná vazba


$(function () {
$(function () {
Řádek 22: Řádek 24:
   });
   });
});
});
// --- Fix externích odkazů při zobrazení přes Google Translate proxy ---
// Doména vaší wiki:
var WIKI_HOST = 'wiki.jcu.cz';


(function () {
(function () {
   function isTranslateHost(host) {
   var NOTE_ID = 'af5-note';
     return host.endsWith('.translate.goog') ||
  var NOTE_HTML =
          /(^|\.)translate\.googleusercontent\.com$/.test(host);
     '<div id="' + NOTE_ID + '" class="articleFeedbackv5-note">' +
  }
      '<b>Tento formulář slouží pouze jako zpětná vazba pro tuto stránku.</b> ' +
  function inTranslateView() {
      'Řešíte-li nějaký problém, napište e-mail na ' +
    return isTranslateHost(location.hostname) || /[?&]_x_tr_/.test(location.search);
      '<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>';
  if (!inTranslateView()) return;


  // Rozbalí URL z Google Translate (*.translate.goog → původní host, zahodí _x_tr_*)
  function injectNote(root) {
  function unwrapUrl(href) {
     var $title = (root ? $(root) : $(document))
     try {
       .find('.articleFeedbackv5-title-wrap')
       var url = new URL(href, location.href);
      .first();


      // translate.googleusercontent.com/translate_c?u=<ORIGINAL>
    if (!$title.length) return false;                 // nadpis není
      if (isTranslateHost(url.hostname) && url.pathname.indexOf('/translate_c') !== -1) {
    if (document.getElementById(NOTE_ID)) return true; // už vloženo
        var u = url.searchParams.get('u');
        if (u) return new URL(u).href;
      }
 
      // *.translate.goog → host s pomlčkami zpět na tečky
      if (url.hostname.endsWith('.translate.goog')) {
        var hostPart = url.hostname.slice(0, -'.translate.goog'.length).replace(/-/g, '.');
        var scheme = url.searchParams.get('_x_tr_sch') || 'https';
        var kept = [];
        url.searchParams.forEach(function (v, k) {
          if (!/^_x_tr_/.test(k)) kept.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
        });
        var query = kept.length ? '?' + kept.join('&') : '';
        return scheme + '://' + hostPart + url.pathname + query + url.hash;
      }


      return url.href;
    $title.after(NOTE_HTML);                         // vložit pod nadpis
     } catch (e) {
     return true;
      return href;
    }
   }
   }


   function isExternal(href) {
   if (injectNote()) return;
    try { return new URL(href).host !== WIKI_HOST; } catch { return false; }
  }


   // 1) Hromadně upravíme existující <a> a <form>
   var obs = new MutationObserver(function (mutations) {
  function patchLinksAndForms(root) {
     for (var m of mutations) {
     root.querySelectorAll('a[href]').forEach(function (a) {
       if (injectNote(m.target)) {
      var clean = unwrapUrl(a.href);
         obs.disconnect();
       if (isExternal(clean)) {
         break;
         a.href = clean;
        a.target = '_blank';
         a.rel = (a.rel ? a.rel + ' ' : '') + 'noopener noreferrer';
       }
       }
     });
     }
  });


    root.querySelectorAll('form[action]').forEach(function (f) {
  obs.observe(document.body, { childList: true, subtree: true });
      try {
  setTimeout(function () { injectNote(); obs.disconnect(); }, 5000);
        var clean = unwrapUrl(f.action);
})();
        if (isExternal(clean)) {
          f.action = clean;
          // u SSO je lepší nové okno, ať to Google neobalí
          f.target = '_blank';
          // případně: f.rel = 'noopener'; (ne každý prohlížeč to na <form> uplatní)
        }
      } catch (e) {}
    });
  }


  // 2) Zachytíme kliky dřív než Google – a otevřeme čistou URL sami
// Vyhledávání – přejmenování popisků jmenných prostorů
  document.addEventListener('click', function (e) {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) {
    // pouze levé tlačítko bez modifikátorů
    $( function () {
    if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
        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 ];
        } );
    } );
}


    var a = e.target;
    while (a && a.tagName !== 'A') a = a.parentElement;
    if (!a) return;
    var href = a.getAttribute('href');
    if (!href || href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:')) return;


    var clean = unwrapUrl(a.href);
//DPL PREFIX
     if (isExternal(clean)) {
$(function () {
      e.preventDefault();
     $('.dpl-short-title').each(function () {
      e.stopImmediatePropagation(); // předejdeme přepisům od Googlu
        var container = $(this);
      window.open(clean, '_blank', 'noopener');
        var prefix = container.data('prefix');
    }
  }, true); // capture = true => jsme před Googlem


  // 3) Ošetříme i odeslání formulářů (SAML/SSO, vyhledávače apod.)
        container.find('a').each(function () {
  document.addEventListener('submit', function (e) {
            var link = $(this);
    var f = e.target;
            var text = link.text();
    if (!(f && f.action)) return;
    var clean = unwrapUrl(f.action);
    if (isExternal(clean)) {
      // jen upravíme action a necháme proběhnout (cílit do nového okna)
      f.action = clean;
      f.target = '_blank';
    }
  }, true);


  // 4) Prvotní průchod a ošetření dynamicky přidaného obsahu
            if (prefix && text.startsWith(prefix)) {
  patchLinksAndForms(document);
                link.text(text.substring(prefix.length));
 
            }
  // Volitelně: observer pro později načtené bloky
  var mo = new MutationObserver(function (muts) {
    muts.forEach(function (m) {
      if (m.addedNodes) {
        m.addedNodes.forEach(function (n) {
          if (n.nodeType === 1) patchLinksAndForms(n);
         });
         });
      }
     });
     });
  });
});
   mo.observe(document.documentElement, { childList: true, subtree: true });
 
})();
//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);
  }
});

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