From f66c992ad88324d0495db0fae606a82d7031f360 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 21 Oct 2021 13:37:38 +0100 Subject: [PATCH] Fixed design preview remembering scroll position when changing page refs https://github.com/TryGhost/Team/issues/1149 - added a `@pageId` argument to ``, if that value is different at the point of swapping iframes after re-rendering it will reset the scroll position instead of copying it from the to-be-hidden iframe - assigned `themeManagement.previewType` to `@pageId` so that it changes when switching between homepage and post previews --- ghost/admin/app/components/gh-html-iframe.js | 9 ++++++++- ghost/admin/app/templates/settings/design/index.hbs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ghost/admin/app/components/gh-html-iframe.js b/ghost/admin/app/components/gh-html-iframe.js index fd29a7a4e5..0b84c24c3f 100644 --- a/ghost/admin/app/components/gh-html-iframe.js +++ b/ghost/admin/app/components/gh-html-iframe.js @@ -62,7 +62,14 @@ export default class GhHtmlIframeComponent extends Component { window.clearTimeout(this.swapTimeout); if (this.iframes.indexOf(renderedIframe) !== this.renderedIframe) { - this.iframes[this.toRenderIframe].contentDocument.body.scrollTop = this.iframes[this.renderedIframe].contentDocument.body.scrollTop; + let newScrollTop = this.iframes[this.renderedIframe].contentDocument.body.scrollTop; + + if (this._lastPageId !== this.args.pageId) { + newScrollTop = 0; + } + this._lastPageId = this.args.pageId; + + this.iframes[this.toRenderIframe].contentDocument.body.scrollTop = newScrollTop; this.iframes[this.toRenderIframe].style = this.visibleIframeStyle; this.renderedIframe = this.toRenderIframe; this.toRenderIframe = this.toRenderIframe === 0 ? 1 : 0; diff --git a/ghost/admin/app/templates/settings/design/index.hbs b/ghost/admin/app/templates/settings/design/index.hbs index 96f3eed6b6..e661fc1d18 100644 --- a/ghost/admin/app/templates/settings/design/index.hbs +++ b/ghost/admin/app/templates/settings/design/index.hbs @@ -50,7 +50,7 @@ {{/if}}
- +