MediaWiki:Common.js: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
m (Disabling the main page css load, to test an updated Fonts.js)
m (Moved Toggle.js to a Gadget (https://zelda.gamepedia.com/MediaWiki:Gadget-Toggle.js))
Line 9: Line 9:


// 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.  
mw.loader.load( '/index.php?title=MediaWiki:Toggle.js&action=raw&ctype=text/javascript' );
mw.loader.load( '/index.php?title=MediaWiki:Fonts.js&action=raw&ctype=text/javascript' );
mw.loader.load( '/index.php?title=MediaWiki:Fonts.js&action=raw&ctype=text/javascript' );
//if (pageName === 'Main_Page') mw.loader.load( 'https://fonts.googleapis.com/css?family=Bowlby+One%7COpen+Sans:400,400i,700,700i', 'text/css' );
//if (pageName === 'Main_Page') mw.loader.load( 'https://fonts.googleapis.com/css?family=Bowlby+One%7COpen+Sans:400,400i,700,700i', 'text/css' );

Revision as of 03:41, 5 July 2017

// --------------------------------------------------------
// Variables
// --------------------------------------------------------
var action             = mw.config.get("wgAction"),
    pageName           = mw.config.get("wgPageName"),
    server             = mw.config.get("wgServer"),
    groups             = mw.config.get("wgUserGroups"),
    canonicalNamespace = mw.config.get("wgCanonicalNamespace");

// Any JavaScript here will be loaded for all users on every page load. 
mw.loader.load( '/index.php?title=MediaWiki:Fonts.js&action=raw&ctype=text/javascript' );
//if (pageName === 'Main_Page') mw.loader.load( 'https://fonts.googleapis.com/css?family=Bowlby+One%7COpen+Sans:400,400i,700,700i', 'text/css' );

// --------------------------------------------------------
// Rights
// Sets a variable "rights" which will return "false" if the 
// currently logged in user is a bureaucrat, administrator, or autoconfirmed user. It will return true otherwise.
// it also defines variables which may be used elsewhere in scripts.
// --------------------------------------------------------

if (groups){
	groupsString = groups.toString();
	var rights_isAuto    = (groupsString.indexOf('autoconfirmed') != -1);
	var rights_isAdmin   = (groupsString.indexOf('sysop')         != -1);
	var rights_isCrat    = (groupsString.indexOf('bureaucrat')    != -1);
	var rights_isRetired = (groupsString.indexOf('retired')       != -1);
	var rights = true;
} else {
	var rights = false;
}

// --------------------------------------------------------
// Special:MovePage
// Uncheck "Leave a redirect behind" if moving a file
// --------------------------------------------------------
$(function() {
	var isMovingFile = pageName.startsWith("Special:MovePage/File");
	if(isMovingFile) {
		var leaveRedirectCheckbox = $("input[name=wpLeaveRedirect]")[0];
		leaveRedirectCheckbox.checked = false;
	}
});

// --------------------------------------------------------
// Special:ExpandTemplates
// Check "Suppress <nowiki> tags in result" when using ExpandTemplates
// --------------------------------------------------------
$(function() {
	if (pageName == "Special:ExpandTemplates") {
		document.getElementById( 'removenowiki' ).checked = true;
	}
});

// --------------------------------------------------------
// ForcePreviewLite
// A modified version of http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Force_edit_summary_alternative
// NOTE: This is not a completed script, only a test of possible options for future addition. Implementation of this script would be done by combining the code of "function forceSummary()" into "function forcePreview()" at http://www.mediawiki.org/wiki/Manual:Force_preview
 // --------------------------------------------------------

function addForceSummary() {
	if(!/&action=edit/.test(window.location.href) && !/&action=submit/.test(window.location.href)) return;
	if(/&section=new/.test(window.location.href)) return;
	if(!document.forms.editform) return;
	document.forms.editform.wpSave.onclick = forceSummary;
}
 
function forceSummary() {
	flashcolour(7);
	document.forms.editform.wpSave.onclick = "";
	return false;
}
 
var flashcolour_timer;
function flashcolour(count) {
	if (count%2 == 1)
		document.getElementById("wpPreview").style.backgroundColor = "silver";
	else
		document.getElementById("wpPreview").style.backgroundColor = "yellow";
	
	if (flashcolour_timer !== null) {
		clearTimeout(flashcolour_timer);
		flashcolour_timer = null;
	}
	
	if (count > 0)
		flashcolour_timer = window.setTimeout("flashcolour(" + (count-1) + ")",350);
}
 
if (action != "submit" && rights === false) {
	$(document).ready(addForceSummary);
}

// --------------------------------------------------
// CrazyEgg Tracking
// --------------------------------------------------
setTimeout(function(){
	var a=document.createElement("script"),
	    b=document.getElementsByTagName("script")[0];
	a.src=document.location.protocol+"//script.crazyegg.com/pages/scripts/0011/8371.js?"+Math.floor(new Date().getTime()/3600000);
	a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}
, 1);

// --------------------------------------------------
// Temporary upload-related things
// --------------------------------------------------

//Add the html5 'required' attribute to the Source field on Special:Upload
if (pageName === "Special:Upload") {
	$(function() {
		$("#mw-input-source").prop('required',true);
		$("label[for=mw-input-source]").html('Source ('+'<a href="/Help:Upload#Source" target="_blank" title="Help:Upload">'+'help'+'</a>'+')');
	});
}

// --------------------------------------------------
// Restyle the Purge tab from the current "Refresh"
// --------------------------------------------------

$(document).ready(function(){
	$("#ca-purge a").attr("title","Purge the server cache of this page [alt-shift-0]").attr("accesskey","0").text("Purge");	
});