Diferenças entre edições de "MediaWiki:Common.js"

Linha 1: Linha 1:
 
/* Código Javascript colocado aqui será carregado para todos os utilizadores em cada carregamento de página */
 
/* Código Javascript colocado aqui será carregado para todos os utilizadores em cada carregamento de página */
  
/* Favicon */
+
/* =====================================
function fixInsecureFavicon() {
+
  FUNÇÕES AUXILIARES
  document.querySelector('link[rel="shortcut icon"]').href =
+
  ===================================== */
    "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
 
}
 
  
 
/* Tabber helpers */
 
/* Tabber helpers */
Linha 20: Linha 18:
 
}
 
}
  
/* Liste des équipements */
+
/* Favicon */
 +
function fixInsecureFavicon() {
 +
  var favicon = document.querySelector('link[rel="shortcut icon"]');
 +
  if (favicon) {
 +
    favicon.href = "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
 +
  }
 +
}
 +
 
 +
/* Liste des équipements / Lista de equipamentos */
 
function changeEquipementDisplay(container) {
 
function changeEquipementDisplay(container) {
 
   var switchButton = container.querySelector(".button");
 
   var switchButton = container.querySelector(".button");
 
   var content = container.nextElementSibling;
 
   var content = container.nextElementSibling;
 +
 +
  if (!switchButton || !content) return;
  
 
   switchButton.addEventListener("click", function () {
 
   switchButton.addEventListener("click", function () {
Linha 31: Linha 39:
 
}
 
}
  
/* Slideshow con pulsanti avanti e indietro in javascript */
+
/* Remove animação de loading e mostra conteúdo assim que estiver pronto */
(function() {
+
function removeLoadingAnimation() {
 +
  var loadingAnimation = document.getElementById("loading-animation");
 +
  var showAfterLoading = document.getElementById("show-after-loading");
  
    function Slideshow( element ) {
+
  if (loadingAnimation) {
        this.el = document.querySelector( element );
+
    hideElement(loadingAnimation);
        this.init();
+
  }
    }
 
  
    Slideshow.prototype = {
+
  if (showAfterLoading) {
        init: function() {
+
    showElement(showAfterLoading);
            this.wrapper = this.el.querySelector( ".slider-wrapper_wiki" );
+
  }
            this.slides = this.el.querySelectorAll( ".slide_wiki" );
+
}
            this.previous = this.el.querySelector( ".slider-previous" );
 
            this.next = this.el.querySelector( ".slider-next" );
 
            this.index = 0;
 
            this.total = this.slides.length;
 
  
            this.actions();
+
/* BOTÃO VOLTAR AO TOPO */
        },
+
function addButtonTop() {
        _slideTo: function( slide ) {
+
  var contentText = document.querySelector("div#mw-content-text");
            var currentSlide = this.slides[slide];
 
            currentSlide.style.display="block";
 
  
            for( var i = 0; i < this.slides.length; i++ ) {
+
  if (contentText !== null) {
                var slide = this.slides[i];
+
    var divButtonTop = document.createElement("div");
                if( slide !== currentSlide ) {
+
     divButtonTop.classList.add("top-button");
                    slide.style.display="none";
+
     contentText.appendChild(divButtonTop);
                }
+
  }
            }
+
}
        },
 
        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" );
 
     });
 
})();
 
 
 
/* Avvio Finestre modal */
 
 
 
$(".trigger").on("click", function() {
 
    var modal = $(this).data("modal");
 
    $(modal).toggle();
 
});
 
 
 
$(".modal").on("click", function(e) {
 
    var className = e.target.className;
 
    if(className === "modal" || className === "close-button"){
 
        $(this).closest(".modal").toggle();
 
    }
 
});
 
 
 
/* Cookie GF */
 
(function () {
 
    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 changeEquipementDisplay(container) {
 
  var switchButton = container.querySelector(".button");
 
  var content = container.nextElementSibling;
 
  
  switchButton.addEventListener("click", function () {
 
    switchButton.classList.toggle("tabber-active");
 
    toggleElement(content);
 
  });
 
}
 
 
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 && topButton !== null) {
 
     var options = {
 
     var options = {
 
       root: null,
 
       root: null,
 
       rootMargin: "0px",
 
       rootMargin: "0px",
       threshold: 0,
+
       threshold: 0
 
     };
 
     };
  
Linha 164: Linha 90:
 
     topButton.addEventListener("click", function () {
 
     topButton.addEventListener("click", function () {
 
       document.documentElement.scrollTo({
 
       document.documentElement.scrollTo({
         top: 0,
+
         top: 0
 
       });
 
       });
 
     });
 
     });
 
   }
 
   }
 
}
 
}
 +
 +
/* Cookies GF */
 +
function cookies() {
 +
  var req = new XMLHttpRequest();
 +
  req.addEventListener("load", function () {
 +
    if (this.status >= 200 && this.status < 300) {
 +
      try {
 +
        var data = JSON.parse(this.responseText);
 +
        if (data && Object.prototype.hasOwnProperty.call(data, "version")) {
 +
          var gdpr = document.createElement("script");
 +
          gdpr.src =
 +
            "https://s3-static.geo.gfsrv.net/cookiebanner/" +
 +
            data.version +
 +
            "/cookie.min.js";
 +
          document.head.appendChild(gdpr);
 +
        }
 +
      } catch (e) {
 +
        // falha a ler JSON, ignora
 +
      }
 +
    }
 +
  });
 +
  req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
 +
  req.send();
 +
}
 +
 +
/* =====================================
 +
  SLIDESHOW
 +
  ===================================== */
 +
 +
/* Slideshow con pulsanti avanti e indietro in javascript */
 +
(function () {
 +
  function Slideshow(element) {
 +
    this.el = document.querySelector(element);
 +
    if (!this.el) return;
 +
    this.init();
 +
  }
 +
 +
  Slideshow.prototype = {
 +
    init: function () {
 +
      this.wrapper = this.el.querySelector(".slider-wrapper_wiki");
 +
      this.slides = this.el.querySelectorAll(".slide_wiki");
 +
      this.previous = this.el.querySelector(".slider-previous");
 +
      this.next = this.el.querySelector(".slider-next");
 +
      this.index = 0;
 +
      this.total = this.slides.length;
 +
 +
      if (!this.slides.length || !this.next || !this.previous) return;
 +
 +
      this.actions();
 +
      this._slideTo(this.index);
 +
    },
 +
    _slideTo: function (slide) {
 +
      var currentSlide = this.slides[slide];
 +
      if (!currentSlide) return;
 +
 +
      currentSlide.style.display = "block";
 +
 +
      for (var i = 0; i < this.slides.length; i++) {
 +
        var s = this.slides[i];
 +
        if (s !== currentSlide) {
 +
          s.style.display = "none";
 +
        }
 +
      }
 +
    },
 +
    actions: function () {
 +
      var self = this;
 +
 +
      this.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 < 0) self.index = 0;
 +
 +
          self._slideTo(self.index);
 +
        },
 +
        false
 +
      );
 +
 +
      this.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 () {
 +
    new Slideshow("#main-slider");
 +
  });
 +
})();
 +
 +
