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 talk:Common.js: Difference between revisions

From Encyclopedia Dramatica
Jump to navigation Jump to search
imported>Caku
imported>MarioMario456
 
(2 intermediate revisions by the same user not shown)
Line 280: Line 280:
{{rainbow|fucking never mind}}
{{rainbow|fucking never mind}}
[[User:Caku|HA HA PEE PEE POO POO]] ([[User talk:Caku|talk]]) 14:21, 24 June 2021 (EDT)
[[User:Caku|HA HA PEE PEE POO POO]] ([[User talk:Caku|talk]]) 14:21, 24 June 2021 (EDT)
== Collapsing Object bug ==
Sometimes, the toggle text won't change when you click the button. I tried as much as I could to attempt to fix this bug but I couldn't fix it. Here's the problematic code:
<pre>
/* Collapsible toggle */
$(document).ready(function() {
$(".collapsibletoggletext").click(function() {
$(this).parent().children(".collapsibletoggletext").toggleClass("hiddentext");
});
});
</pre>
<span style="font-size:16px">—[[User:MarioMario456|<span style="color:red;background:-webkit-linear-gradient(0deg,#f00,#c04);-webkit-background-clip:text;-webkit-text-fill-color:transparent">Mario</span>]][[User talk:MarioMario456|<span style="color:purple;background:-webkit-linear-gradient(0deg,#808,#40c);-webkit-background-clip:text;-webkit-text-fill-color:transparent">Mario</span>]][[Special:Contributions/MarioMario456|<span style="color:purple;background:-webkit-linear-gradient(0deg,#20d,#00f);-webkit-background-clip:text;-webkit-text-fill-color:transparent">456</span>]]</span> 22:52, 20 October 2021 (EDT)
:Finally figured out what's going on. "st/ed_global.js" already has a conflicting script. [[User:Kaizen|Our current server admin]] should delete it now, most of it is old, broken and bloated code. <span style="font-size:16px">—[[User:MarioMario456|<span style="color:red;background:-webkit-linear-gradient(0deg,#f00,#c04);-webkit-background-clip:text;-webkit-text-fill-color:transparent">Mario</span>]][[User talk:MarioMario456|<span style="color:purple;background:-webkit-linear-gradient(0deg,#808,#40c);-webkit-background-clip:text;-webkit-text-fill-color:transparent">Mario</span>]][[Special:Contributions/MarioMario456|<span style="color:purple;background:-webkit-linear-gradient(0deg,#20d,#00f);-webkit-background-clip:text;-webkit-text-fill-color:transparent">456</span>]]</span> 19:46, 28 October 2021 (EDT)

Latest revision as of 23:46, 28 October 2021

Old common.js

MediaWiki:Common.js of ED:

/* Hook that enables collapsing objects.
 * Added 7/13/2008 by WhiteMystery ([email protected]) */
 
addOnloadHook(createToggleLinks);
 
/* Function that creates collapsing objects and toggle links.
 * Added 7/13/2008 by WhiteMystery ([email protected]) */
 
