|
1 | | -import {extraMenuUpdateCallbacks} from "@website/js/content/menu"; |
2 | | -import publicWidget from "@web/legacy/js/public/public_widget"; |
3 | | - |
4 | | -const faqHorizontal = publicWidget.Widget.extend({ |
5 | | - selector: '.s_faq_horizontal', |
6 | | - disabledInEditableMode: false, |
7 | | - |
8 | | - /** |
9 | | - * @override |
10 | | - */ |
11 | | - async start() { |
12 | | - await this._super(...arguments); |
13 | | - |
14 | | - this.titles = this.$el[0].getElementsByClassName('s_faq_horizontal_entry_title'); |
15 | | - |
16 | | - this._updateTitlesPosition(); |
17 | | - this._updateTitlesPositionBound = this._updateTitlesPosition.bind(this); |
18 | | - extraMenuUpdateCallbacks.push(this._updateTitlesPositionBound); |
19 | | - }, |
20 | | - /** |
21 | | - * @override |
22 | | - */ |
23 | | - destroy() { |
24 | | - const indexCallback = extraMenuUpdateCallbacks.indexOf(this._updateTitlesPositionBound); |
25 | | - if (indexCallback >= 0) { |
26 | | - extraMenuUpdateCallbacks.splice(indexCallback, 1); |
27 | | - } |
28 | | - }, |
| 1 | +import { Interaction } from "@website/core/interaction"; |
| 2 | +import { registry } from "@web/core/registry"; |
| 3 | + |
| 4 | +// TODO - Handle extraMenuUpdateCallbacks |
| 5 | +class FaqHorizontal extends Interaction { |
| 6 | + static selector = ".s_faq_horizontal"; |
29 | 7 |
|
30 | | - //-------------------------------------------------------------------------- |
31 | | - // Private |
32 | | - //-------------------------------------------------------------------------- |
| 8 | + setup() { |
| 9 | + this.titles = this.el.getElementsByClassName('s_faq_horizontal_entry_title'); |
| 10 | + // this.updateTitlesPositionBound = this.updateTitlesPosition.bind(this); |
| 11 | + // extraMenuUpdateCallbacks.push(this.updateTitlesPositionBound); |
| 12 | + } |
33 | 13 |
|
34 | | - /** |
35 | | - * @private |
36 | | - */ |
37 | | - _updateTitlesPosition() { |
| 14 | + start() { |
| 15 | + this.updateTitlesPosition(); |
| 16 | + } |
| 17 | + |
| 18 | + destroy() { |
| 19 | + // const indexCallback = extraMenuUpdateCallbacks.indexOf(this._updateTitlesPositionBound); |
| 20 | + // if (indexCallback >= 0) { |
| 21 | + // extraMenuUpdateCallbacks.splice(indexCallback, 1); |
| 22 | + // } |
| 23 | + } |
| 24 | + |
| 25 | + updateTitlesPosition() { |
38 | 26 | let position = 16; // Add 1rem equivalent in px to provide a visual gap by default |
39 | 27 | const fixedElements = document.getElementsByClassName('o_top_fixed_element'); |
40 | 28 |
|
41 | | - Array.from(fixedElements).forEach((el) => position += el.offsetHeight); |
| 29 | + for (let el of fixedElements) { |
| 30 | + position += el.offsetHeight; |
| 31 | + } |
42 | 32 |
|
43 | | - Array.from(this.titles).forEach((title) => { |
| 33 | + for (let title of this.titles) { |
44 | 34 | title.style.top = `${position}px`; |
45 | 35 | title.style.maxHeight = `calc(100vh - ${position + 40}px)`; |
46 | | - }); |
47 | | - }, |
48 | | -}); |
49 | | - |
50 | | -publicWidget.registry.snippetFaqHorizontal = faqHorizontal; |
| 36 | + } |
| 37 | + } |
| 38 | +} |
51 | 39 |
|
52 | | -export default faqHorizontal; |
| 40 | +registry |
| 41 | + .category("website.active_elements") |
| 42 | + .add("website.faq_horizontal", FaqHorizontal); |
0 commit comments