feat: Changes in xblock_v2 to support studio_view [FC-0076] (#36029)
Updates to support studio_view (editors) in xblock_v2 iframe. - Send a message when cancel button is clicked on xblock_v2 iframe only in studio_view - Send a message when save.end event is notified on xblock_v2 iframe. - Send notify function in runtime. This is to avoid errors when saving the Xblock
This commit is contained in:
@@ -215,6 +215,16 @@
|
||||
}
|
||||
return url;
|
||||
},
|
||||
notify: (eventName, data) => {
|
||||
/**
|
||||
* Used in `studio_view` to notify events and errors
|
||||
**/
|
||||
window.parent.postMessage({
|
||||
type: 'xblock-event',
|
||||
eventName,
|
||||
data,
|
||||
}, '*');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -258,6 +268,25 @@
|
||||
const blockJS = { element };
|
||||
callback(blockJS);
|
||||
}
|
||||
|
||||
if ('{{ view_name | safe }}' === 'studio_view') {
|
||||
// Used when rendering the `studio_view`, in order to avoid open a new tab on click cancel or save
|
||||
const selectors = [
|
||||
'.cancel-button',
|
||||
'.save-button',
|
||||
'.action-cancel',
|
||||
'.action-save',
|
||||
];
|
||||
|
||||
for (const selector of selectors) {
|
||||
const queryObject = document.querySelector(selector);
|
||||
if (queryObject) {
|
||||
queryObject.addEventListener('click', function() {
|
||||
event.preventDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively initialize the JavaScript code of each XBlock:
|
||||
|
||||
Reference in New Issue
Block a user