Refactoring : sécurité (XSS), découpage en modules inc/* et js/admin/*, IDs résolus par slug, perf (caches, cron Gravatar, assets auto-hébergés), tests
This commit is contained in:
77
js/admin/admin-rename.js
Normal file
77
js/admin/admin-rename.js
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Renomme « Article » en « Annonce » dans l'interface admin (toutes pages).
|
||||
* Dépend de admin-base.js (window.ThalimAdmin).
|
||||
*/
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var TA = window.ThalimAdmin;
|
||||
|
||||
function renameArticlesToAnnonces() {
|
||||
const replacements = [
|
||||
[/Tous les articles/g, 'Toutes les annonces'],
|
||||
[/Ajouter un article/g, 'Ajouter une annonce'],
|
||||
[/Modifier l.article/g, "Modifier l'annonce"],
|
||||
[/Prévisualiser l.article/g, "Prévisualiser l'annonce"],
|
||||
[/Afficher l.article/g, "Afficher l'annonce"],
|
||||
[/Voir l.article/g, "Voir l'annonce"],
|
||||
[/Article publié/g, 'Annonce publiée'],
|
||||
[/Article mis à jour/g, 'Annonce mise à jour'],
|
||||
[/Article planifié/g, 'Annonce planifiée'],
|
||||
[/Articles par page/g, 'Annonces par page'],
|
||||
[/Articles/g, 'Annonces'],
|
||||
[/Article/g, 'Annonce'],
|
||||
[/Rechercher des articles/g, 'Rechercher des annonces'],
|
||||
];
|
||||
|
||||
function applyReplacements(text) {
|
||||
return replacements.reduce((t, [s, r]) => t.replace(s, r), text);
|
||||
}
|
||||
|
||||
function replaceInTextNodes(el) {
|
||||
if (!el) return;
|
||||
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
|
||||
const nodes = [];
|
||||
while (walker.nextNode()) nodes.push(walker.currentNode);
|
||||
nodes.forEach(function(node) {
|
||||
const replaced = applyReplacements(node.textContent);
|
||||
if (replaced !== node.textContent) node.textContent = replaced;
|
||||
});
|
||||
}
|
||||
|
||||
// Menu latéral
|
||||
replaceInTextNodes(document.querySelector('#menu-posts'));
|
||||
|
||||
// Titre de page (h1) et bouton d'ajout
|
||||
document.querySelectorAll('.wp-heading-inline, .page-title-action').forEach(replaceInTextNodes);
|
||||
|
||||
// Notifications après sauvegarde (Article publié, mis à jour…)
|
||||
document.querySelectorAll('#message, .notice').forEach(replaceInTextNodes);
|
||||
|
||||
// Boîte de publication — lien "Voir l'article"
|
||||
replaceInTextNodes(document.querySelector('.submitbox'));
|
||||
|
||||
// Options d'écran — "Articles par page"
|
||||
replaceInTextNodes(document.querySelector('#screen-options-wrap'));
|
||||
|
||||
// Bouton de recherche (attribut value + aria-label)
|
||||
var searchSubmit = document.querySelector('#search-submit');
|
||||
if (searchSubmit) {
|
||||
if (searchSubmit.value) {
|
||||
searchSubmit.value = applyReplacements(searchSubmit.value);
|
||||
}
|
||||
var ariaLabel = searchSubmit.getAttribute('aria-label');
|
||||
if (ariaLabel) {
|
||||
searchSubmit.setAttribute('aria-label', applyReplacements(ariaLabel));
|
||||
}
|
||||
}
|
||||
|
||||
// Titre de l'onglet du navigateur
|
||||
document.title = applyReplacements(document.title);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
TA.safeRun('renameArticlesToAnnonces', renameArticlesToAnnonces);
|
||||
});
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user