MediaWiki:Common.js : Différence entre versions

 
(6 révisions intermédiaires par le même utilisateur non affichées)
Ligne 4 : Ligne 4 :
 
DECLARATIONS DES FONCTIONS ET PROCEDURES
 
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 */
 
/* Favicon */
 
function fixInsecureFavicon() {
 
function fixInsecureFavicon() {
   document.querySelector('link[rel="shortcut icon"]').href = "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
+
   document.querySelector('link[rel="shortcut icon"]').href =
 +
    "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
 
}
 
}
  
 
/* Liste des équipements */
 
/* Liste des équipements */
function changeDisplay(content){
+
function changeEquipementDisplay(container) {
 
+
   var switchButton = container.querySelector(".button");
   var boutonSwitch = content.querySelector(".button");
+
   var content = container.nextElementSibling;
   var frereList = content.nextElementSibling;
+
 
 
+
   switchButton.addEventListener("click", function () {
   boutonSwitch.addEventListener("click", function(){
+
     switchButton.classList.toggle("tabber-active");
     this.classList.toggle('tabber-active');
+
     toggleElement(content);
     frereList.classList.toggle('tabber-noactive');
 
 
   });
 
   });
 +
}
 +
 +
/* 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 */
 
/* BOUTON RETOUR VERS LE HAUT */
 
function addButtonTop() {
 
function addButtonTop() {
 
 
 
   var contentText = document.querySelector("div#mw-content-text");
 
   var contentText = document.querySelector("div#mw-content-text");
 
+
 
 
   if (contentText !== null) {
 
   if (contentText !== null) {
   
 
 
     var divButtonTop = document.createElement("div");
 
     var divButtonTop = document.createElement("div");
 
     divButtonTop.classList.add("top-button");
 
     divButtonTop.classList.add("top-button");
Ligne 36 : Ligne 60 :
  
 
function buttonTop() {
 
function buttonTop() {
 
 
 
   var balise = document.querySelector("div#mw-page-header-links");
 
   var balise = document.querySelector("div#mw-page-header-links");
 
   var topButton = document.querySelector(".top-button");
 
   var topButton = document.querySelector(".top-button");
 
+
 
 
   if (balise !== null) {
 
   if (balise !== null) {
 
     var options = {
 
     var options = {
Ligne 46 : Ligne 69 :
 
       threshold: 0,
 
       threshold: 0,
 
     };
 
     };
 
+
 
 
     var observer = new IntersectionObserver(callback, options);
 
     var observer = new IntersectionObserver(callback, options);
 
     observer.observe(balise);
 
     observer.observe(balise);
  
 
     function callback(entries) {
 
     function callback(entries) {
       entries.forEach(function(entry) {
+
       entries.forEach(function (entry) {
 
         if (entry.isIntersecting) {
 
         if (entry.isIntersecting) {
 
           topButton.classList.remove("show-button");
 
           topButton.classList.remove("show-button");
 
         } else {
 
         } else {
        topButton.classList.add("show-button");
+
          topButton.classList.add("show-button");
 
         }
 
         }
 
       });
 
       });
 
     }
 
     }
  
     topButton.addEventListener("click", function(){
+
     topButton.addEventListener("click", function () {
 
       document.documentElement.scrollTo({
 
       document.documentElement.scrollTo({
         top: 0
+
         top: 0,
 
       });
 
       });
 
     });
 
     });
Ligne 70 : Ligne 93 :
 
/* Cookies */
 
/* Cookies */
 
function cookies() {
 
function cookies() {
    var req = new XMLHttpRequest();
+
  var req = new XMLHttpRequest();
    req.addEventListener('load', function (ev) {
+
  req.addEventListener("load", function (ev) {
        if (this.status >= 200 && this.status < 300) {
+
    if (this.status >= 200 && this.status < 300) {
            var data = JSON.parse(this.responseText);
+
      var data = JSON.parse(this.responseText);
            if (data.hasOwnProperty('version')) {
+
      if (data.hasOwnProperty("version")) {
                var gdpr = document.createElement("script");
+
        var gdpr = document.createElement("script");
                gdpr.src = "https://s3-static.geo.gfsrv.net/cookiebanner/" + data.version + "/cookie.min.js";
+
        gdpr.src =
                document.head.appendChild(gdpr);
+
          "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();
+
    }
 +
  });
 +
  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);
 
}
 
}
  
Ligne 90 : Ligne 135 :
 
========================================== */
 
========================================== */
  
(function(){
+
(function () {
 
+
   fixInsecureFavicon();
   fixInsecureFavicon()
 
 
 
  var equipmentContainer = document.querySelectorAll('div#mw-content-text .list-equip');
 
  var loadScripts = document.querySelectorAll('div[data-load-javascript]');
 
  
   equipmentContainer.forEach(function(container){
+
  var equipmentContainer = document.querySelectorAll(
     changeDisplay(container);
+
    "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 */
 
   /* Charge des scripts spécifiques au chargement de certaines pages */
   if (loadScripts.length) {
+
   if (loadScripts.length > 0) {
 +
    var allowedScripts = [
 +
      "Tabber",
 +
      "Skills",
 +
      "Modal",
 +
      "Switch",
 +
      "Loot",
 +
      "Map",
 +
      "Filter",
 +
      "Calculator",
 +
      "Element",
 +
      "Pets",
 +
      "Colorblind",
 +
    ];
 +
    var scriptsToLoad = [];
  
     var scriptNames = {Tabber: true, Skills: true, Modal: true, Switch: true, Loot: true, Map: true};
+
     for (var i = 0; i < loadScripts.length; i++) {
 +
      var script = loadScripts[i].dataset["loadJavascript"];
  
    loadScripts.forEach(function(el) {
+
      if (
 +
        allowedScripts.indexOf(script) !== -1 &&
 +
        scriptsToLoad.indexOf(script) === -1
 +
      ) {
 +
        scriptsToLoad.push(script);
 +
      }
 +
    }
  
       var script = el.dataset['loadJavascript'];
+
    function loadNextScript() {
 
+
       if (scriptsToLoad.length > 0) {
      if (scriptNames[script]) {
+
        var script = scriptsToLoad.shift();
         mw.loader.load("/index.php?title=MediaWiki:Script/" + script + ".js&action=raw&ctype=text/javascript");
+
         addScript(
         delete scriptNames[script];
+
          "/index.php?title=MediaWiki:Script/" +
 +
            script +
 +
            ".js&action=raw&ctype=text/javascript",
 +
          loadNextScript
 +
        );
 +
      } else {
 +
         removeLoadingAnimation();
 
       }
 
       }
 +
    }
  
     });
+
     loadNextScript();
 
   }
 
   }
 
+
 
 
   if (mw.config.get("wgUserName")) {
 
   if (mw.config.get("wgUserName")) {
     mw.loader.load("/index.php?title=MediaWiki:Script/Redactor.js&action=raw&ctype=text/javascript");
+
     mw.loader.load(
 +
      "/index.php?title=MediaWiki:Script/Redactor.js&action=raw&ctype=text/javascript"
 +
    );
 
   }
 
   }
  
 
   addButtonTop();
 
   addButtonTop();
 
   buttonTop();
 
   buttonTop();
   cookies()
+
   cookies();
 
 
 
})();
 
})();

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