MediaWiki:Common.js

De Wikidébats, l'encyclopédie des débats et des arguments « pour » et « contre »
Aller à la navigation Aller à la recherche

Note : après avoir enregistré 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 pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac).
  • Google Chrome : appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac).
  • Internet Explorer : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
  • Opera : allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité et sécurité → Effacer les données d’exploration → Images et fichiers en cache.
/* <Dynamic API call> */

$(function() {
	argumentMapContentCall();
	argumentMapColor();
	argumentContentCall();
	argumentContentDrop();
	moreContentCall();
	latestChangesCall();
	hoverContentCall();
	hoverContentLeave();
	fillEditSummaryForCheckbox();
	breadcrumbGeneration();
	breadcrumbMenu();
});

function loadContentFromTitle(titleElement) {
	titleElement.addClass('expanded');
	var page = titleElement.data('page');
	var template = titleElement.data('template');
	var argument = titleElement.data('argument');
	var type = titleElement.data('type');
	var level = titleElement.data('level');
	var root = titleElement.data('root');
	var path = titleElement.data('path');
	var warnings = titleElement.data('warnings');
	var wrapper = titleElement.parent().find('.argument-content-wrapper');
	var query = '{{' + template + '|page=' + page + '|argument=' + argument + '|type=' + type + '|niveau=' + level + '|racine=' + root + '|chemin=' + path + '|avertissements=' + warnings + '}}';
	new mw.Api().post({
		action: "parse",
		contentmodel: "wikitext",
		text: query
	}).done(function(data) {
		var text = data.parse.text['*'].replace(/<!--[\S\s]*?-->/gm, '');
		wrapper.append(text);
	});
}

function argumentContentCall() {
	$(document).on('click', '.argument-expandable-title:not(.expanded)', function() {
		loadContentFromTitle($(this));
		breadcrumbMenu(this);
		$(this).closest('.colonnes').addClass('inline');
		$(this).addClass('actualiser-ariane');
	});
}

function argumentMapContentCall() {
	$('.ns-0').on('click', '#Argument_map .titre-argument-carte', function() {
		var id = $(this).attr('id');
		id = id.slice(0, -4); // Supprime les 4 derniers caractères "_map"
		var titleElement = $('#' + CSS.escape(document.getElementById(id).querySelector("div").id));
		if (!$(titleElement).hasClass('expanded')) {
			loadContentFromTitle(titleElement);
		}
		breadcrumbMenu(titleElement);
		$(this).addClass('visited');
	});
}

function argumentMapColor(){
	$('.ns-0').on('click', '.liste-arguments .root-argument:not(.expanded)', function(){
		var id = $(this).attr('id');
		var element = $('#' + id + '_map');
		element.addClass('visited');
		
	});
}

function argumentContentDrop() {
	$(document).on('click', '.argument-expandable-title.expanded', function() {
		$(this).removeClass('expanded');
		var wrapper = $(this).parent().find('.argument-content-wrapper');
		wrapper.empty();
	});
}

function moreContentCall() {
	$(document).on('click', '.more-content-button', function() {
		$(this).hide();
		var page = $(this).data('page');
		var wrapper = $(this).parent().find('.more-content-wrapper');
		var query = '{{Contenu supplémentaire | page = ' + page + '}}';
		new mw.Api().post({
			action: "parse",
			contentmodel: "wikitext",
			text: query
		}).done(function(data) {
			var text = data.parse.text['*'].replace(/<!--[\S\s]*?-->/gm, '');
			wrapper.replaceWith('<div class="more-content-wrapper"><div class="more-content-drop show"></div>' + text + '</div>');
		});
	});
}

function latestChangesCall(){
	$('.ns-0').on('click', '.latest-changes-button.mw-ui-button', function(){
		$(this).hide();
		var page = $(this).data('page');
		var wrapper = $(this).parent().find('.latest-changes-wrapper');
		var query = '{{Dernières modifications | page = ' + page + '}}';
		new mw.Api().post({
			action: "parse",
			contentmodel: "wikitext",
			text: query
		}).done( function( data ) {
			var text = data.parse.text['*'].replace(/<!--[\S\s]*?-->/gm, '' );
			wrapper.replaceWith('<div class="latest-changes-wrapper"><div class="latest-changes-drop show"></div>' + text + '</div>');
		});
	});
}

function hoverContentCall(){
	$(document).on('mouseenter', '.hover-link', function(){
		var template = $(this).data('template');
		var parameter1 = $(this).data('parameter1');
		var parameter2 = $(this).data('parameter2');
		var parameter3 = $(this).data('parameter3');
		var position = $(this).data('position');
		var wrapper = $(this).find('.hover-content-wrapper');
		var query = '{{ ' + template + ' | ' + parameter1 + ' | ' + parameter2 + ' | ' + parameter3 + ' }}';
		new mw.Api().post({
			action: "parse",
			contentmodel: "wikitext",
			text: query
		}).done( function( data ) {
			var text = data.parse.text['*'].replace(/<!--[\S\s]*?-->/gm, '' );
			wrapper.replaceWith('<div class="hover-content-wrapper show ' + position + '">' + text + '</div>').show();
		});
	});
}

function hoverContentLeave(){
	$(document).on('mouseleave', '.hover-link', function(){
		$(this).find('.hover-content-wrapper').replaceWith('<div class="hover-content-wrapper"></div>');
	});
}

function breadcrumbGeneration(titleElement) {
	if (typeof titleElement === "undefined") {
		return;
	}

	// Obtenir la valeur de path depuis l'élément
	var path = $(titleElement).data('path');

	// Vérifier si path est défini et non vide
	if (path) {
		var page = $(titleElement).data('page');
		var query = '{{Fil d\'Ariane (menu) | chemin = ' + path + ' | page = ' + page + ' }}';

		// Chargement du fil d'Ariane
		new mw.Api().post({
			action: "parse",
			contentmodel: "wikitext",
			text: query
		}).done(function(data) {
			var text = data.parse.text['*'].replace(/<!--[\S\s]*?-->/gm, '');

			// Vérifier si l'élément #fil-ariane existe dans le DOM
			var filArianeExists = $('#fil-ariane').length > 0;

			// Si #fil-ariane existe, le remplacer
			if (filArianeExists) {
				$('#fil-ariane').replaceWith('<nav id="fil-ariane" class="zone-ariane" style="position: fixed; top: 0px; z-index: 999;">' + text + '</nav>').show();
			} else {
				var wrapper = $(document).find('.mediawiki');
				wrapper.before('<nav id="fil-ariane" class="zone-ariane" style="position: fixed; top: 0px; z-index: 999;">' + text + '</nav>').show();
			}

			// Pour positionner la croix de fermeture du fil en fonction de la largeur de l'écran
			var containerWidth = $('#fil-ariane').width();
			var rightValue = containerWidth - 34;
			$('#supprimer-ariane').css('left', rightValue + 'px');
		});
	} else {
		$('#fil-ariane').remove();
	}
}


