So, i am integrating a template into Rails 7.0 project, where JS is already written to some extend. A lot.
And it is driving me nuts, because JS is triggered fine on first load, then after clicking some link (seems like by default they are turbo enabled) this exact same JS is somehow not triggered at all.
This is the code for example:
// On document ready
if (document.readyState === 'loading') {
document.addEventListener('turbo:load', KTMenu.init);
} else {
KTMenu.init();
console.log("fired")
}
As you can see i’ve added log to console, to see what is going on, and when page is delivered by turbo, the “else” part is definitely triggered, but not working anymore.
Can please, someone explain why this is not working?
Should i add an event listener here (to some other event, as load already happened)?
I don’t get it
Thanks