MediaWiki:Common.js

From The Talos Principle Wiki
Revision as of 09:57, 20 November 2023 by Theadamabrams (talk | contribs) (Custom hex strings based on spoiler setup)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

/* Custom animated hints: */
  var coll = document.getElementsByClassName("custom-collapsible");
  var i;
  
  for (i = 0; i < coll.length; i++) {
    coll[i].addEventListener("click", function() {
      this.classList.toggle("active");
      var content = this.nextElementSibling;
      if (content.style.maxHeight){
        content.style.maxHeight = null;
        content.classList.remove("custom-collapsible-content-visible");
      } else {
        content.style.maxHeight = content.scrollHeight + "px";
        content.classList.add("custom-collapsible-content-visible");
      } 
    });
  }


/* Custom hex strings */
var hss = document.getElementsByClassName("hex-string");
var i;

for (i = 0; i < hss.length; i++) {
  hss[i].addEventListener("click", function() {
  if (this.dataset.state === 'hex') {
    // Switch to English
    this.querySelector('.hex-string-content').innerText = this.dataset.text;
    this.dataset.state = 'text';
  } else {
    // Switch to Hex
    this.querySelector('.hex-string-content').innerText = this.dataset.hex;
    this.dataset.state = 'hex';
  }
}