From 06b03ba5ef8375b1236f6ecb52ac468124e910ba Mon Sep 17 00:00:00 2001 From: Romeo Fragomeli Date: Thu, 28 Apr 2022 12:34:43 +0000 Subject: [PATCH] [FIX] website: fix snippet handler for BS5 scroll spy (at destroy event) This commit correclty destroy the component by removing handler and callback. This fix some issues in tests. Task ID: 2766483 Part-of: odoo/odoo#95450 --- .../static/src/snippets/s_table_of_content/000.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/snippets/s_table_of_content/000.js b/addons/website/static/src/snippets/s_table_of_content/000.js index fcae4ed7fd7..87d6a0c5067 100644 --- a/addons/website/static/src/snippets/s_table_of_content/000.js +++ b/addons/website/static/src/snippets/s_table_of_content/000.js @@ -14,12 +14,18 @@ const TableOfContent = publicWidget.Widget.extend({ async start() { await this._super(...arguments); this._updateTableOfContentNavbarPosition(); - extraMenuUpdateCallbacks.push(this._updateTableOfContentNavbarPosition.bind(this)); + this._updateTableOfContentNavbarPositionBound = this._updateTableOfContentNavbarPosition.bind(this); + extraMenuUpdateCallbacks.push(this._updateTableOfContentNavbarPositionBound); }, /** * @override */ destroy() { + const indexCallback = extraMenuUpdateCallbacks.indexOf(this._updateTableOfContentNavbarPositionBound); + if (indexCallback >= 0) { + extraMenuUpdateCallbacks.splice(indexCallback, 1); + } + this._scrollingElement.scrollspy('dispose'); this.$target.css('top', ''); this.$target.find('.s_table_of_content_navbar').css('top', ''); this._super(...arguments); @@ -42,7 +48,8 @@ const TableOfContent = publicWidget.Widget.extend({ const $mainNavBar = $('#oe_main_menu_navbar'); position += $mainNavBar.length ? $mainNavBar.outerHeight() : 0; position += isHorizontalNavbar ? this.$target.outerHeight() : 0; - $().getScrollingElement().scrollspy({target: '.s_table_of_content_navbar', method: 'offset', offset: position + 100, alwaysKeepFirstActive: true}); + this._scrollingElement = $().getScrollingElement(); + this._scrollingElement.scrollspy({target: this.$target.find('.s_table_of_content_navbar'), method: 'offset', offset: position + 100, alwaysKeepFirstActive: true}); }, });