MediaWiki:Common.js : Différence entre versions

m
 
(85 révisions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
+
/* Tout le JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
  
 +
/* =====================================
 +
DECLARATIONS DES FONCTIONS ET PROCEDURES
 +
======================================== */
  
/* For a responsive Wiki we need to add the viewport meta tag to the head of the page */
+
function showElement(element) {
var viewPortTag=document.createElement('meta');
+
  element.classList.remove("tabber-noactive");
viewPortTag.id="viewport";
+
}
viewPortTag.name = "viewport";
 
  
/* user-scalable=no forbid to users to zoom in and out to the page, and only scroll it. */
+
function hideElement(element) {
viewPortTag.content = "width=device-width; initial-scale=1.0; user-scalable=yes";
+
  element.classList.add("tabber-noactive");
document.getElementsByTagName('head')[0].appendChild(viewPortTag);
+
}
  
var theme=document.createElement('meta');
+
function toggleElement(element) {
theme.id="theme";
+
  element.classList.toggle("tabber-noactive");
theme.name="theme-color";
+
}
theme.content="#1f0e02";
 
  
/* Slideshow pour faire défiler les images, c'est du JS pompé sur le wiki italien */
+
/* Favicon */
(function() {
+
function fixInsecureFavicon() {
 +
  document.querySelector('link[rel="shortcut icon"]').href =
 +
    "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
 +
}
  
   init(); //on page load - show first slide, hidethe rest
+
/* Liste des équipements */
 +
function changeEquipementDisplay(container) {
 +
   var switchButton = container.querySelector(".button");
 +
  var content = container.nextElementSibling;
  
   function init() {
+
   switchButton.addEventListener("click", function () {
 +
    switchButton.classList.toggle("tabber-active");
 +
    toggleElement(content);
 +
  });
 +
}
  
    parents = document.getElementsByClassName('slideshow-container');
+
/* Enlève l'animation de chargement et affiche le contenu de la page lorsque c'est nécessaire */
 +
function removeLoadingAnimation() {
 +
  var loadingAnimation = document.getElementById("loading-animation");
 +
  var showAfterLoading = document.getElementById("show-after-loading");
  
    for (j = 0; j < parents.length; j++) {
+
  if (loadingAnimation) {
      var slides = parents[j].getElementsByClassName("mySlides");
+
    hideElement(loadingAnimation);
      var dots = parents[j].getElementsByClassName("dot");
 
      slides[0].classList.add('active-slide');
 
      dots[0].classList.add('active');
 
    }
 
 
   }
 
   }
  
   dots = document.getElementsByClassName('dot'); //dots functionality
+
   if (showAfterLoading) {
 +
    showElement(showAfterLoading);
 +
  }
 +
}
  
   for (i = 0; i < dots.length; i++) {
+
/* BOUTON RETOUR VERS LE HAUT */
 +
function addButtonTop() {
 +
   var contentText = document.querySelector("div#mw-content-text");
  
    dots[i].onclick = function() {
+
  if (contentText !== null) {
 
+
    var divButtonTop = document.createElement("div");
      slides = this.parentNode.parentNode.getElementsByClassName("mySlides");
+
    divButtonTop.classList.add("top-button");
 
+
    contentText.appendChild(divButtonTop);
      for (j = 0; j < this.parentNode.children.length; j++) {
 
        this.parentNode.children[j].classList.remove('active');
 
        slides[j].classList.remove('active-slide');
 
        if (this.parentNode.children[j] == this) {
 
          index = j;
 
        }
 
      }
 
      this.classList.add('active');
 
      slides[index].classList.add('active-slide');
 
 
 
    }
 
 
   }
 
   }
//prev/next functionality
+
}
  links = document.querySelectorAll('.slideshow-container a');
 
 
 
  for (i = 0; i < links.length; i++) {
 
    links[i].onclick = function() {
 
      current = this.parentNode;
 
  
      var slides = current.getElementsByClassName("mySlides");
+
function buttonTop() {
      var dots = current.getElementsByClassName("dot");
+
  var balise = document.querySelector("div#mw-page-header-links");
      curr_slide = current.getElementsByClassName('active-slide')[0];
+
  var topButton = document.querySelector(".top-button");
      curr_dot = current.getElementsByClassName('active')[0];
 
      curr_slide.classList.remove('active-slide');
 
      curr_dot.classList.remove('active');
 
      if (this.className == 'next') {
 
  
        if (curr_slide.nextElementSibling.classList.contains('mySlides')) {
+
  if (balise !== null) {
          curr_slide.nextElementSibling.classList.add('active-slide');
+
    var options = {
          curr_dot.nextElementSibling.classList.add('active');
+
      root: null,
        } else {
+
      rootMargin: "0px",
          slides[0].classList.add('active-slide');
+
      threshold: 0,
          dots[0].classList.add('active');
+
    };
        }
 
  
      }
+
    var observer = new IntersectionObserver(callback, options);
 +
    observer.observe(balise);
  
       if (this.className == 'prev') {
+
    function callback(entries) {
 
+
       entries.forEach(function (entry) {
         if (curr_slide.previousElementSibling) {
+
         if (entry.isIntersecting) {
           curr_slide.previousElementSibling.classList.add('active-slide');
+
           topButton.classList.remove("show-button");
          curr_dot.previousElementSibling.classList.add('active');
 
 
         } else {
 
         } else {
           slides[slides.length - 1].classList.add('active-slide');
+
           topButton.classList.add("show-button");
          dots[slides.length - 1].classList.add('active');
 
 
         }
 
         }
 
+
       });
       }
 
 
 
 
     }
 
     }
  
 +
    topButton.addEventListener("click", function () {
 +
      document.documentElement.scrollTo({
 +
        top: 0,
 +
      });
 +
    });
 
   }
 
   }
})();
+
}
  
 +
/* Cookies */
 +
function cookies() {
 +
  var req = new XMLHttpRequest();
 +
  req.addEventListener("load", function (ev) {
 +
    if (this.status >= 200 && this.status < 300) {
 +
      var data = JSON.parse(this.responseText);
 +
      if (data.hasOwnProperty("version")) {
 +
        var gdpr = document.createElement("script");
 +
        gdpr.src =
 +
          "https://s3-static.geo.gfsrv.net/cookiebanner/" +
 +
          data.version +
 +
          "/cookie.min.js";
 +
        document.head.appendChild(gdpr);
 +
      }
 +
    }
 +
  });
 +
  req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
 +
  req.send();
 +
}
  
 +
function addScript(src, callback) {
 +
  var script = document.createElement("script");
 +
  script.src = src;
  
/*
+
  function onComplete() {
* rwdImageMaps jQuery plugin v1.6
+
    if (script.parentNode) {
*
+
      script.parentNode.removeChild(script);
* Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
+
    }
*
+
    if (callback) {
* Copyright (c) 2016 Matt Stow
+
      callback();
* https://github.com/stowball/jQuery-rwdImageMaps
+
    }
* http://mattstow.com
+
  }
* Licensed under the MIT license
 
*/
 
;(function($) {
 
$.fn.rwdImageMaps = function() {
 
var $img = this;
 
  
var rwdImageMap = function() {
+
  script.onload = onComplete;
$img.each(function() {
+
  script.onerror = onComplete;
if (typeof($(this).attr('usemap')) == 'undefined')
 
return;
 
  
var that = this,
+
  document.head.appendChild(script);
$that = $(that);
+
}
  
// Since WebKit doesn't know the height until after the image has loaded, perform everything in an onload copy
+
/* =======================================
$('<img />').on('load', function() {
+
FONCTION GLOBALE
var attrW = 'width',
+
Exécutée une fois au chargement de la page
attrH = 'height',
+
========================================== */
w = $that.attr(attrW),
 
h = $that.attr(attrH);
 
  
if (!w || !h) {
+
(function () {
var temp = new Image();
+
  fixInsecureFavicon();
temp.src = $that.attr('src');
 
if (!w)
 
w = temp.width;
 
if (!h)
 
h = temp.height;
 
}
 
  
var wPercent = $that.width()/100,
+
  var equipmentContainer = document.querySelectorAll(
hPercent = $that.height()/100,
+
    "div#mw-content-text .list-equip"
map = $that.attr('usemap').replace('#', ''),
+
  );
c = 'coords';
+
  var loadScripts = document.querySelectorAll("div[data-load-javascript]");
  
$('map[name="' + map + '"]').find('area').each(function() {
+
  equipmentContainer.forEach(function (container) {
var $this = $(this);
+
    changeEquipementDisplay(container);
if (!$this.data(c))
+
  });
$this.data(c, $this.attr(c));
 
  
var coords = $this.data(c).split(','),
+
  /* Charge des scripts spécifiques au chargement de certaines pages */
coordsPercent = new Array(coords.length);
+
  if (loadScripts.length > 0) {
 +
    var allowedScripts = [
 +
      "Tabber",
 +
      "Skills",
 +
      "Modal",
 +
      "Switch",
 +
      "Loot",
 +
      "Map",
 +
      "Filter",
 +
      "Calculator",
 +
      "Element",
 +
      "Pets",
 +
      "Colorblind",
 +
    ];
 +
    var scriptsToLoad = [];
  
for (var i = 0; i < coordsPercent.length; ++i) {
+
    for (var i = 0; i < loadScripts.length; i++) {
if (i % 2 === 0)
+
      var script = loadScripts[i].dataset["loadJavascript"];
coordsPercent[i] = parseInt(((coords[i]/w)*100)*wPercent);
 
else
 
coordsPercent[i] = parseInt(((coords[i]/h)*100)*hPercent);
 
}
 
$this.attr(c, coordsPercent.toString());
 
});
 
}).attr('src', $that.attr('src'));
 
});
 
};
 
$(window).resize(rwdImageMap).trigger('resize');
 
  
return this;
+
      if (
};
+
        allowedScripts.indexOf(script) !== -1 &&
})(jQuery);
+
        scriptsToLoad.indexOf(script) === -1
 +
      ) {
 +
        scriptsToLoad.push(script);
 +
      }
 +
    }
  
$(document).ready(function(e) {
+
    function loadNextScript() {
    $('img[usemap]').rwdImageMaps();
+
      if (scriptsToLoad.length > 0) {
});
+
        var script = scriptsToLoad.shift();
 
+
        addScript(
// Modal windows in javascript
+
          "/index.php?title=MediaWiki:Script/" +
 
+
            script +
$(".trigger").on("click", function() {
+
            ".js&action=raw&ctype=text/javascript",
    var modal = $(this).data("modal");
+
          loadNextScript
    $(modal).toggle();
+
        );
});
+
      } else {
 
+
         removeLoadingAnimation();
$(".modal").on("click", function(e) {
+
      }
    var className = e.target.className;
 
    if(className === "modal" || className === "close-button"){
 
         $(this).closest(".modal").toggle();
 
 
     }
 
     }
});
 
  
/* Pour le bas de page */
+
    loadNextScript();
 +
  }
  
$('div#content').append( "<div class='content-footer'></div>" );
+
  if (mw.config.get("wgUserName")) {
 
+
    mw.loader.load(
/* Pour les cookies */
+
      "/index.php?title=MediaWiki:Script/Redactor.js&action=raw&ctype=text/javascript"
 +
    );
 +
  }
  
(function () {
+
  addButtonTop();
    var req = new XMLHttpRequest();
+
  buttonTop();
    req.addEventListener('load', function (ev) {
+
  cookies();
        if (this.status >= 200 && this.status < 300) {
 
            var data = JSON.parse(this.responseText);
 
            if (data.hasOwnProperty('version')) {
 
                var gdpr = document.createElement("script");
 
                gdpr.src = "https://s3-static.geo.gfsrv.net/cookiebanner/" + data.version + "/cookie.min.js";
 
                document.head.appendChild(gdpr);
 
            }
 
        }
 
    });
 
    req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
 
    req.send();
 
 
})();
 
})();

