JavaScript Events & API

Listen to Elephanta browser events for analytics and integrations, and control popups and sliders from JavaScript.

Developer 2 min read Updated
On this page

Elephanta fires standard DOM events you can listen to for analytics (GA4, Meta Pixel), A/B tests and custom integrations.

#Popups

Event (on document) When
elephanta:popup:open A popup starts opening
elephanta:popup:close A popup starts closing
elephanta:popup:closed A popup finished closing
elephanta:popup:convert A conversion was counted
document.addEventListener('elephanta:popup:convert', function (e) {
    if (window.gtag) { gtag('event', 'popup_conversion', { popup: e.detail && e.detail.id }); }
});

// Open popup 123 from your own code
ElephantaPopups.open(123);
document.addEventListener('elephanta:ajax-search:complete', function (e) {
    // Results were updated: re-run a lazy-loader, send an event, etc.
});

#Super Slider

ess:ready and ess:change fire on the slider element (class ess, plus ess-ID for a specific slider) and bubble up. e.detail contains index and slider. The element's .ess property exposes next(), prev() and goTo(index).

var slider = document.querySelector('.ess-123'); // slider ID 123
slider.addEventListener('ess:change', function (e) {
    console.log('Now showing slide', e.detail.index);
});
slider.ess.goTo(2);

#Translate

document.addEventListener('elephanta:translate', function (e) {
    // e.detail.lang = new language code, e.detail.previous = previous one
    console.log('Language changed from', e.detail.previous, 'to', e.detail.lang);
});

#Element code helpers

JavaScript added in an element's Attributes & Custom Code section receives element, target, selector(query), settings and jQuery. See Advanced Controls.

Event details

Inspect e.detail in your browser console to see the data each event carries.