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 === */

Version du 22 février 2026 à 12:02

/* Tout JavaScript présent ici sera exécuté par tous les utilisateurs à chaque chargement de page. */
$( function () {
    $( '.citizen-search-trigger' ).on( 'click', function () {
        $( '#searchInput' ).focus();
    } );

    // Raccourci Ctrl+K (ou Cmd+K sur Mac)
    $( document ).on( 'keydown', function ( e ) {
        if ( ( e.ctrlKey || e.metaKey ) && e.key === 'k' ) {
            e.preventDefault();
            $( '#searchInput' ).focus();
        }
    } );
} );

/**
 * MinecraftConnect - Boutons de copie d'adresse serveur Minecraft
 * Inspiré de l'extension PreToClip
 */
(function() {
    'use strict';
    
    function initMinecraftButtons($content) {
        $content.find('.minecraft-connect-wrapper').each(function() {
            var $wrapper = $(this);
            
            // Éviter la double initialisation
            if ($wrapper.data('mc-initialized')) {
                return;
            }
            $wrapper.data('mc-initialized', true);
            
            var serverAddress = $wrapper.data('mc-server');
            var buttonText = $wrapper.data('mc-text');
            
            // Créer le bouton
            var $button = $('<button>')
                .addClass('mw-ui-button mw-ui-progressive minecraft-connect-btn')
                .attr('type', 'button')
                .attr('title', 'Cliquer pour copier : ' + serverAddress)
                .text(buttonText + ' 📋');
            
            // Remplacer le span par le bouton
            $wrapper.replaceWith($button);
            
            // Gestion du clic
            $button.on('click', function() {
                copyToClipboard(serverAddress, $button, buttonText);
            });
        });
    }
    
    function copyToClipboard(text, $button, originalText) {
        // Méthode moderne (Clipboard API)
        if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(text).then(
                function() {
                    showSuccess($button, originalText);
                },
                function() {
                    // Fallback si échec
                    fallbackCopy(text, $button, originalText);
                }
            );
        } else {
            // Fallback pour anciens navigateurs
            fallbackCopy(text, $button, originalText);
        }
    }
    
    function fallbackCopy(text, $button, originalText) {
        var $temp = $('<textarea>')
            .val(text)
            .css({
                position: 'fixed',
                top: 0,
                left: 0,
                width: '2em',
                height: '2em',
                padding: 0,
                border: 'none',
                outline: 'none',
                boxShadow: 'none',
                background: 'transparent'
            })
            .appendTo('body');
        
        $temp[0].select();
        $temp[0].setSelectionRange(0, 99999);
        
        try {
            var successful = document.execCommand('copy');
            if (successful) {
                showSuccess($button, originalText);
            } else {
                showError($button, originalText);
            }
        } catch (err) {
            showError($button, originalText);
        }
        
        $temp.remove();
    }
    
    function showSuccess($button, originalText) {
        mw.notify('Adresse copiée dans le presse-papier !', {
            type: 'success',
            autoHide: true,
            tag: 'minecraft-connect'
        });
        
        $button
            .text('✓ Copié !')
            .removeClass('mw-ui-progressive')
            .addClass('mw-ui-constructive')
            .prop('disabled', true);
        
        setTimeout(function() {
            $button
                .text(originalText + ' 📋')
                .prop('disabled', false)
                .removeClass('mw-ui-constructive')
                .addClass('mw-ui-progressive');
        }, 2000);
    }
    
    function showError($button, originalText) {
        mw.notify('Erreur lors de la copie', {
            type: 'error',
            autoHide: true,
            tag: 'minecraft-connect'
        });
        
        $button
            .text('✗ Erreur')
            .removeClass('mw-ui-progressive')
            .addClass('mw-ui-destructive');
        
        setTimeout(function() {
            $button
                .text(originalText + ' 📋')
                .removeClass('mw-ui-destructive')
                .addClass('mw-ui-progressive');
        }, 2000);
    }
    
    // Initialisation au chargement et pour VisualEditor
    mw.hook('wikipage.content').add(initMinecraftButtons);
    
}());


/* === Modèle:Règle — copie d'ancre === */
mw.hook('wikipage.content').add(function ($content) {

    /* Crée le toast une seule fois */
    var $toast = $('#regle-toast');
    if ($toast.length === 0) {
        $toast = $('<div>')
            .attr('id', 'regle-toast')
            .addClass('regle-toast')
            .appendTo('body');
    }

    var toastTimer;

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

    /* 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();

        var ancre = $(this).attr('href').replace('#', '');
        var url   = window.location.origin
                  + window.location.pathname
                  + '#' + ancre;

        /* Défilement vers l'ancre */
        var cible = document.getElementById(ancre);
        if (cible) {
            cible.scrollIntoView({ behavior: 'smooth', block: 'start' });
        }

        /* Mise à jour de l'URL */
        history.replaceState(null, '', '#' + ancre);

        /* 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 {
            /* Fallback navigateurs anciens */
            var $tmp = $('<textarea>')
                .val(url)
                .css({ position: 'fixed', opacity: 0 })
                .appendTo('body');
            $tmp[0].select();
            try {
                document.execCommand('copy');
                showToast('🔗 Lien copié !');
            } catch (err) {
                showToast('❌ Copie impossible');
            }
            $tmp.remove();
        }
    });

});
/* === 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.