Version actuelle datée du 1 décembre 2024 à 06:23

/* Tout le JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */

/* =====================================
DECLARATIONS DES FONCTIONS ET PROCEDURES
======================================== */

function showElement(element) {
  element.classList.remove("tabber-noactive");
}

function hideElement(element) {
  element.classList.add("tabber-noactive");
}

function toggleElement(element) {
  element.classList.toggle("tabber-noactive");
}

/* Favicon */
function fixInsecureFavicon() {
  document.querySelector('link[rel="shortcut icon"]').href =
    "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
}

/* Liste des équipements */
function changeEquipementDisplay(container) {
  var switchButton = container.querySelector(".button");
  var content = container.nextElementSibling;

  switchButton.addEventListener("click", function () {
    switchButton.classList.toggle("tabber-active");
    toggleElement(content);
  });
}

/* Enlève l'animation de chargement et affiche le contenu de la page lorsque c'est nécessaire */
function removeLoadingAnimation() {
  var loadingAnimation = document.getElementById("loading-animation");
  var showAfterLoading = document.getElementById("show-after-loading");

  if (loadingAnimation) {
    hideElement(loadingAnimation);
  }

  if (showAfterLoading) {
    showElement(showAfterLoading);
  }
}

/* BOUTON RETOUR VERS LE HAUT */
function addButtonTop() {
  var contentText = document.querySelector("div#mw-content-text");

  if (contentText !== null) {
    var divButtonTop = document.createElement("div");
    divButtonTop.classList.add("top-button");
    contentText.appendChild(divButtonTop);
  }
}

