Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/* jshint scripturl: true */
/* globals window, document */
/* globals mw, $ */
/* exported obtenir, addSpecialCharset, addSpecialCharsetHTML, addCustomButton */

/**
 * Le JavaScript placé ici affectera tous les utilisateurs du site mobile.
 *
 * ATTENTION : Avant de modifier cette page, veuillez tester vos changements avec votre propre
 * minerva.js. Une erreur sur cette page peut faire bugger le site entier (et gêner l'ensemble des
 * visiteurs), même plusieurs heures après la modification !
 *
 * <nowiki> /!\ Ne pas retirer cette balise
 */

// Encapsulation de tout le code dans une IIFE globale
// (le code doit être exécuté immédiatement, donc ne pas mettre ici de mw.loader.using(), etc.)
( function () {
	'use strict';

	/****************************************/
	/* Applications pour l'ensemble du site */
	/****************************************/

	/**
	 * Réécriture des titres
	 *
	 * Fonction utilisée par [[Modèle:Titre incorrect]]
	 *
	 * La fonction cherche un bandeau de la forme
	 * <div id="RealTitleBanner">
	 *   <span id="RealTitle">titre</span>
	 * </div>
	 *
	 * Un élément comportant id="DisableRealTitle" désactive la fonction
	 */
	function rewritePageTitle( $ ) {
		var $realTitle, titleHtml, $h1,
			$realTitleBanner = $( '#RealTitleBanner' );
		if ( $realTitleBanner.length && !$( '#DisableRealTitle' ).length ) {
			$realTitle = $( '#RealTitle' );
			$h1 = $( '.mw-first-heading' );
			if ( $realTitle.length && $h1.length ) {
				titleHtml = $realTitle.html();
				if ( titleHtml === '' ) {
					$h1.hide();
				} else {
					$h1.html( titleHtml );
					if ( mw.config.get( 'wgAction' ) === 'view' ) {
						// using a callback for replacement, to prevent interpreting "$" characters that realTitle might contain
						document.title = document.title.replace( /^.+( [—–-] Wikipédia)$/, function ( match, p1 ) {
							return $realTitle.text() + p1;
						} );
					}
				}
				$realTitleBanner.hide();
				$( '<p>' ).css( 'font-size', '80%' )
					.append( 'Titre à utiliser pour créer un lien interne : ', $( '<b>' ).text( mw.config.get( 'wgPageName' ).replaceAll( '_', ' ' ) ) )
					.insertAfter( $h1 );
			}
		}
	}
	$( rewritePageTitle );


	/**
	 * Script pour alterner entre plusieurs cartes de géolocalisation
	 */

	function GeoBox_Init( $content ) {
		$content.find( '.img_toggle' ).each( function ( i, Container ) {
			Container.id = 'img_toggle_' + i;
			var Boxes = $( Container ).find( '.geobox' );
			if ( Boxes.length < 2 ) {
				return;
			}
			var ToggleLinksDiv = document.createElement( 'ul' );
			ToggleLinksDiv.id = 'geoboxToggleLinks_' + i;
			Boxes.each( function ( a, ThisBox ) {
				ThisBox.id = 'geobox_' + i + '_' + a;
				// C'est possible qu'il n'y ait pas d'image (par exemple https://fr.m.wikipedia.org/wiki/%C3%8Ele-de-France?oldid=157053815#Situation)
				// Le problème est causé par un système de lazy-loading des images ("image-lazy-loaded")
				var ThisAlt;
				var img = ThisBox.getElementsByTagName( 'img' )[ 0 ];
				if ( img ) {
					ThisAlt = img.alt;
				} else {
					var placeholder = ThisBox.getElementsByClassName( 'lazy-image-placeholder' )[ 0 ];
					if ( placeholder ) {
						ThisAlt = placeholder.dataset.alt;
					}
				}
				if ( !ThisAlt ) {
					ThisAlt = 'erreur : description non trouvée';
				}
				var toggle = document.createElement( 'a' );
				toggle.id = 'geoboxToggle_' + i + '_' + a;
				toggle.textContent = ThisAlt;
				toggle.href = 'javascript:';
				toggle.onclick = function ( e ) {
					e.preventDefault();
					GeoBox_Toggle( this );
					// rustine rapide pour forcer le chargement de l'image, si c'était un "lazy-image-placeholder"
					$( window ).scroll();
				};
				var Li = document.createElement( 'li' );
				Li.appendChild( toggle );
				ToggleLinksDiv.appendChild( Li );
				if ( a === 0 ) {
					toggle.style.color = '#888';
					toggle.style.pointerEvents = 'none';
				} else {
					ThisBox.style.display = 'none';
				}
			} );
			Container.appendChild( ToggleLinksDiv );
		} );
	}

	function GeoBox_Toggle( link ) {
		var matches = link.id.match( /^geoboxToggle_(\d+)_(\d+)$/ );
		if ( !matches ) {
			return;
		}
		var ImgToggleIndex = matches[ 1 ];
		var GeoBoxIndex = matches[ 2 ];
		var ImageToggle = document.getElementById( 'img_toggle_' + ImgToggleIndex );
		var Links = document.getElementById( 'geoboxToggleLinks_' + ImgToggleIndex );
		var Geobox = document.getElementById( 'geobox_' + ImgToggleIndex + '_' + GeoBoxIndex );
		var Link = document.getElementById( 'geoboxToggle_' + ImgToggleIndex + '_' + GeoBoxIndex );
		if ( !ImageToggle || !Links || !Geobox || !Link ) {
			return;
		}
		$( ImageToggle ).find( '.geobox' ).each( function ( _, ThisgeoBox ) {
			if ( ThisgeoBox.id === Geobox.id ) {
				ThisgeoBox.style.display = '';
			} else {
				ThisgeoBox.style.display = 'none';
			}
		} );
		$( Links ).find( 'a' ).each( function ( _, thisToggleLink ) {
			if ( thisToggleLink.id === Link.id ) {
				thisToggleLink.style.color = '#888';
				thisToggleLink.style.pointerEvents = 'none';
			} else {
				thisToggleLink.style.color = '';
				thisToggleLink.style.pointerEvents = '';
			}
		} );
	}

	mw.hook( 'wikipage.content' ).add( GeoBox_Init );

	// Functions used commonly in global scripts.
	// @todo: it might be a good idea to make these use mw.notify users there is a problem
	window.obtenir = function () {};
	window.addSpecialCharset = function () {};
	window.addSpecialCharsetHTML = function () {};
	window.addCustomButton = function () {};

} )(); // Fermeture de la IIFE globale

/* </nowiki> */