From f6d4b8e9376df2a01847208fa27260c7d8cce84b Mon Sep 17 00:00:00 2001 From: Daniel Kudwien Date: Fri, 11 Jul 2025 13:53:34 +0200 Subject: [PATCH 1/2] Fixed JS hooks documentation does not educate about integrating with widgets. --- src/hooks/js.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/hooks/js.md b/src/hooks/js.md index a89a010b..b7056123 100644 --- a/src/hooks/js.md +++ b/src/hooks/js.md @@ -136,6 +136,28 @@ elementorFrontend.hooks.addAction( 'frontend/element_ready/google-maps.satellite } ); ``` +## Integrating with widgets + +Elementor Frontend does not trigger an event when a widget is initialized and loaded. And most widgets use hardcoded parameters derived from element settings, so you cannot customize them from PHP or JavaScript. + +You can use the regular window.onLoad event to act on elements when page loading has completed. + +#### Example + +```js +jQuery(document).ready(function ($) { + // Swiper instance only exists after image carousel widget + // has been initialized. + $(window).on('load', () => { + const $carousel = $('.swiper'); + if ($carousel.data('swiper')) { + const swiper = $carousel.data('swiper'); + swiper.params.a11y.containerRole = 'button'; + } + }); +}); +``` + ## Editor Hooks ### `panel/open_editor/{elementType}` From b5c70c793a8a710b0eec8aad5146cbe03f4d13ac Mon Sep 17 00:00:00 2001 From: Daniel Kudwien Date: Fri, 11 Jul 2025 14:13:40 +0200 Subject: [PATCH 2/2] Support multiple swiper instances. --- src/hooks/js.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hooks/js.md b/src/hooks/js.md index b7056123..46100518 100644 --- a/src/hooks/js.md +++ b/src/hooks/js.md @@ -145,15 +145,16 @@ You can use the regular window.onLoad event to act on elements when page loading #### Example ```js -jQuery(document).ready(function ($) { +jQuery(document).ready(($) => { // Swiper instance only exists after image carousel widget // has been initialized. $(window).on('load', () => { - const $carousel = $('.swiper'); - if ($carousel.data('swiper')) { - const swiper = $carousel.data('swiper'); - swiper.params.a11y.containerRole = 'button'; - } + $('.swiper').each(function () { + const swiper = $(this).data('swiper'); + if (swiper) { + swiper.params.a11y.containerRole = 'button'; + } + }); }); }); ```