Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

« MediaWiki:Common.js » : différence entre les versions

Page de l’interface de MediaWiki
Hiob (discussion | contributions)
Aucun résumé des modifications
Hiob (discussion | contributions)
Module:Règle
Ligne 153 : Ligne 153 :
/* === Modèle:Règle — copie d'ancre === */
/* === Modèle:Règle — copie d'ancre === */
mw.hook('wikipage.content').add(function ($content) {
mw.hook('wikipage.content').add(function ($content) {
     // Crée le toast s'il n'existe pas encore
 
     /* Crée le toast une seule fois */
     var $toast = $('#regle-toast');
     var $toast = $('#regle-toast');
     if ($toast.length === 0) {
     if ($toast.length === 0) {
Ligne 159 : Ligne 160 :
             .attr('id', 'regle-toast')
             .attr('id', 'regle-toast')
             .addClass('regle-toast')
             .addClass('regle-toast')
             .text('Lien copié !');
             .appendTo('body');
        $('body').append($toast);
     }
     }


     var toastTimer;
     var toastTimer;


     function showToast() {
     function showToast(message) {
         clearTimeout(toastTimer);
         clearTimeout(toastTimer);
         $toast.addClass('regle-toast--visible');
         $toast.text(message).addClass('regle-toast--visible');
         toastTimer = setTimeout(function () {
         toastTimer = setTimeout(function () {
             $toast.removeClass('regle-toast--visible');
             $toast.removeClass('regle-toast--visible');
Ligne 173 : Ligne 173 :
     }
     }


     $content.find('a.regle-lien').off('click.regle').on('click.regle', function (e) {
    /* Cible tous les liens internes dont le href commence par #r- */
     $content.find('a[href^="#r-"]').off('click.regle').on('click.regle', function (e) {
         e.preventDefault();
         e.preventDefault();
        var ancre = $(this).data('ancre');
        var url = window.location.origin
                + window.location.pathname
                + '#' + ancre;


         // Défilement vers l'ancre
        var ancre = $(this).attr('href').replace('#', '');
         var $cible = $('#' + ancre);
        var url  = window.location.origin
         if ($cible.length) {
                  + window.location.pathname
             $cible[0].scrollIntoView({ behavior: 'smooth', block: 'start' });
                  + '#' + ancre;
 
         /* Défilement vers l'ancre */
         var cible = document.getElementById(ancre);
         if (cible) {
             cible.scrollIntoView({ behavior: 'smooth', block: 'start' });
         }
         }


         // Copie dans le presse-papier
         /* Mise à jour de l'URL */
         if (navigator.clipboard) {
        history.replaceState(null, '', '#' + ancre);
             navigator.clipboard.writeText(url).then(showToast);
 
        /* Copie dans le presse-papier */
         if (navigator.clipboard && window.isSecureContext) {
             navigator.clipboard.writeText(url)
                .then(function () { showToast('🔗 Lien copié !'); })
                .catch(function () { showToast('❌ Copie impossible'); });
         } else {
         } else {
             // Fallback pour navigateurs anciens
             /* Fallback navigateurs anciens */
             var $tmp = $('<textarea>').val(url).appendTo('body');
             var $tmp = $('<textarea>')
                .val(url)
                .css({ position: 'fixed', opacity: 0 })
                .appendTo('body');
             $tmp[0].select();
             $tmp[0].select();
             document.execCommand('copy');
             try {
                document.execCommand('copy');
                showToast('🔗 Lien copié !');
            } catch (err) {
                showToast('❌ Copie impossible');
            }
             $tmp.remove();
             $tmp.remove();
            showToast();
         }
         }
    });


        // Met à jour l'URL sans recharger
        history.replaceState(null, '', '#' + ancre);
    });
});
});
/* === fin Modèle:Règle === */
/* === fin Modèle:Règle === */
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.