Skip to content

Commit 1f84bab

Browse files
committed
[ADD] developer: scroller service added
This commit adds the documentation related to the scroller service. This service is used for the webclient to handle clicks on links and there were no documentation related until now. closes odoo#1313 Signed-off-by: Géry Debongnie (ged) <[email protected]>
1 parent 0653e3d commit 1f84bab

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

content/developer/reference/frontend/services.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Reference List
128128
- manage the browser url
129129
* - :ref:`rpc <frontend/services/rpc>`
130130
- send requests to the server
131+
* - :ref:`scroller <frontend/services/scroller>`
132+
- handle clicks on anchors elements
131133
* - :ref:`title <frontend/services/title>`
132134
- read or modify the window title
133135
* - :ref:`user <frontend/services/user>`
@@ -692,6 +694,57 @@ When a rpc fails, then:
692694
displayed and the server is regularly contacted until it responds. The
693695
notification is closed as soon as the server responds.
694696

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+
695748
.. _frontend/services/title:
696749

697750
Title Service

0 commit comments

Comments
 (0)