Difference between revisions of "MediaWiki:Common.js"

(Trying to add a simple function/variable to see if that breaks anything)
Line 34: Line 34:
 
$( "span[title][data-title-override] a[title]" ).removeAttr( "title" );
 
$( "span[title][data-title-override] a[title]" ).removeAttr( "title" );
  
 
+
var $e = function (tag, text, classes, id) {
 +
var d = document.createElement(tag);
 +
if (classes !== undefined) {
 +
d.classList.add(...classes);
 +
}
 +
if(id) {
 +
d.id = id;
 +
}
 +
d.textContent = (text || "");
 +
return d;
 +
};
 
var $sv = function (variable, value) {
 
var $sv = function (variable, value) {
 
document.documentElement.style.setProperty(variable, value);
 
document.documentElement.style.setProperty(variable, value);
 
};
 
};

Revision as of 05:25, 28 November 2019

//
// TEXT SWAP-OUT ANIMATION
//
// Swappers have these two attributes.
var nexus = $( "input[data-swapper][data-swap-interval]" );
if(nexus.length) {
	// Check each swapper separately.
	nexus.each(function() {
		// Define variables inside here to hold stuff for the setInterval loop.
		var nex = $(this);
		var overlord = $( "#swap-override" );  // A checkbox to pause ALL swapping on a page
		var inverter = $( "#swap-inverter" );  // A checkbox to invert ALL animations (check to animate)
		var ident = nex.attr( "data-swapper" );     // Name
		var rep = nex.attr( "data-swap-interval" ); // Duration (in milliseconds)
		setInterval(function(){
			var x = nex.prop( "checked" );
			if(!overlord.prop( "checked" ) &&	(inverter.prop( "checked" ) ? x : !x) ) { // Pause when checked
				$( "[data-swap-nexus=" + ident + "]" ).each(function() {
					// Rotate out the text!
					var swap = $(this).attr( "data-swap" ).split( " " ),
					newText = swap.shift();
					swap.push( newText );
					$(this).text(newText).attr( "data-swap" , swap.join( " " ));
				});
			}
		}, rep);
	});
}


//
// OVERRIDE LINK TITLES (in certain circumstances)
//
$( "span[title][data-title-override] a[title]" ).removeAttr( "title" );

var $e = function (tag, text, classes, id) {
	var d = document.createElement(tag);
	if (classes !== undefined) {
		d.classList.add(...classes);
	}
	if(id) {
		d.id = id;
	}
	d.textContent = (text || "");
	return d;
};
var $sv = function (variable, value) {
	document.documentElement.style.setProperty(variable, value);
};