function breadcrumbMenu(titleElement) {
	if (typeof titleElement === "undefined") {
		return;
	}

	breadcrumbGeneration(titleElement);
	
	var root = $(titleElement).closest('.root-argument')[0];
	var idRoot = root ? root.id : null;
	

	// Création d'un menu sticky
	function sticky() {
		// Pour masquer le fil d'Ariane si on remonte en tête de page
		var firstHeading = document.querySelector("#Pros");
		var memoPositionH1 = firstHeading.offsetTop;
		var filAriane = $('#fil-ariane');
		// position du curseur au scroll
		var posCurseur = this.pageYOffset;
		if (posCurseur <= memoPositionH1 + 50) {
			filAriane.hide();
		} else {
			filAriane.show();
		}
	}

	// Défilement jusqu'au titre avec un décalage égal au menu
	function scrollToTitle() {
		if ($(titleElement).hasClass('expanded')) {
			var titleTop = $(titleElement).offset().top - $("#fil-ariane").height() - 50;
			$("html, body").animate({ scrollTop: titleTop }, 50);
		}
	}

	// evenement
	window.addEventListener("scroll", sticky);
	setTimeout(scrollToTitle, 750);
}


/* </Dynamic API call> */


/**
	* For suppressing tooltips on interactive elements created with an API call
	* @example <>
	*/
 (function($,mw){
	removeTooltips();
 }(jQuery, mediaWiki));
 
 function removeTooltips(){
	$(document).on('mouseenter', '.hover-content-wrapper a', function(){
		$(this).removeAttr('title');	
	});
	$(document).on('mouseenter', '.hover-link a', function(){
		$(this).removeAttr('title');	
	});
 }

/**
 * fork de jQuery makeCollapsible 
 * 
 * script initial : http://www.mediawiki.org/wiki/RL/DM#jQuery.makeCollapsible
 * auteur initial : Krinkle <[email protected]>
 *
 * modifications : http://fr.wikipedia.org/wiki/Utilisateur:Lgd
 *
 * Dual license:
 * @license CC-BY 3.0 <http://creativecommons.org/licenses/by/3.0>
 * @license GPL2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 */

