MediaWiki:Gadget-FlecheHaut.js
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) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./* {{Projet:JavaScript/Script|FlecheHaut}} */
/*
* Ajoute à chaque titre de section un lien de retour en haut de page
* Auteur : Marc Mongenet
* Mise à jour mediawiki 1.19 : Lgd
* Dernière révision : 25 septembre 2018
*/
mw.loader.using( 'user', function () {
$( function ( $ ) {
'use strict';
var options = {
text: '↑',
title: 'Haut de page',
animate: false,
animate_duration: 1000,
};
if ( typeof FlecheHaut_options !== 'undefined' ) {
Object.assign( options, FlecheHaut_options );
}
var callback = function ( e ) {
e.preventDefault();
if ( options.animate ) {
// c'est bien sur les deux éléments, refs https://stackoverflow.com/a/5580397
$( 'html, body' ).animate( { scrollTop: 0 }, options.animate_duration );
} else {
window.scrollTo( 0, 0 );
}
};
var $lien = $( '<a href="#" class="noprint">' )
.text( options.text)
.attr( 'title', options.title)
.css( {
'margin-left': '0.3em',
'user-select': 'none' // jQuery se charge d'ajouter un vendor prefix si nécessaire
} )
.click( callback );
// see: [[mw:Heading HTML changes]] and [[phab:T13555]]
// new markup
var $headingsNew = $( '#mw-content-text' ).find( '.mw-heading' );
// old markup, and manual <hN> tags
// alternatively, ':not(.mw-heading) > :is(h2, h3, h4, h5, h6)' could be used, but it is slower
var $headingsOldAndManual = $( '#mw-content-text' ).find( ':not(.mw-heading) > h2, :not(.mw-heading) > h3, :not(.mw-heading) > h4, :not(.mw-heading) > h5, :not(.mw-heading) > h6' );
// we also have to filter out the TOC heading <h2>... (all skins except Vector 2022 and Minerva)
$headingsOldAndManual = $headingsOldAndManual.not( '#mw-toc-heading' );
$headingsNew.add( $headingsOldAndManual ).append( $lien );
} );
} );