Tutorial

Elementor Linked JetSlider Widgets revisited

Uses Plugins

Elementor PRO
Crocoblock JetElements

Description

Elementor Linked JetSlider Widgets revisited

1

Add Jet Sliders to the page

  1. Add two JetSlider Widgets to the page
  2. Style them as you like
  3. On both, go to Advanced -> Attributes
  4. Add "data-remote-group|slides-c"

Note: ensure both sliders have the same number of slides.

2

JavaScript

  1. Add an HTML Widget to the page.
  2. Copy and paste the code below into it.

Code (click to copy)

JavaScript (javascript)

Note:

This updated code links both the Elementor Native Slides Widgets and the JetElements Slider Widgets. However, all Sliders in a group must be of the same type.

<script>
    ;(w => {
        let swiperRefGroups = {};
        let sliderProRefGroups = {};

        w.addEventListener('elementor/frontend/init', () => {

            const initListener = $scope => {
                const type = $scope.data('widget_type');
                const [name, skin] = type.split('.');
                switch (name) {
                    case 'slides':
                        initSwiperWidget($scope);
                        break;

                    case 'jet-slider':
                        initSliderProWidget($scope);
                        break;
                        
                    case 'jet-carousel':
                        initSliderProWidget($scope);
                        break;

                    default:
                        return;
                }
            }
            elementorFrontend.hooks.addAction('frontend/element_ready/widget', initListener);
        });

        /**************
         * WIDGET INITIALISERS */
        const initSwiperWidget = $scope => {
            const group = $scope.data('remote-group');
            if (group) {
                swiperRemoteInit($scope, group);
            }
        }

        const initSliderProWidget = $scope => {
            const group = $scope.data('remote-group');
            if (group) {
                sliderProRemoteInit($scope, group);
            }
        }

        /*#######################
        REMOTE CONNECTORS
        #######################*/

        /*****
         * Elementor Swiper Widgets
         * */
        let swiperDebounce; //Stop JS triggered changes re-triggering
        const swiperRemoteHandleChange = (triggerSwiper, group) => {
            if (swiperDebounce) {
                return
            }
            swiperDebounce = setTimeout(() => {
                clearTimeout(swiperDebounce);
                swiperDebounce = null;
            }, 500);

            //Iterate connected swipers in the group
            const groupRefs = swiperRefGroups[group];
            groupRefs.forEach(swiper => {
                //skip swiper that triggered this change
                if (triggerSwiper !== swiper) {
                    swiper.slideTo(triggerSwiper.activeIndex, 500, true)
                }
            });
        }

        const swiperRemoteInit = ($scope, group) => {
            const swiperContainer = $scope.find('.swiper-container');
            let swiperRef;

            //Wait for Swiper to initialise
            setTimeout(() => {
                swiperRef = swiperContainer.data('swiper');
                swiperRef.on('realIndexChange', () => {
                        swiperRemoteHandleChange(swiperRef, group);
                    }
                );
                if (undefined === swiperRefGroups[group]) {
                    swiperRefGroups[group] = [];
                }
                swiperRefGroups[group].push(swiperRef);
            }, 100);
        }


        /*****
         * Crocoblock SliderPro Widgets
         * */
         /*@see https://github.com/bqworks/slider-pro/blob/master/docs/api.md */
        let sliderProDebounce;
        const sliderProRemoteHandleChange = (triggerRef, group, index) => {
            if (sliderProDebounce) {
                return
            }
            sliderProDebounce = setTimeout(() => {
                clearTimeout(sliderProDebounce);
                sliderProDebounce = null;
            }, 500);

            //Iterate connected swipers in the group
            const groupRefs = sliderProRefGroups[group];
            groupRefs.forEach( jsRef => {
                if (triggerRef !== jsRef) {
                    jsRef.gotoSlide(index);
                }
            });
        }

        const sliderProRemoteInit = ($scope, group) => {
            const container = $scope.find('.slider-pro');
            let ref;

            //Wait for Slider to initialise
            setTimeout(() => {
                ref = container.data('sliderPro');
                ref.on('gotoSlide', e => {
                        sliderProRemoteHandleChange(ref, group, e.index);
                    }
                );
                if (undefined === sliderProRefGroups[group]) {
                    sliderProRefGroups[group] = [];
                }
                sliderProRefGroups[group].push(ref);
            }, 100);
        }

    })(window)
</script>