Skip to content
Snippets Groups Projects
Commit d2d79db2 authored by Bart Langelaan's avatar Bart Langelaan Committed by Geoff Appleby
Browse files

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

parent 9482433e
Branches
Tags
1 merge request!3Issue #3214916: Behaviors will not load after AJAX call when using CSP Extras
......@@ -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);
});
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment