Skip to content

Commit

Permalink
[DOCS] Add JS custom event documentation
Browse files Browse the repository at this point in the history
Describe the given JS custom events by
listing the given events and how to listen
to them.
  • Loading branch information
rintisch committed Mar 22, 2024
1 parent 38c92ae commit b92209d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/Developer/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Information for developer how to extend the extension.

Events/Index
Hooks/Index
JavaScript-Events/Index
51 changes: 51 additions & 0 deletions Documentation/Developer/JavaScript-Events/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.. include:: ../../Includes.txt

=================
JavaScript Events
=================

Multiple `custom JavaScript events<https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent>`__
allow to react with own JavaScript on JavaScript which is executed after certain
user actions.


List of events
==============
The following events exists:

=========================================== ====================================
Event name User action which triggers the event
=========================================== ====================================
`extcode:be-variant-was-changed` A BE variant of a product was chosen.
`extcode:country-updated` The country of billing or shipping address is updated.
`extcode:currency-updated` The currency of the cart is updated.
`extcode:hide-message-block` The success/error message after adding a product to the cart will be hidden.
`extcode:minicart-was-updated` A product is added to the cart (which updates the mini cart).
`extcode:render-add-to-cart-result-message` A product is added to the cart which renders a success (or error) message.
`extcode:set-payment` Another payment option is chosen.
`extcode:set-shipping` Another shipping option is chosen.
=========================================== ====================================

.. TIP::
The best way to understand when the event is executed and which data it
contains can be seen in it's context. Search in the directory
`/Build/Sources/` for the event name.

How to listen for events
========================

Every event comes with a detail object which contains data relevant for this
specific event.

The following example shows how to listen for an event.

.. code-block:: javascript
:caption: Extract of some JavaScript added with e.g. an AssetViewhelper
document.addEventListener("extcode:country-updated", (event) => {
console.log("The event 'extcode:country-updated' was fired.");
console.log("The event contains the following detail data:");
console.log(event.detail);
});

0 comments on commit b92209d

Please sign in to comment.