function newCollapsible( $content ) {

	return $content.find('.fr-collapsible').each(function() {
		// Define reused variables and functions
		var	$that = $(this),
			that = this,
			collapsetext = $(this).attr( 'data-collapsetext' ),
			expandtext = $(this).attr( 'data-expandtext' ),
			toggleElement = function( $collapsible, action, $defaultToggle, instantHide ) {
				// Validate parameters
				if ( !$collapsible.jquery ) { // $collapsible must be an instance of jQuery
					return;
				}
				if ( action != 'expand' && action != 'collapse' ) {
					// action must be string with 'expand' or 'collapse'
					return;
				}
				if ( typeof $defaultToggle == 'undefined' ) {
					$defaultToggle = null;
				}
				if ( $defaultToggle !== null && !($defaultToggle instanceof $) ) {
					// is optional (may be undefined), but if defined it must be an instance of jQuery.
					// If it's not, abort right away.
					// After this $defaultToggle is either null or a valid jQuery instance.
					return;
				}

				var $containers = null;

				if ( action == 'collapse' ) {

					// Collapse the element
					if ( $collapsible.is( 'table' ) &&	$collapsible.find('caption').length ) { // only table with caption
						// Hide all table rows of this table
						// Slide doens't work with tables, but fade does as of jQuery 1.1.3
						// http://stackoverflow.com/questions/467336#920480
						$containers = $collapsible.find( '>tbody>tr, >thead>tr' );
						if ( $defaultToggle ) {
							$containers.stop(true, true).fadeOut();
						} else {
							if ( instantHide ) {
								$containers.hide();
							} else {
								$containers.stop( true, true ).fadeOut();
							}
						}

					} else if ( !$collapsible.is( 'ul' ) && !$collapsible.is( 'ol' )	&& !$that.is( 'table' ) ) { // <div>, <p> etc. but not ul ol and tables without caption
						var $collapsibleContent = $collapsible.find( '> .fr-collapsible-content' );

						// If a collapsible-content is defined, collapse it
						if ( $collapsibleContent.length ) {
							if ( instantHide ) {
								$collapsibleContent.hide();
							} else {
								$collapsibleContent.slideUp();
							}

						// Otherwise assume this is a customcollapse with a remote toggle
						// .. and there is no collapsible-content because the entire element should be toggled
						} else {
							if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) {
								$collapsible.fadeOut();
							} else {
								$collapsible.slideUp();
							}
						}
					}

				} else {

					// Expand the element
					if ( $collapsible.is( 'table' ) &&	$collapsible.find('caption').length ) {
						$containers = $collapsible.find( '>tbody>tr, >thead>tr' );
						if ( $defaultToggle ) {
							$containers.stop(true, true).fadeIn();
						} else {
							$containers.stop(true, true).fadeIn();
						}

					} else if ( !$collapsible.is( 'ul' ) && !$collapsible.is( 'ol' )	&& !$that.is( 'table' ) ) { // <div>, <p> etc.but not ul ol and not tables without caption
						var $collapsibleContent = $collapsible.find( '> .fr-collapsible-content' );

						// If a collapsible-content is defined, collapse it
						if ( $collapsibleContent.length ) {
							$collapsibleContent.slideDown();

						// Otherwise assume this is a customcollapse with a remote toggle
						// .. and there is no collapsible-content because the entire element should be toggled
						} else {
							if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) {
								$collapsible.fadeIn();
							} else {
								$collapsible.slideDown();
							}
						}
					}
				}
			},
			// Toggles collapsible and togglelink class and updates text label
			toggleLinkDefault = function( that, e ) {
				var	$that = $(that),
					$collapsible = $that.closest( '.fr-collapsible.fr-made-collapsible' ).toggleClass( 'fr-collapsed' );
				e.preventDefault();
				e.stopPropagation();

				// It's expanded right now
				if ( !$that.hasClass( 'fr-collapsible-toggle-collapsed' ) ) {
					// Change link to "Show"
					$that.removeClass( 'fr-collapsible-toggle-expanded' ).addClass( 'fr-collapsible-toggle-collapsed' );
					if ( $that.find( '> a' ).length ) {
						$that.find( '> a' ).text( expandtext );
					} else {
						$that.text( expandtext );
					}
					// Collapse element
					toggleElement( $collapsible, 'collapse', $that );

				// It's collapsed right now
				} else {
					// Change link to "Hide"
					$that.removeClass( 'fr-collapsible-toggle-collapsed' ).addClass( 'fr-collapsible-toggle-expanded' );
					if ( $that.find( '> a' ).length ) {
						$that.find( '> a' ).text( collapsetext );
					} else {
						$that.text( collapsetext );
					}
					// Expand element
					toggleElement( $collapsible, 'expand', $that );
				}
				return;
			},
			// Toggles collapsible and togglelink class
			toggleLinkPremade = function( $that, e ) {
				var	$collapsible = $that.eq(0).closest( '.fr-collapsible.fr-made-collapsible' ).toggleClass( 'fr-collapsed' );
				if ( $(e.target).is('a') ) {
					return true;
				}
				e.preventDefault();
				e.stopPropagation();

				// It's expanded right now
				if ( !$that.hasClass( 'fr-collapsible-toggle-collapsed' ) ) {
					// Change toggle to collapsed
					$that.removeClass( 'fr-collapsible-toggle-expanded' ).addClass( 'fr-collapsible-toggle-collapsed' );
					// Collapse element
					toggleElement( $collapsible, 'collapse', $that );

				// It's collapsed right now
				} else {
					// Change toggle to expanded
					$that.removeClass( 'fr-collapsible-toggle-collapsed' ).addClass( 'fr-collapsible-toggle-expanded' );
					// Expand element
					toggleElement( $collapsible, 'expand', $that );
				}
				return;
			},
			// Toggles customcollapsible
			toggleLinkCustom = function( $that, e, $collapsible ) {
				// For the initial state call of customtogglers there is no event passed
				if (e) {
					e.preventDefault();
				e.stopPropagation();
				}
				// Get current state and toggle to the opposite
				var action = $collapsible.hasClass( 'fr-collapsed' ) ? 'expand' : 'collapse';
				$collapsible.toggleClass( 'fr-collapsed' );
				toggleElement( $collapsible, action, $that );

			};

		// Use custom text or default ?
		if( !collapsetext ) {
			//collapsetext = mw.message( 'collapsible-collapse' );
			collapsetext = 'masquer';
		}
		if ( !expandtext ) {
			//expandtext = mw.message( 'collapsible-expand' );
			expandtext = 'afficher';
		}

		// Create toggle link with a space around the brackets (&nbsp;[text]&nbsp;)
		var $toggleLink =
			$( '<a href="#"></a>' )
				.text( collapsetext )
				.wrap( '<span class="fr-collapsible-toggle"></span>' )
				.parent()
				.on( 'click.fr-collapse', function(e) {
					toggleLinkDefault( this, e );
				} );

		// Return if it has been enabled already.
		if ( $that.hasClass( 'fr-made-collapsible' ) ) {
			return;
		} else {
			$that.addClass( 'fr-made-collapsible' );
		}

		// Check if this element has a custom position for the toggle link
		// (ie. outside the container or deeper inside the tree)
		// Then: Locate the custom toggle link(s) and bind them
		if ( ( $that.attr( 'id' ) || '' ).indexOf( 'fr-customcollapsible-' ) === 0 ) {

			var thatId = $that.attr( 'id' ),
				$customTogglers = $content.find( '.' + thatId.replace( 'fr-customcollapsible', 'fr-customtoggle' ) );

			// Double check that there is actually a customtoggle link
			if ( $customTogglers.length ) {
				$customTogglers.on( 'click.fr-collapse', function( e ) {
					toggleLinkCustom( $(this), e, $that );
				} );
			}

			// Initial state
			if ( $that.hasClass( 'fr-collapsed' ) ) {
				$that.removeClass( 'fr-collapsed' );
				toggleLinkCustom( $customTogglers, null, $that );
			}

		// If this is not a custom case, do the default:
		// Wrap the contents add the toggle link
		} else {

			// Elements are treated differently
			if ( $that.is( 'table' )	&&	$that.find('caption').length ) { // only table with caption
				// The toggle-link will be in the caption
				var	$caption = $that.find( 'caption' ),
					$toggle = $caption.find( '> .fr-collapsible-toggle' );

				// If theres no toggle link, add it to the caption
				if ( !$toggle.length ) {
					$caption.eq(-1).prepend( $toggleLink );
				} else {
					$toggleLink = $toggle.off( 'click.fr-collapse' ).on( 'click.fr-collapse', function( e ) {
						toggleLinkPremade( $toggle, e );
					} );
				}

			} else if ( !$that.is( 'ul' ) && !$that.is( 'ol' )	&& !$that.is( 'table' ) ) { // <div>, <p> etc.but not ol ul and not tables without caption

				// The toggle-link will be the first child of the element
				var $toggle = $that.find( '> .fr-collapsible-toggle' );

				// If a direct child .content-wrapper does not exists, create it
				if ( !$that.find( '> .fr-collapsible-content' ).length ) {
					$that.wrapInner( '<div class="fr-collapsible-content"></div>' );
				}

				// If theres no toggle link, add it
				if ( !$toggle.length ) {
					$that.prepend( $toggleLink );
				} else {
					$toggleLink = $toggle.off( 'click.fr-collapse' ).on( 'click.fr-collapse', function( e ) {
						toggleLinkPremade( $toggle, e );
					} );
				}
			}
		}

		// Initial state (only for those that are not custom)
		if ( $that.hasClass( 'fr-collapsed' ) && ( $that.attr( 'id' ) || '').indexOf( 'fr-customcollapsible-' ) !== 0 ) {
			$that.removeClass( 'fr-collapsed' );
			// The collapsible element could have multiple togglers
			// To toggle the initial state only click one of them (ie. the first one, eq(0) )
			// Else it would go like: hide,show,hide,show for each toggle link.
			toggleElement( $that, 'collapse', $toggleLink.eq(0), /* instantHide = */ true );
			$toggleLink.eq(0).click();
		}
	} );
};

function newCollapsibleKeyboard($content) {
	$content.find('.fr-collapsible-toggle, .fr-collapsible-toggle-keyboard').attr('tabindex',0).keypress(function(event){
		if ( event.which == 13 ) {
			$(this).click()
		}
	});
};

function newCollapsibleGroup($content) {
	$content.find('.fr-collapsible-group').each(function(){
		var $that = $(this);
		var text = 'Tout ouvrir';
		var $tooglelink = $('<a class="fr-collapsible-toggle fr-collapsible-toggle-collapsed fr-collapsible-group-toogle-all" href="#">Tout ouvrir</a>');
		$that.find('.fr-collapsible-group-toogle:first').append($tooglelink).click(function(event){
			if(text == 'Tout ouvrir') {
				text = 'Tout fermer';
				$that.find('.fr-collapsible-toggle-collapsed:not(".fr-collapsible-group-toogle-all")').click();
			} else {
				text = 'Tout ouvrir';
				$that.find('.fr-collapsible-toggle-expanded:not(".fr-collapsible-group-toogle-all")').click();
			}
			$tooglelink.text(text);
			return false;
		});
	});
};

