@@ -128,6 +128,8 @@ Reference List
128
128
- manage the browser url
129
129
* - :ref: `rpc <frontend/services/rpc >`
130
130
- send requests to the server
131
+ * - :ref: `scroller <frontend/services/scroller >`
132
+ - handle clicks on anchors elements
131
133
* - :ref: `title <frontend/services/title >`
132
134
- read or modify the window title
133
135
* - :ref: `user <frontend/services/user >`
@@ -692,6 +694,57 @@ When a rpc fails, then:
692
694
displayed and the server is regularly contacted until it responds. The
693
695
notification is closed as soon as the server responds.
694
696
697
+ .. _frontend/services/scroller :
698
+
699
+ Scroller service
700
+ ----------------
701
+
702
+ Overview
703
+ ~~~~~~~~
704
+
705
+ - Technical name: `scroller `
706
+ - Dependencies: none
707
+
708
+ Whenever the user clicks on an anchor in the web client, this service automatically scrolls
709
+ to the target (if appropriate).
710
+
711
+ The service adds an event listener to get `click `'s on the document. The service checks
712
+ if the selector contained in its href attribute is valid to distinguish anchors and Odoo
713
+ actions (e.g. `<a href="#target_element"></a> `). It does nothing if it is not the case.
714
+
715
+ An event `SCROLLER:ANCHOR_LINK_CLICKED ` is triggered on the main application bus if the click seems to be
716
+ targeted at an element. The event contains a custom event containing the `element ` matching and its `id ` as a reference.
717
+ It may allow other parts to handle a behavior relative to anchors themselves. The original event is also
718
+ given as it might need to be prevented. If the event is not prevented, then the user interface will
719
+ scroll to the target element.
720
+
721
+ API
722
+ ~~~
723
+
724
+ The following values are contained in the `anchor-link-clicked ` custom event explained above.
725
+
726
+ .. list-table ::
727
+ :widths: 25 25 50
728
+ :header-rows: 1
729
+
730
+ * - Name
731
+ - Type
732
+ - Description
733
+ * - `element `
734
+ - `HTMLElement | null `
735
+ - The anchor element targeted by the href
736
+ * - `id `
737
+ - `string `
738
+ - The id contained in the href
739
+ * - `originalEv `
740
+ - `Event `
741
+ - The original click event
742
+
743
+ .. note ::
744
+ The scroller service emits a `SCROLLER:ANCHOR_LINK_CLICKED ` event on the :ref: `main bus <frontend/framework/bus >`.
745
+ To avoid the default scroll behavior of the scroller service, you must use `preventDefault() ` on the event given
746
+ to the listener so that you can implement your own behavior correctly from the listener.
747
+
695
748
.. _frontend/services/title :
696
749
697
750
Title Service
0 commit comments