MediaWiki:Common.js: Difference between revisions
Undo revision 2976 by Theadamabrams (talk) Tag: Undo |
Updated collapsibles |
||
Line 2: | Line 2: | ||
/* Custom | /* Custom collapsibles for hints (cannot be nested): */ | ||
var coll = document.getElementsByClassName(" | var coll = document.getElementsByClassName("collapsible-hint"); | ||
var i; | var i; | ||
Line 12: | Line 12: | ||
if (content.style.maxHeight){ | if (content.style.maxHeight){ | ||
content.style.maxHeight = null; | content.style.maxHeight = null; | ||
content.classList.remove(" | content.classList.remove("collapsible-hint-content-visible"); | ||
} else { | } else { | ||
content.style.maxHeight = content.scrollHeight + "px"; | content.style.maxHeight = content.scrollHeight + "px"; | ||
content.classList.add(" | content.classList.add("collapsible-hint-content-visible"); | ||
} | } | ||
}); | }); | ||
} | } | ||
/* Custom collapsibles for social media threads */ | |||
$(document).ready(function() { | |||
$('.collapsible-dialogue-link').on('click', function() { | |||
//alert("Click!"); | |||
$parentElem = $(this).closest('.collapsible-dialogue'); | |||
if ($(this).text() == 'Collapse') { | |||
// hide | |||
$(this).text('Choose'); | |||
$parentElem.children('.collapsible-dialogue-content').slideUp(200); | |||
} else { | |||
// show | |||
$(this).text('Collapse'); | |||
$parentElem.children('.collapsible-dialogue-content').slideDown(200); | |||
$parentElem.siblings('.collapsible-dialogue').find('.collapsible-dialogue-content').slideUp(200); | |||
$parentElem.siblings('.collapsible-dialogue').find('.collapsible-dialogue-link').text('Choose'); | |||
} | |||
}); | |||
}); | |||
/* Custom hex strings */ | /* Custom hex strings */ | ||
Line 38: | Line 57: | ||
}); | }); | ||
} | } | ||
Revision as of 17:05, 2 December 2023
/* Any JavaScript here will be loaded for all users on every page load. */ /* Custom collapsibles for hints (cannot be nested): */ var coll = document.getElementsByClassName("collapsible-hint"); 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("collapsible-hint-content-visible"); } else { content.style.maxHeight = content.scrollHeight + "px"; content.classList.add("collapsible-hint-content-visible"); } }); } /* Custom collapsibles for social media threads */ $(document).ready(function() { $('.collapsible-dialogue-link').on('click', function() { //alert("Click!"); $parentElem = $(this).closest('.collapsible-dialogue'); if ($(this).text() == 'Collapse') { // hide $(this).text('Choose'); $parentElem.children('.collapsible-dialogue-content').slideUp(200); } else { // show $(this).text('Collapse'); $parentElem.children('.collapsible-dialogue-content').slideDown(200); $parentElem.siblings('.collapsible-dialogue').find('.collapsible-dialogue-content').slideUp(200); $parentElem.siblings('.collapsible-dialogue').find('.collapsible-dialogue-link').text('Choose'); } }); }); /* 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'; } }); }