User:Saftzie/minerva.js

ShoutWiki — express yourself and be heard!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
(function (mw, $) {
	'use strict';

	var
		global, common, skin,
		urlGlobal = mw.config.get('wgScriptPath') +
			'/index.php?title=User:Saftzie/global.js&action=raw&ctype=text/javascript';

	// short-circuit running this file, Wikia-style, usually for debugging
	if (/(?:\?|&)useuserjs=0(?:&|$)/.test(location.search)) {
		return;
	}

	// define load states for global/common/skin js
	(window.user = window.user || {}).state = user.state || {};
	// skin.js
	skin = user.state.skin = user.state.skin || {
		last: null,
//		defer: $.Deferred()
	};
	if (skin.last === 'skin') {
		return; // prevent repeat loading
	}
	skin.last = 'skin';
	// common.js
	common = user.state.common = user.state.common || {
		last: null,
		defer: $.Deferred()
	};
	// global.js
	global = user.state.global = user.state.global || {
		last: 'skin',
		defer: $.Deferred()
	};

	// enforce global -> common -> skin js serialization
	common.defer.done(function () {
		// whatever
	});

	// mobile doesn't load global.js
	// so test global.last
	if (global.last !== 'global') {
		$.ajax(urlGlobal, { // make mobile load global.js, anyway
			cache: true,
			crossDomain: true,
			dataType: 'script'
		});
	}
}(mediaWiki, jQuery));