diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js index 5b3f6d60a64..e7b9fe37eed 100644 --- a/addons/website/static/src/js/content/snippets.animation.js +++ b/addons/website/static/src/js/content/snippets.animation.js @@ -561,6 +561,12 @@ registry.Parallax = Animation.extend({ */ destroy: function () { this._super.apply(this, arguments); + this._updateBgCss({ + transform: '', + top: '', + bottom: '', + }); + $(window).off('.animation_parallax'); if (this.modalEl) { $(this.modalEl).off('.animation_parallax'); @@ -587,7 +593,8 @@ registry.Parallax = Animation.extend({ // Reset offset if parallax effect will not be performed and leave var noParallaxSpeed = (this.speed === 0 || this.speed === 1); if (noParallaxSpeed) { - this.$bg.css({ + // TODO remove in master, kept for compatibility in stable + this._updateBgCss({ transform: '', top: '', bottom: '', @@ -603,11 +610,33 @@ registry.Parallax = Animation.extend({ // Provide a "safe-area" to limit parallax const absoluteRatio = Math.abs(this.ratio); - this.$bg.css({ + this._updateBgCss({ top: -absoluteRatio, bottom: -absoluteRatio, }); }, + /** + * Updates the parallax background element style with the provided CSS + * values. + * If the editor is enabled, it deactivates the observer during the CSS + * update. + * + * @param {Object} cssValues - The CSS values to apply to the background. + */ + _updateBgCss(cssValues) { + if (!this.$bg) { + // Safety net in case the `destroy` is called before the `start` is + // executed. + return; + } + if (this.options.wysiwyg) { + this.options.wysiwyg.odooEditor.observerUnactive('_updateBgCss'); + } + this.$bg.css(cssValues); + if (this.options.wysiwyg) { + this.options.wysiwyg.odooEditor.observerActive('_updateBgCss'); + } + }, //-------------------------------------------------------------------------- // Effects @@ -629,7 +658,7 @@ registry.Parallax = Animation.extend({ var vpEndOffset = scrollOffset + this.viewport; if (vpEndOffset >= this.visibleArea[0] && vpEndOffset <= this.visibleArea[1]) { - this.$bg.css('transform', 'translateY(' + _getNormalizedPosition.call(this, vpEndOffset) + 'px)'); + this._updateBgCss({'transform': 'translateY(' + _getNormalizedPosition.call(this, vpEndOffset) + 'px)'}); } function _getNormalizedPosition(pos) { diff --git a/addons/website/static/tests/tours/parallax.js b/addons/website/static/tests/tours/parallax.js index f997d5ae9f6..f157582b3e5 100644 --- a/addons/website/static/tests/tours/parallax.js +++ b/addons/website/static/tests/tours/parallax.js @@ -46,5 +46,19 @@ wTourUtils.registerWebsitePreviewTour("test_parallax", { content: "Check that the data related to the filter have been transferred to the new target", trigger: "iframe span.s_parallax_bg[data-gl-filter='blur']", isCheck: true, +}, + wTourUtils.changeOption("Parallax", "we-toggler"), + wTourUtils.changeOption("Parallax", 'we-button[data-select-data-attribute="1.5"]'), +{ + content: "Check that the option was correctly applied", + trigger: 'iframe span.s_parallax_bg[style*=top][style*=bottom][style*=transform]', + run: () => {}, //it's a check +}, + ...wTourUtils.clickOnSave(), + ...wTourUtils.clickOnEditAndWaitEditMode(), +{ + content: "The parallax should not add o_dirty when entering edit mode", + trigger: 'iframe #wrap:not(.o_dirty)', + run: () => {}, //it's a check }, ]);