mw.hook( 'wikipage.content' ).add( [
	newCollapsible,
	newCollapsibleKeyboard,
	newCollapsibleGroup
] );

/*\
* * REFERENCE TOOLTIPS
\*/
// See [[mw:Reference Tooltips]]
// Source https://en.wikipedia.org/wiki/MediaWiki:Gadget-ReferenceTooltips.js

( function () {

// enwiki settings
var REF_LINK_SELECTOR = '.reference, a[href^="#CITEREF"]',
		COMMENTED_TEXT_CLASS = 'rt-commentedText',
		COMMENTED_TEXT_SELECTOR = ( COMMENTED_TEXT_CLASS ? '.' + COMMENTED_TEXT_CLASS + ', ' : '') +
				'abbr[title]';

mw.messages.set( {
		'rt-enable-footer': 'Enable Reference Tooltips',
		'rt-settings-title': 'Reference Tooltips',
		'rt-save': 'Save',
		'rt-cancel': 'Cancel',
		'rt-enable': 'Enable',
		'rt-disable': 'Disable',
		'rt-activationMethod': 'Tooltip appears when',
		'rt-hovering': 'hovering',
		'rt-clicking': 'clicking',
		'rt-delay': 'Delay before the tooltip appears (in milliseconds)',
		'rt-tooltipsForComments': 'Show tooltips over <span title="Tooltip example" class="' + ( COMMENTED_TEXT_CLASS || 'rt-commentedText' ) + '" style="border-bottom: 1px dotted; cursor: help;">text with a dotted underline</span> in Reference Tooltips style (allows to see such tooltips on devices with no mouse support)',
		'rt-disabledNote': 'You can re-enable Reference Tooltips using a link in the footer of the page.',
		'rt-done': 'Done',
		'rt-enabled': 'Reference Tooltips are enabled'
} );

// "Global" variables
var SECONDS_IN_A_DAY = 60 * 60 * 24,
		CLASSES = {
				FADE_IN_DOWN: 'rt-fade-in-down',
				FADE_IN_UP: 'rt-fade-in-up',
				FADE_OUT_DOWN: 'rt-fade-out-down',
				FADE_OUT_UP: 'rt-fade-out-up'
		},
		IS_TOUCHSCREEN = 'ontouchstart' in document.documentElement,
		// Quite a rough check for mobile browsers, a mix of what is advised at
		// https://stackoverflow.com/a/24600597 (sends to
		// https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent)
		// and https://stackoverflow.com/a/14301832
		IS_MOBILE = /Mobi|Android/i.test( navigator.userAgent ) ||
				typeof window.orientation !== 'undefined',
		CLIENT_NAME = $.client.profile().name,
		enabled, delay, activatedByClick, tooltipsForComments, cursorWaitCss,
		windowManager,
		$body = $( document.body ),
		$window = $( window );

function rt( $content ) {
	   

		var teSelector,
				settingsDialogOpening = false;


		function enableRt() {
				enabled = true;
				$( '.rt-enableItem' ).remove();
				rt( $content );
				mw.notify( mw.msg( 'rt-enabled' ) );
		}

		function disableRt() {
				$content.find( teSelector ).removeClass( 'rt-commentedText' ).off( '.rt' );
				$body.off( '.rt' );
				$window.off( '.rt' );
		}

		function addEnableLink() {
				// #footer-places – Vector
				// #f-list – Timeless, Monobook, Modern
				// parent of #footer li – Cologne Blue
				var $footer = $( '#footer-places, #f-list' );
				if ( !$footer.length ) {
						$footer = $( '#footer li' ).parent();
				}
				$footer.append(
						$( '<li>' )
								.addClass( 'rt-enableItem' )
								.append(
										$( '<a>' )
												.text( mw.msg( 'rt-enable-footer' ) )
												.attr( 'href', 'javascript:' )
												.click( function ( e ) {
														e.preventDefault();
														enableRt();
												} )
						)
				);
		}

		function TooltippedElement( $element ) {
				var tooltip,
						events,
						te = this;

				function onStartEvent( e ) {
						var showRefArgs;

						if ( activatedByClick && te.type !== 'commentedText' && e.type !== 'contextmenu' ) {
								e.preventDefault();
						}
						if ( !te.noRef ) {
								showRefArgs = [ $( this ) ];
								if ( te.type !== 'supRef' ) {
										showRefArgs.push( e.pageX, e.pageY );
								}
								te.showRef.apply( te, showRefArgs );
						}
				}

				function onEndEvent() {
						if ( !te.noRef ) {
								te.hideRef();
						}
				}

				if ( !$element ) {
						return;
				}

				// TooltippedElement.$element and TooltippedElement.$originalElement will be different when
				// the first is changed after its cloned version is hovered in a tooltip
				this.$element = $element;
				this.$originalElement = $element;
				if ( this.$element.is( REF_LINK_SELECTOR ) ) {
						if ( this.$element.prop( 'tagName' ) === 'SUP' ) {
								this.type = 'supRef';
						} else {
								this.type = 'harvardRef';
						}
				} else {
						this.type = 'commentedText';
						this.comment = this.$element.attr( 'title' );
						if ( !this.comment ) {
								return;
						}
						this.$element.addClass('rt-commentedText');
				}
				
				events = {
						'mouseenter.rt': onStartEvent,
						'mouseleave.rt': onEndEvent
				};

				this.$element.on( events );

				this.hideRef = function ( immediately ) {
						clearTimeout( te.showTimer );

						if ( this.type === 'commentedText' ) {
								this.$element.attr( 'title', this.comment );
						}

						if ( this.tooltip && this.tooltip.isPresent ) {
								if ( activatedByClick || immediately ) {
										this.tooltip.hide();
								} else {
										this.hideTimer = setTimeout( function () {
												te.tooltip.hide();
										}, 200 );
								}
						} else if ( this.$ref && this.$ref.hasClass( 'rt-target' ) ) {
								this.$ref.removeClass( 'rt-target' );
								if ( activatedByClick ) {
										$body.off( 'click.rt touchstart.rt', this.onBodyClick );
								}
						}
				};

				this.showRef = function ( $element, ePageX, ePageY ) {
						// Popups gadget
						if ( window.pg ) {
								disableRt();
								return;
						}
						
						if ( this.tooltip && !this.tooltip.$content.length ) {
								return;
						}

						var tooltipInitiallyPresent = this.tooltip && this.tooltip.isPresent;

						function reallyShow() {
								var viewportTop, refOffsetTop, teHref;

								if ( !te.$ref && !te.comment ) {
										teHref = te.type === 'supRef' ?
												te.$element.find( 'a' ).attr( 'href' ) :
												te.$element.attr( 'href' ); // harvardRef
										te.$ref = teHref &&
												$( '#' + $.escapeSelector( teHref.slice( 1 ) ) );
										if ( !te.$ref || !te.$ref.length || !te.$ref.text() ) {
												te.noRef = true;
												return;
										}
								}

								if ( !tooltipInitiallyPresent && !te.comment ) {
										viewportTop = $window.scrollTop();
										refOffsetTop = te.$ref.offset().top;
										if ( !activatedByClick &&
												viewportTop < refOffsetTop &&
												viewportTop + $window.height() > refOffsetTop + te.$ref.height() &&
												// There can be gadgets/scripts that make references horizontally scrollable.
												$window.width() > te.$ref.offset().left + te.$ref.width()
										) {
												// Highlight the reference itself
												te.$ref.addClass( 'rt-target' );
												return;
										}
								}

								if ( !te.tooltip ) {
										te.tooltip = new Tooltip( te );
										if ( !te.tooltip.$content.length ) {
												return;
										}
								}

								// If this tooltip is called from inside another tooltip. We can't define it
								// in the constructor since a ref can be cloned but have the same Tooltip object;
								// so, Tooltip.parent is a floating value.
								te.tooltip.parent = te.$element.closest( '.rt-tooltip' ).data( 'tooltip' );
								if ( te.tooltip.parent && te.tooltip.parent.disappearing ) {
										return;
								}

								te.tooltip.show();

								if ( tooltipInitiallyPresent ) {
										if ( te.tooltip.$element.hasClass( 'rt-tooltip-above' ) ) {
												te.tooltip.$element.addClass( CLASSES.FADE_IN_DOWN );
										} else {
												te.tooltip.$element.addClass( CLASSES.FADE_IN_UP );
										}
										return;
								}

								te.tooltip.calculatePosition( ePageX, ePageY );

								$window.on( 'resize.rt', te.onWindowResize );
						}

						// We redefine this.$element here because e.target can be a reference link inside
						// a reference tooltip, not a link that was initially assigned to this.$element
						this.$element = $element;

						if ( this.type === 'commentedText' ) {
								this.$element.attr( 'title', '' );
						}

			   
						this.showTimer = setTimeout( reallyShow, delay );

				};

				this.onBodyClick = function ( e ) {
						if ( !te.tooltip && !(te.$ref && te.$ref.hasClass( 'rt-target' )) ) {
								return;
						}

						var $current = $( e.target );

						function contextMatchesParameter( parameter ) {
								return this === parameter;
						}

						// The last condition is used to determine cases when a clicked tooltip is the current
						// element's tooltip or one of its descendants
						while ( $current.length &&
								( !$current.hasClass( 'rt-tooltip' ) ||
										!$current.data( 'tooltip' ) ||
										!$current.data( 'tooltip' ).upToTopParent(
												contextMatchesParameter, [ te.tooltip ],
												true
										)
								)
						) {
								$current = $current.parent();
						}
						if ( !$current.length ) {
								te.hideRef();
						}
				};

				this.onWindowResize = function () {
						te.tooltip.calculatePosition();
				};
		}

		function Tooltip( te ) {
				var tooltip = this;

				// This variable can change: one tooltip can be called from a harvard-style reference link
				// that is put into different tooltips
				this.te = te;

				switch ( this.te.type ) {
						case 'supRef':
								this.id = 'rt-' + this.te.$originalElement.attr( 'id' );
								this.$content = this.te.$ref
										.contents()
										.filter( function ( i ) {
												var $this = $( this );
												return this.nodeType === Node.TEXT_NODE ||
														!( $this.is( '.mw-cite-backlink' ) ||
																( i === 0 &&
																		// Template:Cnote, Template:Note
																		( $this.is( 'b' ) ||
																				// Template:Note_label
																				$this.is( 'a' ) &&
																				$this.attr( 'href' ).indexOf( '#ref' ) === 0
																		)
																)
														);
										} )
										.clone( true );
								break;
						case 'harvardRef':
								this.id = 'rt-' + this.te.$originalElement.closest( 'li' ).attr( 'id' );
								this.$content = this.te.$ref
										.clone( true )
										.removeAttr( 'id' );
								break;
						case 'commentedText':
								this.id = 'rt-' + String( Math.random() ).slice( 2 );
								this.$content = $( document.createTextNode( this.te.comment ) );
								break;
				}
				if ( !this.$content.length ) {
						return;
				}

				this.insideWindow = Boolean( this.te.$element.closest( '.oo-ui-window' ).length );

				this.$element = $( '<div>' )
						.addClass( 'rt-tooltip' )
						.attr( 'id', this.id )
						.attr( 'role', 'tooltip' )
						.data( 'tooltip', this );
				if ( this.insideWindow ) {
						this.$element.addClass( 'rt-tooltip-insideWindow' );
				}

				// We need the $content interlayer here in order for the settings icon to have correct
				// margins
				this.$content = this.$content
						.wrapAll( '<div>' )
						.parent()
						.addClass( 'rt-tooltipContent' )
						.addClass( 'mw-parser-output' )
						.appendTo( this.$element );

				if ( !activatedByClick ) {
						this.$element
								.mouseenter( function () {
										if ( !tooltip.disappearing ) {
												tooltip.upToTopParent( function () {
														this.show();
												} );
										}
								} )
								.mouseleave( function ( e ) {
										// https://stackoverflow.com/q/47649442 workaround. Relying on relatedTarget
										// alone has pitfalls: when alt-tabbing, relatedTarget is empty too
										if ( CLIENT_NAME !== 'chrome' ||
												( !e.originalEvent ||
														e.originalEvent.relatedTarget !== null ||
														!tooltip.clickedTime ||
														$.now() - tooltip.clickedTime > 50
												)
										) {
												tooltip.upToTopParent( function () {
														this.te.hideRef();
												} );
										}
								} )
								.click( function () {
										tooltip.clickedTime = $.now();
								} );
				}

				// Tooltip tail element is inside tooltip content element in order for the tooltip
				// not to disappear when the mouse is above the tail
				this.$tail = $( '<div>' )
						.addClass( 'rt-tooltipTail' )
						.prependTo( this.$element );

				this.disappearing = false;

				this.show = function () {
						this.disappearing = false;
						clearTimeout( this.te.hideTimer );
						clearTimeout( this.te.removeTimer );

						this.$element
								.removeClass( CLASSES.FADE_OUT_DOWN )
								.removeClass( CLASSES.FADE_OUT_UP );

						if ( !this.isPresent ) {
								$body.append( this.$element );
						}

						this.isPresent = true;
				};

				this.hide = function () {
						var tooltip = this;

						tooltip.disappearing = true;

						if ( tooltip.$element.hasClass( 'rt-tooltip-above' ) ) {
								tooltip.$element
										.removeClass( CLASSES.FADE_IN_DOWN )
										.addClass( CLASSES.FADE_OUT_UP );
						} else {
								tooltip.$element
										.removeClass( CLASSES.FADE_IN_UP )
										.addClass( CLASSES.FADE_OUT_DOWN );
						}

						tooltip.te.removeTimer = setTimeout( function () {
								if ( tooltip.isPresent ) {
										tooltip.$element.detach();
										
										tooltip.$tail.css( 'left', '' );

										if ( activatedByClick ) {
												$body.off( 'click.rt touchstart.rt', tooltip.te.onBodyClick );
										}
										$window.off( 'resize.rt', tooltip.te.onWindowResize );

										tooltip.isPresent = false;
								}
						}, 200 );
				};

				this.calculatePosition = function ( ePageX, ePageY ) {
						var teElement, teOffsets, teOffset, tooltipTailOffsetX, tooltipTailLeft,
								offsetYCorrection = 0;

						this.$tail.css( 'left', '' );

						teElement = this.te.$element.get( 0 );
						if ( ePageX !== undefined ) {
								tooltipTailOffsetX = ePageX;
								teOffsets = teElement.getClientRects &&
										teElement.getClientRects() ||
										teElement.getBoundingClientRect();
								if ( teOffsets.length > 1 ) {
										for (var i = teOffsets.length - 1; i >= 0; i--) {
												if ( ePageY >= Math.round( $window.scrollTop() + teOffsets[i].top ) &&
														ePageY <= Math.round(
																$window.scrollTop() + teOffsets[i].top + teOffsets[i].height
														)
												) {
														teOffset = teOffsets[i];
												}
										}
								}
						}

						if ( !teOffset ) {
								teOffset = teElement.getClientRects &&
										teElement.getClientRects()[0] ||
										teElement.getBoundingClientRect();
						}
						teOffset = {
								top: $window.scrollTop() + teOffset.top,
								left: $window.scrollLeft() + teOffset.left,
								width: teOffset.width,
								height: teOffset.height
						};
						if ( !tooltipTailOffsetX ) {
								tooltipTailOffsetX = ( teOffset.left * 2 + teOffset.width ) / 2;
						}
						if ( CLIENT_NAME === 'msie' && this.te.type === 'supRef' ) {
								offsetYCorrection = -Number(
										this.te.$element.parent().css( 'font-size' ).replace( 'px', '' )
								) / 2;
						}
						this.$element.css( {
								top: teOffset.top - this.$element.outerHeight() - 7 + offsetYCorrection,
								left: tooltipTailOffsetX - 20,
								right: ''
						} );

						// Is it squished against the right side of the page?
						if ( this.$element.offset().left + this.$element.outerWidth() > $window.width() - 1 ) {
								this.$element.css( {
										left: '',
										right: 0
								} );
								tooltipTailLeft = tooltipTailOffsetX - this.$element.offset().left - 5;
						}

						// Is a part of it above the top of the screen?
						if ( teOffset.top < this.$element.outerHeight() + $window.scrollTop() + 6 ) {
								this.$element
										.removeClass( 'rt-tooltip-above' )
										.addClass( 'rt-tooltip-below' )
										.addClass( CLASSES.FADE_IN_UP )
										.css( {
												top: teOffset.top + teOffset.height + 9 + offsetYCorrection
										} );
								if ( tooltipTailLeft ) {
										this.$tail.css( 'left', ( tooltipTailLeft + 12 ) + 'px' );
								}
						} else {
								this.$element
										.removeClass( 'rt-tooltip-below' )
										.addClass( 'rt-tooltip-above' )
										.addClass( CLASSES.FADE_IN_DOWN )
										// A fix for cases when a tooltip shown once is then wrongly positioned when it
										// is shown again after a window resize. We just repeat what is above.
										.css( {
												top: teOffset.top - this.$element.outerHeight() - 7 + offsetYCorrection
										} );
								if ( tooltipTailLeft ) {
										// 12 is the tail element width/height
										this.$tail.css( 'left', tooltipTailLeft + 'px' );
								}
						}
				};

				// Run some function for all the tooltips up to the top one in a tree. Its context will be
				// the tooltip, while its parameters may be passed to Tooltip.upToTopParent as an array
				// in the second parameter. If the third parameter passed to ToolTip.upToTopParent is true,
				// the execution stops when the function in question returns true for the first time,
				// and ToolTip.upToTopParent returns true as well.
				this.upToTopParent = function ( func, parameters, stopAtTrue ) {
						var returnValue,
								currentTooltip = this;

						do {
								returnValue = func.apply( currentTooltip, parameters );
								if ( stopAtTrue && returnValue ) {
										break;
								}
						} while ( currentTooltip = currentTooltip.parent );

						if ( stopAtTrue ) {
								return returnValue;
						}
				};
		}

		if ( !enabled ) {
				addEnableLink();
				return;
		}

		teSelector = REF_LINK_SELECTOR;
		if ( tooltipsForComments ) {
				teSelector += ', ' + COMMENTED_TEXT_SELECTOR;
		}
		$content.find( teSelector ).each( function () {
				new TooltippedElement( $( this ) );
		} );
}

enabled = true;
delay = 200;
// Since the mobile browser check is error-prone, adding IS_MOBILE condition here would probably
// leave cases where a user interacting with the browser using touches doesn't know how to call
// a tooltip in order to switch to activation by click. Some touch-supporting laptop users
// interacting by touch (though probably not the most popular use case) would not be happy too.
activatedByClick = IS_TOUCHSCREEN;
// Arguably we shouldn't convert native tooltips into gadget tooltips for devices that have
// mouse support, even if they have touchscreens (there are laptops with touchscreens).
// IS_TOUCHSCREEN check here is for reliability, since the mobile check is prone to false
// positives.
tooltipsForComments = IS_TOUCHSCREEN && IS_MOBILE;

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

}() );

function fillEditSummaryForCheckbox(object, section, addingMessage, removingMessage){
	if (typeof object === "undefined") {
		return;
	}
	var summary = $('input[name=wpSummary]').val();
	var checked = object.prop('checked');
	var bannerName = object.parent();
	var bannerName = $(bannerName).next();
	var bannerName = $(bannerName).text() + ' »';
	if (checked) {
		var actionDone = addingMessage + ' «';
	} else {
		var actionDone = removingMessage + ' «';
	}
	if (summary) {
		var condition = summary.substr(-3);
	if (condition == '*/ ') {
		var summary = summary + actionDone + bannerName;
		$('input[name=wpSummary]').val(summary);
	} else {
		var summary = summary + ' + ' + actionDone + bannerName;
		$('input[name=wpSummary]').val(summary);
	}
	} else {
		var summary = section + actionDone + bannerName;
		$('input[name=wpSummary]').val(summary);
	}
}

$('.mw-special-FormEdit').on('change', '.mw-special-FormEdit .zone-bandeaux .mandatoryField', function(){
	var summary = $('input[name=wpSummary]').val();
	var bannerName = $('select#input_2 option:selected').val() + ' »';
	var actionDone = ' Niveau d’avancement du débat changé à « ';
	if (summary) {
	var condition = summary.substr(-3);
	if (condition == '*/ ') {
		var summary = summary + actionDone + bannerName;
		$('input[name=wpSummary]').val(summary);
	} else {
		var summary = summary + ' +' + actionDone + bannerName;
		$('input[name=wpSummary]').val(summary);
	}
	} else {
		var summary = '/* Bandeaux d’avertissement */' + actionDone + bannerName;
		$('input[name=wpSummary]').val(summary);
	}
});

