« MediaWiki:Common.js » : différence entre les versions
Page de l’interface de MediaWiki
Autres actions
Aucun résumé des modifications |
Annulation des modifications 3831 de Hiob (discussion) Balise : Annulation |
||
| (2 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 14 : | Ligne 14 : | ||
} ); | } ); | ||
/** | |||
* MinecraftConnect - Boutons de copie d'adresse serveur Minecraft | |||
* Inspiré de l'extension PreToClip | |||
*/ | |||
(function() { | (function() { | ||
'use strict'; | 'use strict'; | ||
function initMinecraftButtons($content) { | |||
$content.find('.minecraft-connect- | $content.find('.minecraft-connect-wrapper').each(function() { | ||
var $ | var $wrapper = $(this); | ||
// Éviter la double initialisation | // Éviter la double initialisation | ||
if ($ | 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); | |||
copyToClipboard( | |||
}); | }); | ||
}); | }); | ||
} | } | ||
function copyToClipboard(text, $button) { | function copyToClipboard(text, $button, originalText) { | ||
// Méthode moderne (Clipboard API) | // Méthode moderne (Clipboard API) | ||
if (navigator.clipboard && | if (navigator.clipboard && navigator.clipboard.writeText) { | ||
navigator.clipboard.writeText(text).then(function() { | navigator.clipboard.writeText(text).then( | ||
function() { | |||
showSuccess($button, originalText); | |||
}, | |||
function() { | |||
// Fallback si échec | |||
fallbackCopy(text, $button, originalText); | |||
} | |||
); | |||
} else { | } else { | ||
// Fallback pour anciens navigateurs | |||
fallbackCopy(text, $button, originalText); | fallbackCopy(text, $button, originalText); | ||
} | } | ||
| Ligne 53 : | Ligne 71 : | ||
function fallbackCopy(text, $button, originalText) { | function fallbackCopy(text, $button, originalText) { | ||
var $temp = $('<textarea>') | var $temp = $('<textarea>') | ||
.val(text) | |||
.css({ | .css({ | ||
position: 'fixed', | position: 'fixed', | ||
| Ligne 63 : | Ligne 82 : | ||
outline: 'none', | outline: 'none', | ||
boxShadow: 'none', | boxShadow: 'none', | ||
background: 'transparent' | background: 'transparent' | ||
}) | }) | ||
.appendTo('body'); | |||
.appendTo('body') | |||
$temp[0].select(); | |||
$temp[0].setSelectionRange(0, 99999); | |||
try { | try { | ||
var successful = document.execCommand('copy'); | var successful = document.execCommand('copy'); | ||
if (successful) { | if (successful) { | ||
showSuccess($button, originalText | showSuccess($button, originalText); | ||
} else { | } else { | ||
showError($button, originalText); | showError($button, originalText); | ||
| Ligne 84 : | Ligne 103 : | ||
} | } | ||
function showSuccess($button, originalText | function showSuccess($button, originalText) { | ||
mw.notify('Adresse copiée dans le presse-papier !', { | |||
mw.notify('Adresse copiée | |||
type: 'success', | type: 'success', | ||
autoHide: true, | autoHide: true, | ||
tag: 'minecraft- | tag: 'minecraft-connect' | ||
}); | }); | ||
$button | $button | ||
.text('✓ Copié !') | .text('✓ Copié !') | ||
.removeClass('mw-ui-progressive') | .removeClass('mw-ui-progressive') | ||
.addClass('mw-ui-constructive'); | .addClass('mw-ui-constructive') | ||
.prop('disabled', true); | |||
setTimeout(function() { | setTimeout(function() { | ||
$button | $button | ||
.text(originalText) | .text(originalText + ' 📋') | ||
.prop('disabled', false) | .prop('disabled', false) | ||
.removeClass('mw-ui-constructive') | .removeClass('mw-ui-constructive') | ||
| Ligne 111 : | Ligne 128 : | ||
mw.notify('Erreur lors de la copie', { | mw.notify('Erreur lors de la copie', { | ||
type: 'error', | type: 'error', | ||
autoHide: true | autoHide: true, | ||
tag: 'minecraft-connect' | |||
}); | }); | ||
| Ligne 121 : | Ligne 139 : | ||
setTimeout(function() { | setTimeout(function() { | ||
$button | $button | ||
.text(originalText) | .text(originalText + ' 📋') | ||
.removeClass('mw-ui-destructive') | .removeClass('mw-ui-destructive') | ||
.addClass('mw-ui-progressive'); | .addClass('mw-ui-progressive'); | ||
}, 2000); | }, 2000); | ||
} | } | ||
// Initialisation au chargement et pour VisualEditor | |||
mw.hook('wikipage.content').add(initMinecraftButtons); | |||
}()); | }()); | ||
Dernière version du 11 novembre 2025 à 13:31
/* 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);
}());