Registration has been disabled and the moderation extension has been turned off.
Contact an admin on Discord or EDF if you want an account. Also fuck bots.

MediaWiki:Common.js: Difference between revisions

From Encyclopedia Dramatica
Jump to navigation Jump to search
imported>MarioMario456
unfocus legacy collapse
imported>MarioMario456
No edit summary
Line 63: Line 63:
var collapsibleElement = document.getElementsByClassName(collapsible);
var collapsibleElement = document.getElementsByClassName(collapsible);
var allElements = document.getElementsByTagName("*");
var allElements = document.getElementsByTagName("*");
var collapsibleRegex = new RegExp("^co;(.+?);(.+?);(.+?);(" + collapsible + ")(;(.+?))?$");
var collapsibleToggle = document.querySelectorAll("[data-correspondingcontent=\"" + collapsible + "\"]");
var collapsibleToggle;
var toggleLink;
for (var i = 0; i < allElements.length; i++) {
if (collapsibleRegex.test(allElements[i].className)) {
collapsibleToggle = allElements[i];
toggleLink = collapsibleToggle.getElementsByTagName("a");
}
}
if (collapsibleElement[0].style.display == "none") {
if (collapsibleElement[0].style.display == "none") {
toggleLink[0].innerHTML = toggleLink[0].dataset.collapsetext;
collapsibleToggle[0].innerHTML = collapsibleToggle[0].dataset.collapsetext;
if (collapsibleElement[0].style.removeProperty)
if (collapsibleElement[0].style.removeProperty)
    collapsibleElement[0].style.removeProperty("display");
    collapsibleElement[0].style.removeProperty("display");
Line 80: Line 72:
}
}
else {
else {
toggleLink[0].innerHTML = toggleLink[0].dataset.expandtext;
collapsibleToggle[0].innerHTML = collapsibleToggle[0].dataset.expandtext;
collapsibleElement[0].style.display = "none";
collapsibleElement[0].style.display = "none";
}
}
Line 100: Line 92:
var collapsibleContent = document.getElementsByClassName(correspondingContent);
var collapsibleContent = document.getElementsByClassName(correspondingContent);
var toggleLink;
var toggleLink;
allElements[i].innerHTML = "<a href=\"javascript:legacyCollapse('" + correspondingContent + "')\" class=\"collapsibletoggle\" data-collapsetext=\"" + collapseText + "\" data-expandtext=\"" + expandText + "\" data-correspondingcontent=\"" + correspondingContent + "\"></a>";
toggleLink = allElements[i].getElementsByTagName("a");
if (defaultState == "0") {
if (defaultState == "0") {
allElements[i].innerHTML = "<a href=\"javascript:legacyCollapse('" + correspondingContent + "')\" data-collapsetext=\"" + collapseText + "\" data-expandtext=\"" + expandText + "\">" + expandText + "</a>";
toggleLink[0].innerHTML = collapsibleValues[2];
collapsibleContent[0].style.display = "none";
collapsibleContent[0].style.display = "none";
}
}
else {
else
allElements[i].innerHTML = "<a href=\"javascript:legacyCollapse('" + correspondingContent + "')\" data-collapsetext=\"" + collapseText + "\" data-expandtext=\"" + expandText + "\">" + collapseText + "</a>";
toggleLink[0].innerHTML = collapsibleValues[1];
}
toggleLink = allElements[i].getElementsByTagName("a");
if (toggleColor)
if (toggleColor)
toggleLink[0].style.color = toggleColor;
toggleLink[0].style.color = toggleColor;

Revision as of 18:08, 31 October 2021

/* Any JavaScript here will be loaded for all users on every page load. */

setInterval(function () {
  var elements = document.getElementsByClassName('blink');
  for (index = 0; index < elements.length; index++) {
    if (elements[index].style.visibility === 'visible') {
      elements[index].style.visibility = 'hidden';
    } else {
      elements[index].style.visibility = 'visible';
    }
  }
}, 1000);



/* Collapsible toggle */

$(document).ready(function() {
	$(".collapsibletoggletext").click(function() {
		$(this).parent().children(".collapsibletoggletext").removeClass("hiddentext");
		$(this).addClass("hiddentext");
	});
});

/* Cycle forwards or backwards through elements one at a time via click */

$(function(){
    $(".cyclesequence").find(".cyclesequencelinknext").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:first").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
       }
       else {
           $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").next(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
         }
    });
});

$(function(){
    $(".cyclesequence").find(".cyclesequencelinkprev").click(function(){
        if ($(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").length === 0) {
            $(this).closest(".cyclesequence").find(".cyclesequenceitem:last").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
       }
       else {
           $(this).closest(".cyclesequence").find(".cyclesequenceitem:visible").prev(".cyclesequenceitem").removeClass("hiddentext").siblings(".cyclesequenceitem").addClass("hiddentext");
         }
    });
});

/* Click link to show one or more items and hide other items */

$(document).ready(function() {
	$(".morphlink").click(function() {
		var correspondingContent = $(this).data("correspondingcontent");
		$("#" + correspondingContent).removeClass("hiddentext");
		$("#" + correspondingContent).siblings().filter($(".morphcontent")).addClass("hiddentext");
	});
});

/* Legacy collapse code. Being kept for backwards compatibility.
   Based on WhiteMystery's original script, but more simplified. */

function legacyCollapse(collapsible) {
	var collapsibleElement = document.getElementsByClassName(collapsible);
	var allElements = document.getElementsByTagName("*");
	var collapsibleToggle = document.querySelectorAll("[data-correspondingcontent=\"" + collapsible + "\"]");
	if (collapsibleElement[0].style.display == "none") {
		collapsibleToggle[0].innerHTML = collapsibleToggle[0].dataset.collapsetext;
		if (collapsibleElement[0].style.removeProperty)
		    collapsibleElement[0].style.removeProperty("display");
		else
			collapsibleElement[0].style.removeAttribute("display");
	}
	else {
		collapsibleToggle[0].innerHTML = collapsibleToggle[0].dataset.expandtext;
		collapsibleElement[0].style.display = "none";
	}
	document.activeElement.blur();
}

function legacyCollapsibles() {
	var allElements = document.getElementsByTagName("*");
	var collapsibleRegex = new RegExp("^co;(.+?);(.+?);(.+?);(.+?)(;(.+?))?$");
	for (var i = 0; i < allElements.length; i++) {
		if (collapsibleRegex.test(allElements[i].className)) {
			console.warn("One or more templates are using obsolete collapse code. Please convert said templates to the new format.");
			var collapsibleValues = collapsibleRegex.exec(allElements[i].className);
			var collapseText = collapsibleValues[1];
			var expandText = collapsibleValues[2];
			var defaultState = collapsibleValues[3];
			var correspondingContent = collapsibleValues[4];
			var toggleColor = collapsibleValues[6];
			var collapsibleContent = document.getElementsByClassName(correspondingContent);
			var toggleLink;
			allElements[i].innerHTML = "<a href=\"javascript:legacyCollapse('" + correspondingContent + "')\" class=\"collapsibletoggle\" data-collapsetext=\"" + collapseText + "\" data-expandtext=\"" + expandText + "\" data-correspondingcontent=\"" + correspondingContent + "\"></a>";
			toggleLink = allElements[i].getElementsByTagName("a");
			if (defaultState == "0") {
				toggleLink[0].innerHTML = collapsibleValues[2];
				collapsibleContent[0].style.display = "none";
			}
			else
				toggleLink[0].innerHTML = collapsibleValues[1];
			if (toggleColor)
				toggleLink[0].style.color = toggleColor;
		}
	}
}

$(document).ready(legacyCollapsibles);