Skip to content

Commit

Permalink
refactor: corrected scroll to target xblock
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Jan 16, 2025
1 parent 8ca933a commit 6e8e77d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cms/static/js/views/pages/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function($, _, Backbone, gettext, BasePage,
if (!data) return;

const xblockElement = this.findXBlockElement(this.targetXBlock);
const xblockWrapper = $("li.studio-xblock-wrapper[data-locator='" + data.payload.locator + "']");

switch (data.type) {
case 'refreshXBlock':
Expand All @@ -145,6 +146,13 @@ function($, _, Backbone, gettext, BasePage,
case 'completeManageXBlockAccess':
this.refreshXBlock(xblockElement, false);
break;
case 'completeXBlockMoving':
xblockWrapper.hide()
break;
case 'rollbackMovedXBlock':
xblockWrapper.show()
break;
case 'updateXBlockName':
case 'addXBlock':
this.createComponent(this, xblockElement, event.data);
break;
Expand Down Expand Up @@ -216,6 +224,25 @@ function($, _, Backbone, gettext, BasePage,
target.scrollIntoView({ behavior: 'smooth', inline: 'center' });
}

if (self.options.isIframeEmbed) {
const scrollOffset = parseInt(localStorage.getItem('modalEditLastYPosition'));
if (localStorage.getItem('modalEditLastYPosition')) {
try {
setTimeout(() => {
window.parent.postMessage(
{
type: 'scrollToXBlock',
message: 'Scroll to XBlock',
payload: {scrollOffset}
}, document.referrer
);
localStorage.removeItem('modalEditLastYPosition');
}, 1000);
} catch (e) {
console.error(e);
}
}
}
},
block_added: options && options.block_added
});
Expand Down Expand Up @@ -454,6 +481,7 @@ function($, _, Backbone, gettext, BasePage,

try {
if (this.options.isIframeEmbed) {
localStorage.setItem('modalEditLastYPosition', event.clientY.toString());
return window.parent.postMessage(
{
type: 'newXBlockEditor',
Expand Down

0 comments on commit 6e8e77d

Please sign in to comment.