Skip to content

Commit

Permalink
Move the required init functions to dedicated function with has run flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pattonwebz committed Dec 9, 2024
1 parent 6a07a3e commit 7eaf5f4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/frontendHighlighterApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,19 @@ 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 initHasRun = false;
const initHighlighter = () => {
if ( ! initHasRun ) {
new AccessibilityCheckerHighlight();
if ( window.edacFrontendHighlighterApp?.userCanFix ) {
fixSettingsModalInit();
}
initHasRun = true;
}
};
window.addEventListener( 'DOMContentLoaded', () => {
initHighlighter();
} );

0 comments on commit 7eaf5f4

Please sign in to comment.