Skip to content
Snippets Groups Projects

Issue #3214916: Behaviors will not load after AJAX call when using CSP Extras

Merged Issue #3214916: Behaviors will not load after AJAX call when using CSP Extras
All threads resolved!
Merged Bart Langelaan requested to merge issue/csp-3214916:3214916-behaviors-will-not into 8.x-1.x
All threads resolved!
+ 20
0
@@ -18,6 +18,17 @@
* The XMLHttpRequest status.
*/
Drupal.AjaxCommands.prototype.add_assets = function (ajax, response, status) {
var assetsLoaded = 0;
function onAssetLoad() {
assetsLoaded += 1;
// When new scripts are loaded, attach newly added behaviors.
if (assetsLoaded >= response.assets.length) {
Drupal.attachBehaviors(document.body, ajax.settings);
}
}
response.assets.forEach(function (item) {
var elem;
var target = document.body;
@@ -37,6 +48,15 @@
elem[key] = item.attributes[key];
});
if (item.type === "script") {
elem.onload = onAssetLoad;
}
else {
// Directly mark this element as loaded. We don't have to wait before
// behaviours can be attached.
onAssetLoad();
}
target.appendChild(elem);
});
};
Loading