mirror of
https://github.com/jonom/silverstripe-betternavigator.git
synced 2024-10-22 14:05:51 +02:00
Support async script loading
Use addEventListener to schedule BN initialisation only if document is still loading (#34)
This commit is contained in:
parent
2a9df8695d
commit
132a98be68
@ -32,13 +32,13 @@ function initialiseBetterNavigator() {
|
||||
}
|
||||
}
|
||||
|
||||
if (document.addEventListener) {
|
||||
if (document.addEventListener && document.readyState === 'loading') {
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
//wait til DOM is ready
|
||||
// wait til DOM finishes loading
|
||||
initialiseBetterNavigator();
|
||||
});
|
||||
} else {
|
||||
//This is the case for IE8 and below
|
||||
//initialise straight away - fine if script is loaded after BN dom element
|
||||
// This is the case for IE8 and below OR already loaded document (e.g. when using async)
|
||||
// initialise straight away - fine if script is loaded after BN dom element
|
||||
initialiseBetterNavigator();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user