Correction : Interception des clics sur le lien stratégie pour éviter le 404
- Le script intercepte maintenant tous les clics sur les liens vers /business/strategie - La page est créée dynamiquement sans navigation (pas de 404) - Gestion du bouton retour du navigateur - Le lien dans le footer utilise maintenant un hash pour éviter la navigation
This commit is contained in:
70
custom.js
70
custom.js
@@ -2,20 +2,41 @@
|
||||
(function() {
|
||||
function initStrategyLinks() {
|
||||
addStrategyLinkToFooter();
|
||||
interceptStrategyLinks();
|
||||
handleStrategyRoute();
|
||||
}
|
||||
|
||||
function handleStrategyRoute() {
|
||||
if (window.location.pathname === '/business/strategie' || window.location.pathname === '/business/strategie.html') {
|
||||
// Vérifier si on est sur la route stratégie au chargement initial
|
||||
if (window.location.pathname === '/business/strategie' || window.location.pathname === '/business/strategie.html' || window.location.hash === '#strategie') {
|
||||
createStrategyPage();
|
||||
}
|
||||
}
|
||||
|
||||
// Intercepter tous les clics sur les liens vers la stratégie
|
||||
function interceptStrategyLinks() {
|
||||
document.addEventListener('click', function(e) {
|
||||
const link = e.target.closest('a');
|
||||
if (link && (link.href.includes('/business/strategie') || link.getAttribute('href') === '/business/strategie' || link.id === 'strategie-link')) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
createStrategyPage();
|
||||
return false;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
function createStrategyPage() {
|
||||
// Sauvegarder le contenu original
|
||||
if (!window.originalBodyContent) {
|
||||
window.originalBodyContent = document.body.innerHTML;
|
||||
}
|
||||
|
||||
// Créer la page stratégie
|
||||
document.body.innerHTML = `
|
||||
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; background: #f5f5f5;">
|
||||
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; background: #f5f5f5; min-height: 100vh;">
|
||||
<div style="background: white; padding: 40px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
|
||||
<a href="/business/" style="display: inline-block; margin-bottom: 20px; color: #2ecc71; text-decoration: none; font-weight: bold;">← Retour au Radar</a>
|
||||
<a href="#" id="back-to-radar" style="display: inline-block; margin-bottom: 20px; color: #2ecc71; text-decoration: none; font-weight: bold; cursor: pointer;">← Retour au Radar</a>
|
||||
<h1 style="color: #1a4d3a; border-bottom: 3px solid #2ecc71; padding-bottom: 10px;">Stratégie d'Évolution Technique - Laplank</h1>
|
||||
<p><strong>Date de mise à jour</strong> : 02/12/2025</p>
|
||||
<p>La stratégie complète est disponible dans le dépôt Git :</p>
|
||||
@@ -23,25 +44,65 @@
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Ajouter le gestionnaire de retour
|
||||
const backLink = document.getElementById('back-to-radar');
|
||||
if (backLink) {
|
||||
backLink.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
if (window.originalBodyContent) {
|
||||
document.body.innerHTML = window.originalBodyContent;
|
||||
// Réinitialiser les liens après restauration
|
||||
setTimeout(initStrategyLinks, 100);
|
||||
} else {
|
||||
window.location.href = '/business/';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Mettre à jour l'URL sans recharger la page
|
||||
window.history.pushState({page: 'strategie'}, 'Stratégie', '/business/strategie');
|
||||
}
|
||||
|
||||
function addStrategyLinkToFooter() {
|
||||
const footer = document.querySelector('footer') || document.querySelector('.footer') || document.querySelector('[class*="footer"]');
|
||||
|
||||
if (footer) {
|
||||
// Vérifier si le lien n'existe pas déjà
|
||||
if (footer.querySelector('#strategie-link') || footer.querySelector('a[href*="strategie"]')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const strategyLink = document.createElement('a');
|
||||
strategyLink.href = '/business/strategie';
|
||||
strategyLink.id = 'strategie-link';
|
||||
strategyLink.href = '#strategie';
|
||||
strategyLink.textContent = '📋 Voir la Stratégie';
|
||||
strategyLink.style.marginLeft = '10px';
|
||||
strategyLink.style.color = '#2ecc71';
|
||||
strategyLink.style.textDecoration = 'none';
|
||||
strategyLink.style.fontWeight = 'bold';
|
||||
strategyLink.style.display = 'inline-block';
|
||||
strategyLink.style.cursor = 'pointer';
|
||||
|
||||
// Intercepter le clic
|
||||
strategyLink.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
createStrategyPage();
|
||||
});
|
||||
|
||||
footer.appendChild(strategyLink);
|
||||
} else {
|
||||
setTimeout(addStrategyLinkToFooter, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// Gérer le bouton retour du navigateur
|
||||
window.addEventListener('popstate', function(event) {
|
||||
if (window.originalBodyContent && !event.state) {
|
||||
document.body.innerHTML = window.originalBodyContent;
|
||||
setTimeout(initStrategyLinks, 100);
|
||||
}
|
||||
});
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initStrategyLinks);
|
||||
@@ -49,4 +110,3 @@
|
||||
initStrategyLinks();
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user