« MediaWiki:Common.js » : différence entre les versions
Page de l’interface de MediaWiki
Autres actions
{{MinecraftConnect}} |
Annulation des modifications 3831 de Hiob (discussion) Balise : Annulation |
||
| (3 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 13 : | Ligne 13 : | ||
} ); | } ); | ||
} ); | } ); | ||
/** | /** | ||
* | * MinecraftConnect - Boutons de copie d'adresse serveur Minecraft | ||
* Inspiré de l'extension PreToClip | |||
*/ | */ | ||
function | (function() { | ||
'use strict'; | |||
navigator.clipboard.writeText( | function initMinecraftButtons($content) { | ||
var | $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() { | setTimeout(function() { | ||
$button | |||
.text(originalText + ' 📋') | |||
.prop('disabled', false) | |||
.removeClass('mw-ui-constructive') | |||
.addClass('mw-ui-progressive'); | |||
}, 2000); | }, 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); | |||
}()); | |||
}) | |||
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);
}());