I'm using a library that uses ajax to retrieve content for my website. The library provides listeners for when the content will be loaded and when it has finished loading.
My code is along the lines of:
document.addEventListener('turbolinks:click', function(e) {
// Possibly does some loading or animations...
}
document.addEventListener('turbolinks:load', function(e) {
// Code here should start running after code in 'turbolinks:click' is finished.
}
What I'm looking to achieve is that the code in the callback of turbolinks:load
should only run after the code in turbolinks:click
has finished whatever it is doing.
So for example turbolinks:click
triggers an animation that takes three seconds to load. If the turbolinks:load
event triggers in those three seconds it should wait until the three seconds have passed, if it triggers after that time it can run instantly.
I hope that makes sense and someone can guide me in the right direction, thanks! :)