MediaWiki:Common.js

De Guild Wars 2 Wiki
Aller à la navigation Aller à la recherche

Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
  • Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
  • Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
  • Opera : appuyez sur Ctrl + F5.
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
try {	
	/** additional scripts **/
	if ( mw.config.get('wgIsArticle') || window.location.href.indexOf( 'action=submit' ) > -1 || mw.config.get( 'wgNamespaceNumber' ) == -1 ) {
		mw.loader.load( '/index.php?title=MediaWiki:Masthead.js&action=raw&ctype=text/javascript' );
		mw.loader.load( '/index.php?title=MediaWiki:InitialSort.js&action=raw&ctype=text/javascript' );
		mw.loader.load( '/index.php?title=MediaWiki:Recherche_de_code_en_jeu.js&action=raw&ctype=text/javascript' );
		//mw.loader.load( '/index.php?title=MediaWiki:SnowStorm.js&action=raw&ctype=text/javascript' );
		
		if ( $('.repliable, .dépliable').length > 0 ) {
			mw.loader.load( '/index.php?title=MediaWiki:CollapsibleTables.js&action=raw&ctype=text/javascript' );
		}
		
		autoConvertUTC();
	}
	
	/**
	 * Force users to select a license option when uploading files (Wiki EN)
	 *   also allows manual entry in Summary for 'ArenaNet image' and 'User image' licenses
	 */
	if ( mw.config.get('wgNamespaceNumber') == -1 ) {
		$(function() {
			$('#mw-upload-form').submit(function(event) {
				var licenseValue = $('#wpLicense').val();
				var uploadDescription = $('#wpUploadDescription').val();
				if (licenseValue == '' && !uploadDescription.match(/(Licensing|ArenaNet image|User image)/i)) {
					alert('Merci de choisir une licence dans la liste déroulante.');
					console.log("test");
					event.preventDefault();
				}
			});
		});
	}

	/**** Code pour infobox **/
	$(function setentêteicône() {	  
		var top = 20;		 
		if ($(".entêteicône").outerHeight() > 25 && $(".entêteicône").outerHeight() < 50 ) {
		  top -= 5;
		} else if ($(".entêteicône").outerHeight() > 51) {
		  top -= 17;
		} else {
		  top += 0;
		}
		$(".entêteicône").css({"margin-top":top + "px", "margin-bottom":"26px"});
	});

	//correction des espaces blancs entre les listes à plusieurs colonnes
	
	$(function formatageDesListesEnColonnesGenereesParUneRequete(){
		var list = document.getElementsByClassName("column request");
		for(var i = 0; i < list.length; i++){
			var divlist = list[i].getElementsByTagName("DIV");
			for(var j = 0; j < divlist.length; j++){
				if(typeof divlist[j].style !== 'undefined'){
					if(divlist[j].style.cssFloat === "left"){
						divlist[j].style.cssFloat = "none";
						divlist[j].style.display = "inline-block";
						divlist[j].style.verticalAlign = "top";
					}
				}
			}
			var plist = list[i].getElementsByTagName("P");
			for(var j = plist.length-1; j >= 0; j--){
				if(plist[j].children.length === 1 && plist[j].children[0].tagName === "BR"){
					plist[j].remove();
				} else {
					var brlist = plist[j].getElementsByTagName("BR");
					for(var k = brlist.length-1; k >= 0; k--){
						if(typeof brlist[k].style !== 'undefined'){
							if(brlist[k].style.clear === "both"){
								brlist[k].remove();
							}
						}
					}
				}
			}
		}
	});

	//Ajout de la section 'Nous suivre' dans la sidebar
	function ModifySidebar( action, section, name, link, icon, iconsize ) {
		try {
			switch ( section ) {
				case 'languages':
					var target = 'p-lang';
					break;
				case 'toolbox':
					var target = 'p-tb';
					break;
				case 'navigation':
					var target = 'p-navigation';
					break;
				default:
					var target = 'p-' + section.replace(/ /g,"_");
					break;
			}

		if ( action == 'add' ) {
			var node = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var aNode = document.createElement( 'a' );
			var liNode = document.createElement( 'li' );

			if(typeof icon != 'undefined' && icon != null){
				var imgNode = document.createElement( 'img' );
				imgNode.setAttribute( 'src', icon );
				imgNode.style.maxHeight = iconsize;
				imgNode.style.maxWidth = iconsize;
				aNode.appendChild(imgNode);
			}
			
			if(name != null){
				aNode.appendChild( document.createTextNode("\u00A0") );
				aNode.appendChild( document.createTextNode( name ) );
			}
			aNode.setAttribute( 'href', link );
			liNode.appendChild( aNode );
			liNode.className = 'plainlinks';
			node.appendChild( liNode );
			
		}

		if ( action == 'remove' ) {
			var list = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var listelements = list.getElementsByTagName( 'li' );

			for ( var i = 0; i < listelements.length; i++ ) {
				if (
					listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
					listelements[i].getElementsByTagName( 'a' )[0].href == link
				)
				{
					list.removeChild( listelements[i] );
				}
			}
		}


		} catch( e ) {
			// let's just ignore what's happened
			return;
		}
	}

	$(function() {
		document.getElementById( "p-Nous_suivre" ).classList.remove("emptyPortlet");
		// adds discord link to Nous suivre
		ModifySidebar( 'add', 'Nous suivre', 'Discord', 'https://discord.gg/6pSGs89', 'https://wiki-fr.guildwars2.com/images/1/17/Discord-icon.svg', '18px' );
		// adds Twitter link to Nous suivre
		ModifySidebar( 'add', 'Nous suivre', 'Twitter', 'https://twitter.com/GW2WFR', 'https://wiki-fr.guildwars2.com/images/4/4f/Twitter-logo.svg', '18px' );
		// adds Youtube link to Nous suivre
		ModifySidebar( 'add', 'Nous suivre', 'YouTube', 'https://www.youtube.com/channel/UCXdAWL9yiAhXPLuhPb-Y_wQ', 'https://wiki-fr.guildwars2.com/images/3/32/Yt_icon_rgb.svg', '18px' );
	});
	
	/**
	 * Convert UTC time to local time. (see [[Template:UTC time]])
	 */
	function autoConvertUTC () {
		function pad (s) {  return (s < 10 ? '0' : '') + s; }
		var days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'];
		$('.utc-auto-convert').each(function(i,v){
			// Get UTC time using MediaWiki {{#time: U}} epoch format
			var utcseconds = v.getAttribute('data-time');
			if (utcseconds == 'error') {
				return;
			}
			var d = new Date(0);
			d.setUTCSeconds(utcseconds);
			var offset = (-1 * d.getTimezoneOffset() / 60);
			var offsetstring = '';
			if (offset > 0) { offsetstring = '+' + offset; }
			if (offset < 0) { offsetstring = offset; }
			
			// Default to showing the time only
			var datestring = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ' UTC' + offsetstring;
			var titlestring = pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ' UTC';
			
			// But check for different formatting in case there is a day of the week given inside the span
			if (!v.textContent.match(/^\d/)) {
				datestring  = days[d.getDay()] + ' ' + datestring;
				titlestring = days[d.getUTCDay()] + ' ' + titlestring;
			}
			
			// Show result
			$(v).html('<span style="cursor:help; border-bottom:1px dotted silver;" title="'+titlestring+'">'+datestring+'</span>');
		});
	}

} catch (err) {
	console.log(err);
}