Skip to content
Snippets Groups Projects
Commit c5305de9 authored by xO-Tx's avatar xO-Tx
Browse files

[FIX] website: fix the scrollspy on table of content

Steps to reproduce:

- Add a "Table Of Content" snippet from the website editor.
- Save > The effect on the active page item (in top menu) is removed.

Starting from [1], a `.scrollspy('dispose')` call was added to destroy
the existing ScrollSpy, and to be able to make a new call that works
correctly when the header height changed.

Since this call has no specific target as option, it will trigger the
`scrollspy._clear()` process on all `'.nav-link'` elements including
navbar items which removes the `'active'` class from current page link.

The goal of this commit is to fix this behaviour by calling the
'dispose' only when an instance of `Scrollspy` exists.

[1]: https://github.com/odoo/odoo/commit/476995ba5a1d33aa0590214609346557d1d471c0



task-3223277

closes odoo/odoo#114937

Signed-off-by: default avatarVray Benjamin (bvr) <bvr@odoo.com>
parent 537a9413
Branches
Tags
No related merge requests found
......@@ -48,8 +48,12 @@ const TableOfContent = publicWidget.Widget.extend({
this.$target.find('.s_table_of_content_navbar').css('maxHeight', isHorizontalNavbar ? '' : `calc(100vh - ${position + 40}px)`);
if (this.previousPosition !== position) {
// The scrollSpy must be destroyed before calling it again.
// Otherwise the call has no effect.
this.$scrollingElement.scrollspy('dispose');
// Otherwise the call has no effect. We also need to be sure that
// a scrollSpy instance exists to avoid targeting elements outside
// the table of content navbar on scrollSpy methods.
if (this.$scrollingElement.data('bs.scrollspy')) {
this.$scrollingElement.scrollspy('dispose');
}
this.$scrollingElement.scrollspy({
target: '.s_table_of_content_navbar',
method: 'offset',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment