Chargement asynchrone plus robuste

Fonctionne aussi si DOMContentLoaded est déjà consommé avant le
chargement de main.js, et permet d'attendre les autres scripts tels
jQuery si ceux-ci ne sont pas encore chargés.
pull/322/head
Alexandre Alapetite 11 years ago
parent 792f78e3d5
commit 6fbb62a2fc
  1. 7
      public/scripts/global_view.js
  2. 44
      public/scripts/main.js

@ -52,9 +52,12 @@ function init_global_view() {
init_stream_delegates($("#panel"));
}
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function () {
if (document.readyState && document.readyState !== 'loading') {
init_global_view();
init_close_panel();
} else if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function () {
init_global_view();
init_close_panel();
}, false);
}

@ -503,17 +503,39 @@ function init_load_more() {
}
//</endless_mode>
if (document.addEventListener) { //jQuery not ready yet
function init_all() {
if (!(window.$ && window.shortcut && ((!full_lazyload) || $.fn.lazyload))) {
if (window.console) {
console.log('Waiting for JS…');
}
window.setTimeout(init_all, 50); //Wait for all js to be loaded
return;
}
$stream = $('#stream');
init_posts();
init_column_categories();
init_shortcuts();
init_stream_delegates($stream);
init_nav_entries();
init_templates();
init_notifications();
init_actualize();
init_load_more();
if (window.console) {
console.log('Init done.');
}
}
if (document.readyState && document.readyState !== 'loading') {
if (window.console) {
console.log('Immediate init…');
}
init_all();
} else if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function () {
$stream = $('#stream');
init_posts();
init_column_categories();
init_shortcuts();
init_stream_delegates($stream);
init_nav_entries();
init_templates();
init_notifications();
init_actualize();
init_load_more();
if (window.console) {
console.log('Waiting for DOMContentLoaded…');
}
init_all();
}, false);
}

Loading…
Cancel
Save