/* =====================================
 +
  MODAIS (JQUERY)
 +
  ===================================== */
 +
 +
$(".trigger").on("click", function () {
 +
  var modal = $(this).data("modal");
 +
  $(modal).toggle();
 +
});
 +
 +
$(".modal").on("click", function (e) {
 +
  var className = e.target.className;
 +
  if (className === "modal" || className === "close-button") {
 +
    $(this).closest(".modal").toggle();
 +
  }
 +
});
 +
 +
/* =======================================
 +
  FUNÇÃO GLOBAL – corre ao carregar a página
 +
  ======================================= */
 +
 
(function () {
 
(function () {
 
   fixInsecureFavicon();
 
   fixInsecureFavicon();
Linha 175: Linha 228:
 
   var urlEnd = ".js&action=raw&ctype=text/javascript";
 
   var urlEnd = ".js&action=raw&ctype=text/javascript";
 
   var loadScripts = document.querySelectorAll("div[data-load-javascript]");
 
   var loadScripts = document.querySelectorAll("div[data-load-javascript]");
 
 
   var equipmentContainer = document.querySelectorAll(
 
   var equipmentContainer = document.querySelectorAll(
 
     "div#mw-content-text .list-equip"
 
     "div#mw-content-text .list-equip"
 
   );
 
   );
  
 +
  /* Lista de equipamentos */
 
   equipmentContainer.forEach(function (container) {
 
   equipmentContainer.forEach(function (container) {
 
     changeEquipementDisplay(container);
 
     changeEquipementDisplay(container);
 
   });
 
   });
  
   /* Charge des scripts spécifiques au chargement de certaines pages */
+
   /* Carrega scripts específicos dependendo da página */
 
   if (loadScripts.length) {
 
   if (loadScripts.length) {
 
     var allowedScripts = {
 
     var allowedScripts = {
Linha 197: Linha 250:
 
       Element: true,
 
       Element: true,
 
       Pets: true,
 
       Pets: true,
       Colorblind: true,
+
       Colorblind: true
 
     };
 
     };
 +
 
     var scriptsToLoad = [];
 
     var scriptsToLoad = [];
  
Linha 214: Linha 268:
  
 
       if (firstScriptName === "Element") {
 
       if (firstScriptName === "Element") {
         scriptsToLoad.shift()
+
         scriptsToLoad.shift();
 
         $.getScript(urlStart + firstScriptName + urlEnd, function () {
 
         $.getScript(urlStart + firstScriptName + urlEnd, function () {
           injectCustomElements();
+
           if (typeof injectCustomElements === "function") {
 +
            injectCustomElements();
 +
          }
 
           loadNextScripts();
 
           loadNextScripts();
 
         });
 
         });
Linha 233: Linha 289:
 
   }
 
   }
  
 +
  /* Editor avançado para utilizadores autenticados */
 
   if (mw.config.get("wgUserName")) {
 
   if (mw.config.get("wgUserName")) {
 
     mw.loader.load(urlStart + "Redactor" + urlEnd);
 
     mw.loader.load(urlStart + "Redactor" + urlEnd);
 
   }
 
   }
  
 +
  /* Botão topo & cookies */
 
   addButtonTop();
 
   addButtonTop();
 
   buttonTop();
 
   buttonTop();
 
   cookies();
 
   cookies();
 
})();
 
})();
JS.txt
 
8 KB
 

Revisão das 15h19min de 15 de novembro de 2025

/* Código Javascript colocado aqui será carregado para todos os utilizadores em cada carregamento de página */

/* =====================================
   FUNÇÕES AUXILIARES
   ===================================== */

/* Tabber helpers */
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() {
  var favicon = document.querySelector('link[rel="shortcut icon"]');
  if (favicon) {
    favicon.href = "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
  }
}

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

  if (!switchButton || !content) return;

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

/* Remove animação de loading e mostra conteúdo assim que estiver pronto */
function removeLoadingAnimation() {
  var loadingAnimation = document.getElementById("loading-animation");
  var showAfterLoading = document.getElementById("show-after-loading");

  if (loadingAnimation) {
    hideElement(loadingAnimation);
  }

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

/* BOTÃO VOLTAR AO TOPO */
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 && topButton !== 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 GF */
function cookies() {
  var req = new XMLHttpRequest();
  req.addEventListener("load", function () {
    if (this.status >= 200 && this.status < 300) {
      try {
        var data = JSON.parse(this.responseText);
        if (data && Object.prototype.hasOwnProperty.call(data, "version")) {
          var gdpr = document.createElement("script");
          gdpr.src =
            "https://s3-static.geo.gfsrv.net/cookiebanner/" +
            data.version +
            "/cookie.min.js";
          document.head.appendChild(gdpr);
        }
      } catch (e) {
        // falha a ler JSON, ignora
      }
    }
  });
  req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
  req.send();
}

/* =====================================
   SLIDESHOW
   ===================================== */

/* Slideshow con pulsanti avanti e indietro in javascript */
(function () {
  function Slideshow(element) {
    this.el = document.querySelector(element);
    if (!this.el) return;
    this.init();
  }

  Slideshow.prototype = {
    init: function () {
      this.wrapper = this.el.querySelector(".slider-wrapper_wiki");
      this.slides = this.el.querySelectorAll(".slide_wiki");
      this.previous = this.el.querySelector(".slider-previous");
      this.next = this.el.querySelector(".slider-next");
      this.index = 0;
      this.total = this.slides.length;

      if (!this.slides.length || !this.next || !this.previous) return;

      this.actions();
      this._slideTo(this.index);
    },
    _slideTo: function (slide) {
      var currentSlide = this.slides[slide];
      if (!currentSlide) return;

      currentSlide.style.display = "block";

      for (var i = 0; i < this.slides.length; i++) {
        var s = this.slides[i];
        if (s !== currentSlide) {
          s.style.display = "none";
        }
      }
    },
    actions: function () {
      var self = this;

      this.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 < 0) self.index = 0;

          self._slideTo(self.index);
        },
        false
      );

      this.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 () {
    new Slideshow("#main-slider");
  });
})();

/* =====================================
   MODAIS (JQUERY)
   ===================================== */

$(".trigger").on("click", function () {
  var modal = $(this).data("modal");
  $(modal).toggle();
});

$(".modal").on("click", function (e) {
  var className = e.target.className;
  if (className === "modal" || className === "close-button") {
    $(this).closest(".modal").toggle();
  }
});

/* =======================================
   FUNÇÃO GLOBAL – corre ao carregar a página
   ======================================= */

(function () {
  fixInsecureFavicon();

  var urlStart = "/index.php?title=MediaWiki:Script/";
  var urlEnd = ".js&action=raw&ctype=text/javascript";
  var loadScripts = document.querySelectorAll("div[data-load-javascript]");
  var equipmentContainer = document.querySelectorAll(
    "div#mw-content-text .list-equip"
  );

  /* Lista de equipamentos */
  equipmentContainer.forEach(function (container) {
    changeEquipementDisplay(container);
  });

  /* Carrega scripts específicos dependendo da página */
  if (loadScripts.length) {
    var allowedScripts = {
      Tabber: true,
      Skills: true,
      Modal: true,
      Switch: true,
      Loot: true,
      Map: true,
      Filter: true,
      Calculator: true,
      Element: true,
      Pets: true,
      Colorblind: true
    };

    var scriptsToLoad = [];

    loadScripts.forEach(function (scriptElement) {
      var scriptName = scriptElement.dataset.loadJavascript;

      if (allowedScripts[scriptName]) {
        allowedScripts[scriptName] = false;
        scriptsToLoad.push(scriptName);
      }
    });

    if (scriptsToLoad.length) {
      var firstScriptName = scriptsToLoad[0];

      if (firstScriptName === "Element") {
        scriptsToLoad.shift();
        $.getScript(urlStart + firstScriptName + urlEnd, function () {
          if (typeof injectCustomElements === "function") {
            injectCustomElements();
          }
          loadNextScripts();
        });
      } else {
        loadNextScripts();
      }
    }

    function loadNextScripts() {
      scriptsToLoad.forEach(function (scriptName) {
        mw.loader.load(urlStart + scriptName + urlEnd);
      });

      removeLoadingAnimation();
    }
  }

  /* Editor avançado para utilizadores autenticados */
  if (mw.config.get("wgUserName")) {
    mw.loader.load(urlStart + "Redactor" + urlEnd);
  }

  /* Botão topo & cookies */
  addButtonTop();
  buttonTop();
  cookies();
})();