Skip to content

Commit

Permalink
Add DOMContentLoaded event alternative for Turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioalcaraz committed Mar 25, 2024
1 parent e3af211 commit 8464325
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions webroot/js/inject-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ if (elem) {
if (doc.addEventListener) {
// This ensures that all event listeners get applied only once.
if (!win.debugKitListenersApplied) {
doc.addEventListener('DOMContentLoaded', onReady, false);
doc.addEventListener('DOMContentLoaded', proxyAjaxOpen, false);
doc.addEventListener('DOMContentLoaded', proxyAjaxSend, false);
// Add support for turbo DOMContentLoaded alternative
// see https://turbo.hotwired.dev/reference/events#turbo%3Aload
const loadedEvent = Turbo ? 'turbo:load' : 'DOMContentLoaded';
doc.addEventListener(loadedEvent, onReady, false);
doc.addEventListener(loadedEvent, proxyAjaxOpen, false);
doc.addEventListener(loadedEvent, proxyAjaxSend, false);
win.debugKitListenersApplied = true;
}
} else {
Expand Down

0 comments on commit 8464325

Please sign in to comment.