Skip to content
Snippets Groups Projects

Issue #2982391: JS scripts with defer property can't be loaded for some cases due to Jquery 3.1 core changes

Open Issue #2982391: JS scripts with defer property can't be loaded for some cases due to Jquery 3.1 core changes
1 file
+ 17
1
Compare changes
  • Side-by-side
  • Inline
+ 17
1
@@ -611,7 +611,23 @@ $(function () {
@@ -611,7 +611,23 @@ $(function () {
//Attach all behaviors.
//Attach all behaviors.
$(function () {
$(function () {
Drupal.attachBehaviors(document, Drupal.settings);
// Only attach behaviors on 'complete' document state to make sure the scripts
 
// using 'defer' are already loaded (otherwise the behaviors
 
// might not get attached).
 
// This is a workaround for jQuery ready being fired too soon
 
// (see https://github.com/jquery/jquery/issues/3271).
 
// If the state is 'complete' attach behaviors immediately.
 
if (document.readyState === 'complete') {
 
Drupal.attachBehaviors(document, Drupal.settings);
 
}
 
// If we have a different state, wait for the state to change to 'complete'.
 
else {
 
document.addEventListener('readystatechange', function() {
 
if (document.readyState === 'complete') {
 
Drupal.attachBehaviors(document, Drupal.settings);
 
}
 
});
 
}
});
});
/**
/**
Loading