From 6e8e77dc32d2f63c7db71731057a4fc3b81c2b68 Mon Sep 17 00:00:00 2001 From: Peter Kulko Date: Mon, 9 Dec 2024 08:34:24 +0200 Subject: [PATCH] refactor: corrected scroll to target xblock --- cms/static/js/views/pages/container.js | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index 8e6a46efab62..25d8cf5df5e1 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -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': @@ -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; @@ -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 }); @@ -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',