From 5db5206cbeb3eefc3e3e82ebb76010e4fab05085 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Thu, 8 Sep 2022 07:34:57 +0000 Subject: [PATCH] [FIX] website, website_mass_mailing: fix parallax in modals Before this commit "parallax" animation was not working in modals. This commit adds a parameter to the animation effects to enable animations (triggered by the scroll) in the modals. Note that for the "Newsletter" popup we have hidden the "parallax" options. To make them work, it would be necessary to review the structure of the "Newsletter" popup so that the vertical scrollbar is in the same location as the "s_popup" snippet (on the ".modal" element). task-2971402 closes odoo/odoo#111424 X-original-commit: f369686c1b74219968746a0f0a164dd6b3c5cfc6 Signed-off-by: Outagant Mehdi (mou) --- .../src/js/content/snippets.animation.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js index 1e1cde02534..8cc8fc54b55 100644 --- a/addons/website/static/src/js/content/snippets.animation.js +++ b/addons/website/static/src/js/content/snippets.animation.js @@ -115,6 +115,9 @@ var AnimationEffect = Class.extend(mixins.ParentedMixin, { * startEvents is received again) * @param {jQuery|DOMElement} [options.$endTarget=$startTarget] * the element(s) on which the endEvents are listened + * @param {boolean} [options.enableInModal] + * when it is true, it means that the 'scroll' event must be + * triggered when scrolling a modal. */ init: function (parent, updateCallback, startEvents, $startTarget, options) { mixins.ParentedMixin.init.call(this); @@ -126,7 +129,8 @@ var AnimationEffect = Class.extend(mixins.ParentedMixin, { // Initialize the animation startEvents, startTarget, endEvents, endTarget and callbacks this._updateCallback = updateCallback; this.startEvents = startEvents || 'scroll'; - const mainScrollingElement = $().getScrollingElement()[0]; + const modalEl = options.enableInModal ? parent.target.closest('.modal') : null; + const mainScrollingElement = modalEl ? modalEl : $().getScrollingElement()[0]; const mainScrollingTarget = mainScrollingElement === document.documentElement ? window : mainScrollingElement; this.$startTarget = $($startTarget ? $startTarget : this.startEvents === 'scroll' ? mainScrollingTarget : window); if (options.getStateCallback) { @@ -400,6 +404,7 @@ var Animation = publicWidget.Widget.extend({ endEvents: desc.endEvents || undefined, $endTarget: _findTarget(desc.endTarget), maxFPS: self.maxFPS, + enableInModal: desc.enableInModal || undefined, }); // Return the DOM element matching the selector in the form @@ -510,6 +515,7 @@ registry.Parallax = Animation.extend({ effects: [{ startEvents: 'scroll', update: '_onWindowScroll', + enableInModal: true, }], /** @@ -518,6 +524,13 @@ registry.Parallax = Animation.extend({ start: function () { this._rebuild(); $(window).on('resize.animation_parallax', _.debounce(this._rebuild.bind(this), 500)); + this.modalEl = this.$target[0].closest('.modal'); + if (this.modalEl) { + $(this.modalEl).on('shown.bs.modal.animation_parallax', () => { + this._rebuild(); + this.modalEl.dispatchEvent(new Event('scroll')); + }); + } return this._super.apply(this, arguments); }, /** @@ -526,6 +539,9 @@ registry.Parallax = Animation.extend({ destroy: function () { this._super.apply(this, arguments); $(window).off('.animation_parallax'); + if (this.modalEl) { + $(this.modalEl).off('.animation_parallax'); + } }, //--------------------------------------------------------------------------