MediaWiki:Common.js

From Wynncraft Wiki
Jump to navigation Jump to search

CSS and Javascript changes must comply with the wiki design rules.


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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
/* Any JavaScript here will be loaded for all users on every page load. */

( function() {
'use strict';

/* Variables for interface text used throughout the script, for ease of translating */
var i18n = {
	// File upload
	defaultLicense: 'License'
};


/* Fires when DOM is ready */
$( function() {

/**
 * Set unlicensed as the default license on file pages
 *
 * That way the file will be categorised so someone can find a license for the file
 */
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
	var $license = $( '#wpLicense' );
	if ( $license.length ) {
		if ( $license.val() === '' ) {
			$license.val( i18n.defaultLicense );
		}
		
		mw.loader.using( 'mediawiki.special.upload', function() {
			$license.change();
		} );
	}
}

} );
/* End DOM ready */

/**
 * Deselect "Create redirect" checkbox on "Special:MovePage" automatically if moving a file or a talk page
 */
if ( mw.config.get( 'wgPageName' ).indexOf( 'Special:MovePage/' ) != -1
  && document.querySelector( '.oo-ui-inputWidget-input' )
  && ( document.querySelector ('.oo-ui-inputWidget-input' ).value % 2 == 1 || document.querySelector( '.oo-ui-inputWidget-input' ).value == 6 )
  && document.querySelector( 'input[name="wpLeaveRedirect"]' ) )
{
    document.querySelector( 'input[name="wpLeaveRedirect"]' ).removeAttribute( 'checked' );
}


}() );


// Avoid redirecting for links in categories
$( '.ns-14 .redirect-in-category .mw-redirect' ).each(function( i, e ){
    var link = $( e ).attr( 'href' ).replace( /^\//, '' );
    $( e ).attr( 'href', '/index.php?title=' + link + '&redirect=no' );
});


/* DRUID infoboxes */
$(function() {
	$('.druid-main-images-label').each(function() {
		$(this).off('click');
		$(this).click(function() {
			var $parent = $(this).closest('.druid-container');
			$parent.find('.druid-toggleable').each(function () {
				$(this).removeClass('focused');
			});
			var i = $(this).attr('data-druid');
			$parent.find('.druid-toggleable[data-druid=' + i + ']').addClass('focused');
		});
	});
});