function buttonTop() {
  var balise = document.querySelector("div#mw-page-header-links");
  var topButton = document.querySelector(".top-button");

  if (balise !== null) {
    var options = {
      root: null,
      rootMargin: "0px",
      threshold: 0,
    };

    var observer = new IntersectionObserver(callback, options);
    observer.observe(balise);

    function callback(entries) {
      entries.forEach(function (entry) {
        if (entry.isIntersecting) {
          topButton.classList.remove("show-button");
        } else {
          topButton.classList.add("show-button");
        }
      });
    }

    topButton.addEventListener("click", function () {
      document.documentElement.scrollTo({
        top: 0,
      });
    });
  }
}

/* Cookies */
function cookies() {
  var req = new XMLHttpRequest();
  req.addEventListener("load", function (ev) {
    if (this.status >= 200 && this.status < 300) {
      var data = JSON.parse(this.responseText);
      if (data.hasOwnProperty("version")) {
        var gdpr = document.createElement("script");
        gdpr.src =
          "https://s3-static.geo.gfsrv.net/cookiebanner/" +
          data.version +
          "/cookie.min.js";
        document.head.appendChild(gdpr);
      }
    }
  });
  req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
  req.send();
}

function addScript(src, callback) {
  var script = document.createElement("script");
  script.src = src;

  function onComplete() {
    if (script.parentNode) {
      script.parentNode.removeChild(script);
    }
    if (callback) {
      callback();
    }
  }

  script.onload = onComplete;
  script.onerror = onComplete;

  document.head.appendChild(script);
}

