Skip to content

Commit

Permalink
Merge pull request #829 from equalizedigital/william/8073815433/retry…
Browse files Browse the repository at this point in the history
…-frontend-highlighter-init-later

Enhancement: Retry frontend highlighter init later
  • Loading branch information
pattonwebz authored Dec 19, 2024
2 parents f3aa624 + 204c511 commit 7fbbb0e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/frontendHighlighterApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,20 @@ class AccessibilityCheckerHighlight {
}
}

window.addEventListener( 'DOMContentLoaded', () => {
new AccessibilityCheckerHighlight();
if ( window.edacFrontendHighlighterApp?.userCanFix ) {
fixSettingsModalInit();
// Some systems (Cloudflare Rocket Loader) defers scripts for performance but that can
// cause some DOMContentLoaded events to be missed. This is flag tracks if it run so we
// can retry at a latter event listener.
let highlighterInitialized = false;
const initHighlighter = () => {
if ( ! highlighterInitialized ) {
new AccessibilityCheckerHighlight();
if ( window.edacFrontendHighlighterApp?.userCanFix ) {
fixSettingsModalInit();
}
highlighterInitialized = true;
}
};

[ 'DOMContentLoaded', 'load' ].forEach( ( event ) => {
window.addEventListener( event, initHighlighter );
} );

0 comments on commit 7fbbb0e

Please sign in to comment.