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

Z The Last Kingdom UO Wiki
Bez shrnutí editace
Bez shrnutí editace
značka: ruční vrácení zpět
 
(Není zobrazeno 6 mezilehlých verzí od stejného uživatele.)
Řádek 1: Řádek 1:
// Force Google Translate widget to load on every page
mw.loader.using(['mediawiki.util'], function () {
(function () {
   $(function () {
   function addGoogleTranslate() {
    if (document.getElementById('google_translate_element')) return;


     var div = document.createElement('div');
     function createSwitcher() {
    div.id = 'google_translate_element';
      if ($('#lang-switcher').length) return;
    div.style.position = 'fixed';
    div.style.top = '10px';
    div.style.right = '10px';
    div.style.zIndex = '9999';
    document.body.appendChild(div);


    var script = document.createElement('script');
      $('body').append(
    script.src = "https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit";
        '<div id="lang-switcher" style="position:fixed;top:10px;right:10px;z-index:9999;background:#fff;padding:6px 12px;border:1px solid #ccc;border-radius:6px;font-size:14px;box-shadow:0 2px 6px rgba(0,0,0,0.2);">' +
    document.body.appendChild(script);
        '<a href="#" id="lang-cs">Čeština</a> | ' +
  }
        '<a href="#" id="lang-en">English</a>' +
        '</div>'
      );


  window.googleTranslateElementInit = function () {
      $('#lang-en').click(function (e) {
    new google.translate.TranslateElement({
        e.preventDefault();
      pageLanguage: 'cs',
        document.cookie = "googtrans=/cs/en;path=/";
      includedLanguages: 'cs,en',
        location.reload();
      autoDisplay: false
      });
    }, 'google_translate_element');
  };


  document.addEventListener("DOMContentLoaded", addGoogleTranslate);
      $('#lang-cs').click(function (e) {
})();
        e.preventDefault();
        document.cookie = "googtrans=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;";
        location.reload();
      });
    }
 
    function loadGoogle() {
      if ($('#google_translate_element').length) return;
 
      $('body').append('<div id="google_translate_element" style="display:none;"></div>');
 
      window.googleTranslateElementInit = function () {
        new google.translate.TranslateElement({
          pageLanguage: 'cs',
          includedLanguages: 'cs,en',
          autoDisplay: false
        }, 'google_translate_element');
      };
 
      $.getScript('https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');
    }
 
    createSwitcher();
    loadGoogle();
 
    // Reinforce switcher after translation DOM rewrite
    setTimeout(createSwitcher, 2000);
 
  });
});