function createToggleLinks() {
 
	var stateArray = new Array();
	var allObjects = document.getElementsByTagName('span');
	var rCollapsingObject = new RegExp("^co;(.+?);(.+?);(.+?);(.+?)(;(.+?))?$");
 
	for ( var i = 0; i < allObjects.length; i++ ) {
 
		if ( rCollapsingObject.test(allObjects[i].className) ) {
 
			var collapsingInformation = rCollapsingObject.exec(allObjects[i].className);
 
			var collapseText = collapsingInformation[1];
			var expandText = collapsingInformation[2];
			var initialState = collapsingInformation[3];
			var targetClass = collapsingInformation[4];
			var linkColor = collapsingInformation[6];
 
			var toggleLink = document.createElement("a");
 
			if ( initialState == "0" ) {
 
				toggleLink.appendChild(document.createTextNode(expandText));
				stateArray[targetClass] = "none";
			}
 
			else {
 
				toggleLink.appendChild(document.createTextNode(collapseText));
				stateArray[targetClass] = "inline";
			}
 
			toggleLink.setAttribute("href", "javascript:toggleCollapse('" + targetClass + "','" + collapseText + "','" + expandText + "')");
 
			if ( linkColor != undefined && linkColor != "undefined" && linkColor != "" )
				toggleLink.style.color = linkColor;
 
			allObjects[i].innerHTML = "";
			allObjects[i].appendChild(toggleLink);
		}
 
		else if ( allObjects[i].className == "morphMaster" ) {
 
			var spanID = allObjects[i].getAttribute("id");
			var targetID = spanID.substr(0, spanID.length - 6);
			var counter = 1;
 
			// Create forward and backward paging if the paging elements exist
			if ( returnObjById(targetID + "LinkNext") && returnObjById(targetID + "LinkPrev") && returnObjById(targetID + "Content1") ) {
 
				// Create the forward link
				var nextLink = document.createElement("a");	
				nextLink.appendChild(document.createTextNode(returnObjById(targetID + "LinkNext").innerHTML));
				nextLink.setAttribute("href", "javascript:morphForward('" + targetID + "')");
 
				returnObjById(targetID + "LinkNext").innerHTML = "";
				returnObjById(targetID + "LinkNext").appendChild(nextLink, 0);
 
				// Create the backward link
				var prevLink = document.createElement("a");	
				prevLink.appendChild(document.createTextNode(returnObjById(targetID + "LinkPrev").innerHTML));
				prevLink.setAttribute("href", "javascript:morphBackward('" + targetID + "')");
 
				returnObjById(targetID + "LinkPrev").innerHTML = "";
				returnObjById(targetID + "LinkPrev").appendChild(prevLink, 0);
 
				// Initialize content panes
				while ( returnObjById(targetID + "Content" + counter) ) {
 
					if ( counter == 1 )
						returnObjById(targetID + "Content" + counter).style.display = "inline";
					else
						returnObjById(targetID + "Content" + counter).style.display = "none";
 
					counter++;
				}	
			}
 
			counter = 1;
 
			// Whether or not there is paging, generate normal links				
			while ( returnObjById(targetID + "Link" + counter) && returnObjById(targetID + "Content" + counter) ) {
 
				var morphLink = document.createElement("a");
				morphLink.appendChild(document.createTextNode(returnObjById(targetID + "Link" + counter).innerHTML));
				morphLink.setAttribute("href", "javascript:performMorph('" + targetID + "','" + counter + "')");
 
				returnObjById(targetID + "Link" + counter).innerHTML = "";
				returnObjById(targetID + "Link" + counter).appendChild(morphLink, 0);
 
				// Initialize content panes
				if ( counter == 1 )
					returnObjById(targetID + "Content" + counter).style.display = "inline";
				else
					returnObjById(targetID + "Content" + counter).style.display = "none";
 
				counter++;
			}
 
			allObjects[i].innerHTML = "1";
			allObjects[i].style.display = "none";
		}
	}
 
	// Set state of appropriate objects
	allObjects = document.getElementsByTagName('*');
 
	for ( var i = 0; i < allObjects.length; i++ ) {
 
		if ( stateArray[allObjects[i].className] )
			allObjects[i].style.display = stateArray[allObjects[i].className];
	}
}
 
/* Function that toggles collapsing objects.
 * Added 7/13/2008 by WhiteMystery ([email protected]) */
 
function toggleCollapse(targetClass, collapseText, expandText) {
 
	var allObjects = document.getElementsByTagName('*');
	var rCollapsingObject = new RegExp("^co;(.+?);(.+?);(.+?);" + targetClass + "(;(.+?))?$");
 
	var linkType;
 
	for ( var i = 0; i < allObjects.length; i++ ) {
 
		if ( allObjects[i].className == targetClass ) {
 
			if ( allObjects[i].style.display == "none" ) {
 
				allObjects[i].style.display = "inline";
				linkType = "Collapse";	
			}
 
			else {
 
				allObjects[i].style.display = "none";
				linkType = "Expand";	
			}
		}	
	}
 
	allObjects = document.getElementsByTagName('span');
 
	for ( var i = 0; i < allObjects.length; i++ ) {
 
		if ( rCollapsingObject.test(allObjects[i].className) ) {
 
			var collapsingInformation = rCollapsingObject.exec(allObjects[i].className);
 
			var collapseText = collapsingInformation[1];
			var expandText = collapsingInformation[2];
			var linkColor = collapsingInformation[5];
 
			var toggleLink = document.createElement("a");
 
			if ( linkType == "Expand" )
 
				toggleLink.appendChild(document.createTextNode(expandText));
 
			else if ( linkType == "Collapse" )
 
				toggleLink.appendChild(document.createTextNode(collapseText));
 
			toggleLink.setAttribute("href", "javascript:toggleCollapse('" + targetClass + "','" + collapseText + "','" + expandText + "')");
 
			if ( linkColor != undefined && linkColor != "undefined" && linkColor != "" )
				toggleLink.style.color = linkColor;
 
			allObjects[i].innerHTML = "";
			allObjects[i].appendChild(toggleLink);
		}
	}
}
 
