Skip to content

Events

Haven dispatches DOM CustomEvents that bubble to document. Use these to hook into the embed lifecycle.

Listening for events

javascript
document.addEventListener('havenDirectoryInit', function (e) {
  console.log('Directory is ready', e.detail);
});

Event reference

EventFired whenModule
havenDirectoryInitDirectory list UI is readyDirectory
havenCalendarInitCalendar list UI is readyCalendar
havenMapLoadMapbox map has loadedDirectory, Calendar
havenFilterReadyFilter UI is renderedDirectory, Calendar
havenFilterToggleA toggle filter changesDirectory, Calendar
havenFilterDropdownA dropdown filter changesDirectory, Calendar
havenDirectoryBreadcrumbUpdateBreadcrumb trail updatesDirectory
havenSortFavorites list is re-sortedDirectory, Calendar
havenFaveToggleUser toggles a favoriteDirectory, Calendar
havenSetFaveCountFavorite count updatesDirectory, Calendar
changeMonthMonth picker month changesCalendar (on picker element)

Common patterns

Wait for directory before custom JS

javascript
document.addEventListener('havenDirectoryInit', function () {
  // safe to query Haven-rendered DOM
  var items = document.querySelectorAll('.haven__item');
});

Wait for map before adding custom markers

javascript
document.addEventListener('havenMapLoad', function () {
  // map is interactive
});

React to filter changes

javascript
document.addEventListener('havenFilterDropdown', function (e) {
  console.log('Filter changed:', e.detail);
});

Init vs map load

When maps are enabled, some internal logic waits for havenMapLoad instead of the module init event. If you need to run code after the full experience (including map) is ready:

javascript
document.addEventListener('havenMapLoad', function () {
  // directory/calendar + map are ready
});

Without maps, listen for havenDirectoryInit or havenCalendarInit.

changeMonth

This event fires on the month picker element (not document):

javascript
document.getElementById('haven-date-filter').addEventListener('changeMonth', function (e) {
  console.log('Month changed');
});

Haven Destinations integration documentation