Skip to content

Commit 79f49e2

Browse files
committed
fix: Improve databridge.js
1 parent 48e3293 commit 79f49e2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

djangocms_alias/static/djangocms_alias/js/databridge.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function () {
22

3-
function processDataBridge(data) {
3+
const processDataBridge = function (data) {
44
let actionsPerformed = 0;
55
window.parent.console.log('Processing data bridge:', data);
66
if (data.replacedPlaceholder) {
@@ -29,14 +29,18 @@
2929
const iframe = window.parent.document.querySelector('.cms-modal-frame > iframe');
3030
const {CMS} = window.parent;
3131

32+
if (!iframe || !CMS) {
33+
return;
34+
}
35+
3236
// Register the event handler in the capture phase to increase the chance it runs first
3337
iframe.addEventListener('load', function (event) {
3438
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
3539
const dataBridge = iframeDocument.body.querySelector('script#data-bridge');
3640
if (dataBridge) {
3741
window.parent.console.log('iframe loaded', dataBridge);
3842
try {
39-
data = JSON.parse(dataBridge.textContent);
43+
const data = JSON.parse(dataBridge.textContent);
4044
if (data.action === 'ALIAS_REPLACE') {
4145
event.stopPropagation();
4246
dataBridge.parentNode.removeChild(dataBridge);

0 commit comments

Comments
 (0)