$('.mw-special-FormEdit').on('click', '.zone-bandeaux .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Bandeaux d’avertissement */ ', 'Ajout du bandeau', 'Retrait du bandeau');
});

$('.mw-special-FormEdit').on('click', '.zone-categories', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Catégories */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-resume', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Résumé de l’argument */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-resume .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Résumé de l’argument */', 'Ajout du bandeau d’avertissement', 'Retrait du bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-citations', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Citations */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-citations .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Citations */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-justifications', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Justifications */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-justifications .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Justifications */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-objections', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Objections */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-objections .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Objections */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-references', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Références */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-debat-detaille', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Débat détaillé */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-references .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Références */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-introduction', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Pour comprendre le débat */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-introduction .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Pour comprendre le débat */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-voir-Wikipedia', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Voir aussi sur Wikipédia */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-arguments-pour', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Arguments « pour » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-arguments-pour .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Arguments « pour » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-arguments-contre', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Arguments « contre » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-biblio-pour', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Bibliographie « pour » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-arguments-contre .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Arguments « contre » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-biblio-pour .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Bibliographie « pour » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-biblio-contre', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Bibliographie « contre » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-biblio-contre .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Bibliographie « contre » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-biblio-nini', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Bibliographie ni « pour » ni « contre » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-biblio-nini .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Bibliographie ni « pour » ni « contre » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-sito-pour', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Sitographie « pour » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-sito-pour .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Sitographie « pour » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-sito-contre', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Sitographie « contre » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-sito-contre .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Sitographie « contre » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-sito-nini', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Sitographie ni « pour » ni « contre » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-sito-nini .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Sitographie ni « pour » ni « contre » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-video-pour', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Vidéographie « pour » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-video-pour .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Vidéographie « pour » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-video-contre', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Vidéographie « contre » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-video-contre .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Vidéographie « contre » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-video-nini', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Vidéographie ni « pour » ni « contre » */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.zone-video-nini .oo-ui-inputWidget-input', function(){
	fillEditSummaryForCheckbox($(this), '/* Vidéographie ni « pour » ni « contre » */', 'Ajout d’un bandeau d’avertissement', 'Retrait d’un bandeau d’avertissement');
});

