Skip to content

Commit

Permalink
refactor: Update preventDefault of events of cancel and save buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Jan 14, 2025
1 parent c05755c commit 9f86ddc
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions common/templates/xblock_v2/xblock_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,22 @@
}

if ('{{ view_name | safe }}' === 'studio_view') {
// Used when rendering the `studio_view`, in order to intercept and handle the cancel button event
document.querySelector('.cancel-button').addEventListener('click', function() {
event.preventDefault();
window.parent.postMessage({
type: 'xblock-event',
eventName: 'cancel-clicked',
}, '*');
});
// 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();
});
}
}
}
}

Expand Down

0 comments on commit 9f86ddc

Please sign in to comment.