From 47ede112ed542239aa4f73aee8301f84f1098e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souk=C3=A9ina=20Bojabza?= Date: Wed, 7 Feb 2024 14:26:37 +0000 Subject: [PATCH] [FIX] website: remove only the "history" carousel listeners at destroy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to not add steps in the history when changing the slides of a carousel, commit [1] added listeners that would deactivate the observer when sliding and reactivate it when the slide is over, in the `slider` public widget. These listeners are then removed at destroy. However, the way they are removed breaks some of the carousel behaviors: - Drop a "Carousel" snippet. - Change any "Carousel" option (so not a "Slide" one). For example, set the "Height" to 50% or add a conditional visibility. - Slide the carousel (with any arrow). => The slide number did not update correctly. - Remove a slide with the "-" button. => The slide was not removed. It happens because, when this widget is destroyed, it removes all the `.carousel` listeners, which means that it also removes the listeners added at the `Carousel` options start. And since the widget is destroyed and restarted every time an option is changed, but the "Carousel" options are started only once at the beginning, the removed listeners are never added back (until the next start of the options). This commit adds an id to the events managing the sliding history, to make them more specific, in order to only remove these ones when the widget is destroyed. [1]: https://github.com/odoo/odoo/commit/14bc1a9bd1ebdec3b73e268450267320b79d01cd opw-3675019 closes odoo/odoo#153578 X-original-commit: 041935aff660ae5df1220e3d844d2a2cbcf4ee5c Signed-off-by: Quentin Smetz (qsm) Signed-off-by: Soukéina Bojabza (sobo) --- addons/website/static/src/js/content/snippets.animation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js index a19e57b9f82..bbbd9bdde90 100644 --- a/addons/website/static/src/js/content/snippets.animation.js +++ b/addons/website/static/src/js/content/snippets.animation.js @@ -466,10 +466,10 @@ registry.slider = publicWidget.Widget.extend({ $(window).on('resize.slider', debounce(() => this._computeHeights(), 250)); if (this.editableMode) { // Prevent carousel slide to be an history step. - this.$el.on("slide.bs.carousel", () => { + this.$el.on("slide.bs.carousel.slider", () => { this.options.wysiwyg.odooEditor.observerUnactive(); }); - this.$el.on("slid.bs.carousel", () => { + this.$el.on("slid.bs.carousel.slider", () => { this.options.wysiwyg.odooEditor.observerActive(); }); } @@ -489,7 +489,7 @@ registry.slider = publicWidget.Widget.extend({ $(el).css("min-height", ""); }); $(window).off('.slider'); - this.$target.off('.carousel'); + this.$el.off('.slider'); }, //--------------------------------------------------------------------------