$('.mw-special-FormEdit').on('click', '.zone-debats-connexes', function(){
	var summary = $('input[name=wpSummary]').val();
	if (!summary) {
		$('input[name=wpSummary]').val('/* Débats connexes */ ');
	}
});

$('.mw-special-FormEdit').on('click', '.resume-modifications', function(){
	var summary = $('input[name=wpSummary]').val();
	var newSummary = $(this).text();
	if (summary) {
	var condition = summary.substr(-3);
	if (condition == '*/ ') {
			var summary = summary + newSummary;
			$('input[name=wpSummary]').val(summary);
	} else {
		var summary = summary + ' + ' + newSummary;
			$('input[name=wpSummary]').val(summary);
	}
	} else {
			$('input[name=wpSummary]').val(newSummary);
	}
});

function renameBar( $content ) {
	$( '.ns-0 #barre-renommer-titre' ).remove();
	var $span = $content.find( '#barre-renommer' );
	if ( $span.length ) {
		$span.attr( 'id', 'barre-renommer-titre' );
		$span.prepend( ' ' );
		$( '.firstHeading' ).append( $span );
	}
}
mw.hook( 'wikipage.content' ).add( renameBar );

function editSection() {
	var buttons = $('div.modifier-initial'); // Sélectionnez les div avec la classe modifier-section
	buttons.each(function() {
		if ( $( this ).length ) {
			$( this ).attr( 'class', 'modifier-section' );
			var section = $( this ).prev('h2.section-modifiable');
			section.append( $( this ) );
		}
	});
}
mw.hook('wikipage.content').add(editSection);

$(document).on('click', '#fil-ariane .lien-ariane', function(){
	var titleElement = $(this).data('anchor');
	var escapedTitleElement = CSS.escape(titleElement);
	escapedTitleElement = document.getElementById(titleElement);
	breadcrumbMenu(escapedTitleElement);
	var wrapper = $(escapedTitleElement).parent().find('.argument-content-wrapper');
	wrapper.empty();
	loadContentFromTitle($(escapedTitleElement));
});

$(document).on('click', '.supprimer-ariane', function(event){
	var nav = $(document).find('#fil-ariane');
	nav.replaceWith('').show();
});

$(document).on('click', '.remonter-argument', function(event) {
	event.preventDefault();
	var titleElement = $(this).find('a');
	var href = titleElement.attr('href');
	var anchorName = href.split('#')[1]; // On extrait le nom de l'ancre de l'attribut href
	var escapedTitleElement = document.getElementById(anchorName);
	var wrapper = $(escapedTitleElement).parent().find('.argument-content-wrapper');
	wrapper.empty();
	loadContentFromTitle($(escapedTitleElement));
	breadcrumbMenu(escapedTitleElement);
});