/* =======================================
FONCTION GLOBALE
Exécutée une fois au chargement de la page
========================================== */

(function () {
  fixInsecureFavicon();

  var equipmentContainer = document.querySelectorAll(
    "div#mw-content-text .list-equip"
  );
  var loadScripts = document.querySelectorAll("div[data-load-javascript]");

  equipmentContainer.forEach(function (container) {
    changeEquipementDisplay(container);
  });

  /* Charge des scripts spécifiques au chargement de certaines pages */
  if (loadScripts.length > 0) {
    var allowedScripts = [
      "Tabber",
      "Skills",
      "Modal",
      "Switch",
      "Loot",
      "Map",
      "Filter",
      "Calculator",
      "Element",
      "Pets",
      "Colorblind",
    ];
    var scriptsToLoad = [];

    for (var i = 0; i < loadScripts.length; i++) {
      var script = loadScripts[i].dataset["loadJavascript"];

      if (
        allowedScripts.indexOf(script) !== -1 &&
        scriptsToLoad.indexOf(script) === -1
      ) {
        scriptsToLoad.push(script);
      }
    }

    function loadNextScript() {
      if (scriptsToLoad.length > 0) {
        var script = scriptsToLoad.shift();
        addScript(
          "/index.php?title=MediaWiki:Script/" +
            script +
            ".js&action=raw&ctype=text/javascript",
          loadNextScript
        );
      } else {
        removeLoadingAnimation();
      }
    }

    loadNextScript();
  }

  if (mw.config.get("wgUserName")) {
    mw.loader.load(
      "/index.php?title=MediaWiki:Script/Redactor.js&action=raw&ctype=text/javascript"
    );
  }

  addButtonTop();
  buttonTop();
  cookies();
})();