/* Functions that perform the morph operations.
 * Added 8/13/2008 by WhiteMystery ([email protected]) */
 
function performMorph(targetID, targetNumber) {
 
	var counter = 1;
 
	while ( returnObjById(targetID + "Content" + counter) ) {
 
		if ( counter == targetNumber )
			returnObjById(targetID + "Content" + counter).style.display = "block";
		else
			returnObjById(targetID + "Content" + counter).style.display = "none";
 
		counter++;
	}
 
	returnObjById(targetID + "Master").innerHTML = targetNumber;
}
 
function morphForward(targetID) {
 
	var nextPane = parseInt(returnObjById(targetID + "Master").innerHTML) + 1;
 
	if ( returnObjById(targetID + "Content" + nextPane) )
		performMorph(targetID, nextPane);
 
	else
		performMorph(targetID, "1");
}
 
function morphBackward(targetID) {
 
	var prevPane = parseInt(returnObjById(targetID + "Master").innerHTML) - 1;
 
	if ( prevPane > 0 )
		performMorph(targetID, prevPane);
 
	else {
 
		var maxIndex = 1;
 
		while ( returnObjById(targetID + "Content" + maxIndex) )
			maxIndex++;
 
		performMorph(targetID, maxIndex - 1);
	}
}
 
/* Function that returns an object by ID for various browsers
 * Taken from http://www.netlobo.com/javascript_get_element_id.html */
 
function returnObjById( id ) {
 
    if (document.getElementById) 
        var returnVar = document.getElementById(id);
 
    else if (document.all) 
        var returnVar = document.all[id];
 
    else if (document.layers) 
        var returnVar = document.layers[id];
 
    return returnVar; 
}

Mgs 07:12, 18 April 2011 (UTC)

Done. Thanks. --JuniusThaddeus 02:31, 23 May 2011 (UTC)
I reverted myself. The script is already located at ed_global.js. --JuniusThaddeus 13:32, 23 May 2011 (UTC)

Morphing Objects

I had a paki rewrite the morphing objects scirpt in vanilla js. I dont know if it works yet.

/* Click link to show one item and hide sibling items */

function morph(){
    var elements = document.getElementsByClassName("morphlink");
    for(let i = 0; i < elements.length; i++){
        elements[i].addEventListener("click",function(){
            var selectedElement = document.getElementById(this.dataset.correspondingcontent);
            selectedElement.classList.remove("hiddentext");
            var selectedSiblings = selectedElement.parentNode.children;
            for(let j = 0; j < selectedSiblings.length; j++){
                if(selectedSiblings[j].classList.contains("morphcontent")){
                    selectedSiblings[j].classList.add("hiddentext");
                }
            }
        });
    }
}
morph();

HA HA PEE PEE POO POO (talk) 14:21, 24 June 2021 (EDT)

Collapsing Object bug

Sometimes, the toggle text won't change when you click the button. I tried as much as I could to attempt to fix this bug but I couldn't fix it. Here's the problematic code:

/* Collapsible toggle */

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

MarioMario456 22:52, 20 October 2021 (EDT)

Finally figured out what's going on. "st/ed_global.js" already has a conflicting script. Our current server admin should delete it now, most of it is old, broken and bloated code. MarioMario456 19:46, 28 October 2021 (EDT)