« MediaWiki:Common.js » : différence entre les versions
Page de l’interface de MediaWiki
Autres actions
key = ctrl+K |
Aucun résumé des modifications Balise : Révoqué |
||
| Ligne 13 : | Ligne 13 : | ||
} ); | } ); | ||
} ); | } ); | ||
/** | |||
* Intégration recherche page d'accueil avec Citizen | |||
*/ | |||
(function() { | |||
'use strict'; | |||
mw.hook('wikipage.content').add(function($content) { | |||
// Sélectionne le bouton de recherche custom | |||
const $customSearch = $content.find('.home-header__search'); | |||
if (!$customSearch.length) return; | |||
// Déclenche la recherche native de Citizen au clic | |||
$customSearch.on('click', function(e) { | |||
e.preventDefault(); | |||
// Méthode 1: Déclenche le bouton de recherche Citizen | |||
const citizenSearchButton = document.querySelector('.citizen-search__button'); | |||
if (citizenSearchButton) { | |||
citizenSearchButton.click(); | |||
return; | |||
} | |||
// Méthode 2 (fallback): Focus direct sur l'input | |||
const searchInput = document.querySelector('#searchInput, .citizen-search__input'); | |||
if (searchInput) { | |||
searchInput.focus(); | |||
} | |||
}); | |||
// Support du raccourci clavier "/" | |||
document.addEventListener('keydown', function(e) { | |||
if (e.key === '/' && !isInputFocused()) { | |||
e.preventDefault(); | |||
$customSearch.click(); | |||
} | |||
}); | |||
// Vérifie si un input est focus | |||
function isInputFocused() { | |||
const activeEl = document.activeElement; | |||
return activeEl && ( | |||
activeEl.tagName === 'INPUT' || | |||
activeEl.tagName === 'TEXTAREA' || | |||
activeEl.isContentEditable | |||
); | |||
} | |||
}); | |||
})(); | |||
Version du 29 octobre 2025 à 14:14
/* 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();
}
} );
} );
/**
* Intégration recherche page d'accueil avec Citizen
*/
(function() {
'use strict';
mw.hook('wikipage.content').add(function($content) {
// Sélectionne le bouton de recherche custom
const $customSearch = $content.find('.home-header__search');
if (!$customSearch.length) return;
// Déclenche la recherche native de Citizen au clic
$customSearch.on('click', function(e) {
e.preventDefault();
// Méthode 1: Déclenche le bouton de recherche Citizen
const citizenSearchButton = document.querySelector('.citizen-search__button');
if (citizenSearchButton) {
citizenSearchButton.click();
return;
}
// Méthode 2 (fallback): Focus direct sur l'input
const searchInput = document.querySelector('#searchInput, .citizen-search__input');
if (searchInput) {
searchInput.focus();
}
});
// Support du raccourci clavier "/"
document.addEventListener('keydown', function(e) {
if (e.key === '/' && !isInputFocused()) {
e.preventDefault();
$customSearch.click();
}
});
// Vérifie si un input est focus
function isInputFocused() {
const activeEl = document.activeElement;
return activeEl && (
activeEl.tagName === 'INPUT' ||
activeEl.tagName === 'TEXTAREA' ||
activeEl.isContentEditable
);
}
});
})();