MediaWiki:Common.js : Différence entre versions

(pour que les images fassent la bonne taille)
 
(89 révisions intermédiaires par 3 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. */
  
$('div#content').append( "<div class='content-footer'></div>" );
+
/* =====================================
 +
DECLARATIONS DES FONCTIONS ET PROCEDURES
 +
======================================== */
  
(function () {
+
function showElement(element) {
    var req = new XMLHttpRequest();
+
  element.classList.remove("tabber-noactive");
    req.addEventListener('load', function (ev) {
+
}
        if (this.status >= 200 && this.status < 300) {
+
 
            var data = JSON.parse(this.responseText);
+
function hideElement(element) {
            if (data.hasOwnProperty('version')) {
+
  element.classList.add("tabber-noactive");
                var gdpr = document.createElement("script");
+
}
                gdpr.src = "https://s3-static.geo.gfsrv.net/cookiebanner/" + data.version + "/cookie.min.js";
+
 
                document.head.appendChild(gdpr);
+
function toggleElement(element) {
            }
+
  element.classList.toggle("tabber-noactive");
        }
+
}
    });
+
 
    req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
+
/* Favicon */
     req.send();
+
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");
  
/* Slideshow pour faire défiler les images, c'est du JS pompé sur le wiki italien */
+
  if (balise !== null) {
(function() {
+
    var options = {
+
      root: null,
function Slideshow( element ) {
+
      rootMargin: "0px",
this.el = document.querySelector( element );
+
      threshold: 0,
this.init();
+
    };
}
 
 
Slideshow.prototype = {
 
init: function() {
 
this.wrapper = this.el.querySelector( ".slider-wrapper" );
 
this.slides = this.el.querySelectorAll( ".slide" );
 
this.previous = this.el.querySelector( ".slider-previous" );
 
this.next = this.el.querySelector( ".slider-next" );
 
this.index = 0;
 
this.total = this.slides.length;
 
 
this.actions();
 
},
 
_slideTo: function( slide ) {
 
var currentSlide = this.slides[slide];
 
currentSlide.style.display="block";
 
 
for( var i = 0; i < this.slides.length; i++ ) {
 
var slide = this.slides[i];
 
if( slide !== currentSlide ) {
 
slide.style.display="none";
 
}
 
}
 
},
 
actions: function() {
 
var self = this;
 
self.next.addEventListener( "click", function() {
 
self.index++;
 
self.previous.style.display = "block";
 
 
if( self.index == self.total - 1 ) {
 
self.index = self.total - 1;
 
self.next.style.display = "none";
 
}
 
if (self.index > self.total) {self.index = self.total}
 
if (self.index < 1) {self.index = 1}
 
self._slideTo( self.index );
 
 
}, false);
 
 
self.previous.addEventListener( "click", function() {
 
self.index--;
 
self.next.style.display = "block";
 
 
if( self.index == 0 ) {
 
self.index = 0;
 
self.previous.style.display = "none";
 
}
 
 
self._slideTo( self.index );
 
 
}, false);
 
}
 
 
};
 
document.addEventListener( "DOMContentLoaded", function() {
 
 
var slider = new Slideshow( "#main-slider" );
 
});
 
})();
 
  
 +
    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 () {
* rwdImageMaps jQuery plugin v1.6
+
      document.documentElement.scrollTo({
*
+
        top: 0,
* 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
+
      });
*
+
    });
* Copyright (c) 2016 Matt Stow
+
  }
* https://github.com/stowball/jQuery-rwdImageMaps
+
}
* http://mattstow.com
 
* Licensed under the MIT license
 
*/
 
;(function($) {
 
$.fn.rwdImageMaps = function() {
 
var $img = this;
 
  
var rwdImageMap = function() {
+
/* Cookies */
$img.each(function() {
+
function cookies() {
if (typeof($(this).attr('usemap')) == 'undefined')
+
  var req = new XMLHttpRequest();
return;
+
  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();
 +
}
  
var that = this,
+
function addScript(src, callback) {
$that = $(that);
+
  var script = document.createElement("script");
 +
  script.src = src;
  
// Since WebKit doesn't know the height until after the image has loaded, perform everything in an onload copy
+
  function onComplete() {
$('<img />').on('load', function() {
+
    if (script.parentNode) {
var attrW = 'width',
+
      script.parentNode.removeChild(script);
attrH = 'height',
+
    }
w = $that.attr(attrW),
+
    if (callback) {
h = $that.attr(attrH);
+
      callback();
 +
    }
 +
  }
  
if (!w || !h) {
+
  script.onload = onComplete;
var temp = new Image();
+
  script.onerror = onComplete;
temp.src = $that.attr('src');
 
if (!w)
 
w = temp.width;
 
if (!h)
 
h = temp.height;
 
}
 
  
var wPercent = $that.width()/100,
+
  document.head.appendChild(script);
hPercent = $that.height()/100,
+
}
map = $that.attr('usemap').replace('#', ''),
 
c = 'coords';
 
  
$('map[name="' + map + '"]').find('area').each(function() {
+
/* =======================================
var $this = $(this);
+
FONCTION GLOBALE
if (!$this.data(c))
+
Exécutée une fois au chargement de la page
$this.data(c, $this.attr(c));
+
========================================== */
  
var coords = $this.data(c).split(','),
+
(function () {
coordsPercent = new Array(coords.length);
+
  fixInsecureFavicon();
  
for (var i = 0; i < coordsPercent.length; ++i) {
+
  var equipmentContainer = document.querySelectorAll(
if (i % 2 === 0)
+
    "div#mw-content-text .list-equip"
coordsPercent[i] = parseInt(((coords[i]/w)*100)*wPercent);
+
  );
else
+
  var loadScripts = document.querySelectorAll("div[data-load-javascript]");
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;
+
  equipmentContainer.forEach(function (container) {
};
+
    changeEquipementDisplay(container);
})(jQuery);
+
  });
  
$(document).ready(function(e) {
+
  /* Charge des scripts spécifiques au chargement de certaines pages */
     $('img[usemap]').rwdImageMaps();
+
  if (loadScripts.length > 0) {
});
+
     var allowedScripts = [
 +
      "Tabber",
 +
      "Skills",
 +
      "Modal",
 +
      "Switch",
 +
      "Loot",
 +
      "Map",
 +
      "Filter",
 +
      "Calculator",
 +
      "Element",
 +
      "Pets",
 +
      "Colorblind",
 +
    ];
 +
    var scriptsToLoad = [];
  
// Modal windows in javascript
+
    for (var i = 0; i < loadScripts.length; i++) {
 +
      var script = loadScripts[i].dataset["loadJavascript"];
  
$(".trigger").on("click", function() {
+
      if (
    var modal = $(this).data("modal");
+
        allowedScripts.indexOf(script) !== -1 &&
    $(modal).toggle();
+
        scriptsToLoad.indexOf(script) === -1
});
+
      ) {
 +
        scriptsToLoad.push(script);
 +
      }
 +
    }
  
$(".modal").on("click", function(e) {
+
    function loadNextScript() {
    var className = e.target.className;
+
      if (scriptsToLoad.length > 0) {
    if(className === "modal" || className === "close-button"){
+
        var script = scriptsToLoad.shift();
         $(this).closest(".modal").toggle();
+
        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();
 +
})();

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