$(document).on('click', '#activer-pleinecran', function(event){
	var mwPanel = document.querySelector('#mw-panel');
	var leftPanel = document.querySelector('#left-navigation');
	var footer = document.querySelector('#footer');
	var mwBody = document.querySelector(".mw-body");
	mwPanel.style.display = 'none';
	leftPanel.style.marginLeft = '0em';
	footer.style.marginLeft = '0em';
	mwBody.style.marginLeft = "0em";
	document.querySelector('#activer-pleinecran').setAttribute('id', 'desactiver-pleinecran');
});

$(document).on('click', '#desactiver-pleinecran', function(event){
	var mwPanel = document.querySelector('#mw-panel');
	var leftPanel = document.querySelector('#left-navigation');
	var footer = document.querySelector('#footer');
	var mwBody = document.querySelector(".mw-body");
	mwPanel.style.display = 'block';
	leftPanel.style.marginLeft = '';
	footer.style.marginLeft = '12em';
	mwBody.style.marginLeft = '12em';
	document.querySelector('#desactiver-pleinecran').setAttribute('id', 'activer-pleinecran');
});

$(document).on('click', '.onglet-externe a', function(event) {
	event.preventDefault();
	var url = $(this).attr('href');
	window.open(url, '_blank');
});

$(document).on('click', '.remonter-fil', function(){
	event.preventDefault();
	$('#fil-ariane .argument-ariane').remove();
	var argumentMap = document.querySelector('#Argument_map');
	var titleTop = $(argumentMap).offset().top - $("#fil-ariane").height() - 40;
	$("html, body").animate({ scrollTop: titleTop }, 50);
});

$(document).ready(function() {
	// Copier le sommaire dans le menu latéral en supprimant les éléments toc-level-2
	var toc = $('#toc');
	var sidetoc = toc.clone().attr('id', 'sidetoc');
	sidetoc.find('.toclevel-2').remove();
	var panel = $('#mw-panel');
	panel.append(sidetoc);
	$('#sidetoc').hide();
	sidetoc.addClass('supprimer-ariane');
});

$(window).scroll(function() {
	var breadcrumb = $(document).find('#fil-ariane');
	var mwPanelElement = $('#mw-panel');
	var mwPanelOffset = mwPanelElement.offset().top + mwPanelElement.outerHeight();
	var scrollTop = $(window).scrollTop();

	if (mwPanelOffset < scrollTop) {
		if (breadcrumb.length) {
			var breadcrumbHeight = $('#fil-ariane').height();
			var sidetocOffset = breadcrumbHeight;
			$('#sidetoc').css('top', sidetocOffset + 'px');
			$('#sidetoc').show();
		} else {
			$('#sidetoc').show();
		}
	} else {
		$('#sidetoc').hide();
	}
});

$(document).ready(function() {
	var h2Elements = $('#bodyContent h2');
	var toctextElements = $('#sidetoc .toclevel-1 a .toctext');

	function updateActiveElement() {
		var activeElementIndex = -1;
		var mouseY = $(window).scrollTop() + $(window).height() / 2;

		h2Elements.each(function(index) {
			var currentH2 = $(this);
			var nextH2 = h2Elements.eq(index + 2);

			var currentH2Offset = currentH2.offset().top;
			var nextH2Offset = nextH2.length ? nextH2.offset().top : $(document).height();

			if (currentH2Offset <= mouseY && nextH2Offset > mouseY) {
				activeElementIndex = index;
				return false; // Sortir de la boucle each
			}
		});

		// Appliquer le style aux éléments du sommaire en fonction de l'élément actif
		toctextElements.removeClass('active');
		if (activeElementIndex !== -1) {
			toctextElements.eq(activeElementIndex).addClass('active');
		}
	}

	$(window).scroll(function() {
		updateActiveElement();
	});

	$(window).mousemove(function() {
		updateActiveElement();
	});
});

$(document).on('click', '.ns-3100 .bouton-argument-suivant', function() {
	$('html, body').animate({ scrollTop: 0 }, 'slow'); // Fait défiler en douceur
});

// Pour afficher le fil d'Ariane au survol d'un titre d'argument
$('.ns-0').ready(function() {
	var timer; // Variable pour stocker le délai
	var mouseEntered = false; // Variable pour suivre si la souris est entrée

	// Gérer l'événement lorsque la souris entre dans .mediawiki
	$('.liste-arguments').on('mouseenter', '.argument-expandable-title span', function() {
		var titleElement = $(this).closest('.argument-expandable-title');
		// Définir un délai de 500 ms
		timer = setTimeout(function() {
			if (mouseEntered) { // Vérifier si la souris est toujours entrée après le délai convenu
				breadcrumbGeneration(titleElement);
			}
		}, 500);
	});

	// Gérer l'événement lorsque la souris bouge dans .argument-expandable-title
	$('.liste-arguments').on('mousemove', '.argument-expandable-title span', function() {
		mouseEntered = true; // Marquer que la souris est entrée
	});

	// Gérer l'événement lorsque la souris quitte .argument-expandable-title
	$('.liste-arguments').on('mouseleave', '.argument-expandable-title span', function() {
		mouseEntered = false; // Réinitialiser la variable
		clearTimeout(timer); // Annuler le délai si la souris quitte après le délai convenu
	});
});

var timerBis; // Variable pour stocker le délai
var isHovered = false; // Indicateur pour suivre l'état du survol

$('.ns-0').on('mouseenter', '.liste-arguments .contenu-argument, .liste-arguments .NavHead span, .liste-arguments .bouton-ajouter span', function() {
	var titleElement = $(this).closest(".argument-content-wrapper").prev();

	// Mettre à jour l'indicateur de survol
	isHovered = true;

	// Effacer le délai précédent s'il existe
	clearTimeout(timerBis);

	// Définir un délai avant de modifier le fil d'Ariane
	timerBis = setTimeout(function() {
		if (isHovered && titleElement.length > 0) {
			breadcrumbGeneration(titleElement);
		}
	}, 1500);
}).on('mouseleave', '.liste-arguments .contenu-argument, .liste-arguments .NavHead span, .liste-arguments .bouton-ajouter span', function() {
	// Mettre à jour l'indicateur de survol et effacer le délai
	isHovered = false;
	clearTimeout(timerBis);
});

function moveSearchBar( $content ) {
	// Sélectionner l'élément #p-search
	var pSearchElement = document.getElementById('p-search');

	// Sélectionner l'élément #mw-page-base
	var mwPageBaseElement = document.getElementById('mw-page-base');

	// Vérifier si les deux éléments existent
	if (pSearchElement && mwPageBaseElement) {
		// Déplacer #p-search avant #mw-page-base
		mwPageBaseElement.parentNode.insertBefore(pSearchElement, mwPageBaseElement);
		// Ajouter display: block à #p-search
		pSearchElement.style.display = 'block';
	}
}
mw.hook( 'wikipage.content' ).add( moveSearchBar );