Difference between revisions of "MediaWiki:Common.js"

From Pokemorph MUSH Wiki
Jump to: navigation, search
(Created page with "Any JavaScript here will be loaded for all users on every page load.: function findAndToggle(_event) { var checked = this.classList.contains("settrue"); $("." + this....")
 
(Ability to invert toggles (to hide things when unchecked))
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
function findAndToggle(_event) {
 
function findAndToggle(_event) {
 +
  var toFind  = "." + this.getAttribute("data-findbyclass");
 +
  var toToggle = this.getAttribute("data-togglethisclass");
 
   var checked = this.classList.contains("settrue");
 
   var checked = this.classList.contains("settrue");
   $("." + this.getAttribute("data-findbyclass")).toggleClass(this.getAttribute("data-togglethisclass"), checked)
+
   checked = this.classList.contains("inverttoggle") ? !checked : checked;
 +
  console.log("findAndToggle on ", this, "[" + checked + "] attempting to find ", toFind, " and toggle ", toToggle);
 +
  $(toFind).toggleClass(toToggle, !checked)
 
   this.classList.toggle("settrue");
 
   this.classList.toggle("settrue");
 
   this.classList.toggle("setfalse");
 
   this.classList.toggle("setfalse");
Line 9: Line 13:
 
$( function() {
 
$( function() {
 
   $(".bindtoggle").on("click", findAndToggle)
 
   $(".bindtoggle").on("click", findAndToggle)
 +
  console.log("Loaded .bindtoggle, connected to ", $(".bindtoggle"));
 
})
 
})

Latest revision as of 09:42, 10 August 2019

/* Any JavaScript here will be loaded for all users on every page load. */
function findAndToggle(_event) {
  var toFind   = "." + this.getAttribute("data-findbyclass");
  var toToggle = this.getAttribute("data-togglethisclass");
  var checked = this.classList.contains("settrue");
  checked = this.classList.contains("inverttoggle") ? !checked : checked;
  console.log("findAndToggle on ", this, "[" + checked + "] attempting to find ", toFind, " and toggle ", toToggle);
  $(toFind).toggleClass(toToggle, !checked)
  this.classList.toggle("settrue");
  this.classList.toggle("setfalse");
}

$( function() {
  $(".bindtoggle").on("click", findAndToggle)
  console.log("Loaded .bindtoggle, connected to ", $(".bindtoggle"));
})