Need help understanding how turbo works

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 :frowning:

Thanks

What do you mean not working anymore?. When using the browser back-button, when does the issue occur?.

It happens on any navigation action. For example, navigating to another page. It works when app is loaded for the first time, any further ‘clicking around’ not loading JS properly anymore.

what does the KTMenu class do exactly?

It prepares the main menu of the app, dropdowns mainly, some other stuff. Dropdowns are the ones not working, at least that’s what’s apperant.

You want to hide the dropdowns?