gamexo developers
Leo Cal

JavaScript API & events

Open the widget from code, mount a card yourself, and listen for bookings on your own page.

The loader script adds one global, window.LeoCal, and sends two events to your page's window. That is the whole surface.

window.LeoCal

window.LeoCal = {
  open(options?),     // open the booking pop-up
  close(),            // close it
  mount(element, options?),   // fill an element with a booking card
  version: '1',
}

It exists once the script has loaded. From code that may run earlier, use optional chaining — window.LeoCal?.open() — so an early call does nothing instead of throwing.

open(options?)

Opens the booking pop-up, closing any that is already open.

OptionType
keystringA browser key. Defaults to the script tag's data-key.
branchstringBranch name or id to open on.
sportstringSport name, slug or id to open on.
courtstringCourt name or id to open on.
popup'modal' | 'sheet'A box in the middle, or a sheet from the top. Defaults to the script tag's data-popup.
window.LeoCal.open()
window.LeoCal.open({ sport: 'football', branch: 'gandipet' })
window.LeoCal.open({ popup: 'sheet' })

It needs a key. If neither options.key nor the script's data-key is present, nothing opens and the console says so:

[leo-cal] No key: add data-key="gxp_…" to the embed.js script tag.

close()

Closes the pop-up if it is open. Does nothing otherwise. Dispatches leo-cal:close.

mount(element, options?)

Fills an element with a booking card, exactly as if it had data-leo-cal-inline. Use it when you create the element yourself and want control over when the card appears:

const slot = document.querySelector('#booking-slot')
window.LeoCal.mount(slot, { sport: 'tennis' })

Mounting the same element twice is a no-op. Elements with data-leo-cal-inline that are on the page at load, or added to it afterwards, are mounted automatically — you only need mount for elements you want to fill by hand.

Events

All are dispatched on window as CustomEvents.

EventdetailWhen
leo-cal:booked{ reference, starts_at, ends_at }A booking was paid and confirmed.
leo-cal:change{ branch, sport, court, source, element }The customer picked a branch, sport or court.
leo-cal:opennoneThe pop-up opened.
leo-cal:closenoneThe pop-up closed, by any route.

In leo-cal:change, branch, sport and court are each { id, name } — what is selected now. source is 'card' or 'popup', and element is the card's data-leo-cal-inline element (null for the pop-up), so a page with several cards knows which one. It fires only for the customer's own choices, never for the widget following a changed data-sport.

window.addEventListener('leo-cal:booked', (event) => {
  const { reference, starts_at, ends_at } = event.detail
  // reference: the booking reference shown to the customer
  // starts_at / ends_at: ISO 8601 instants, with a timezone offset
})

leo-cal:booked fires after the payment is verified and the booking confirmed — not when the customer merely closes the payment window. A customer who abandons payment, or whose payment fails, does not trigger it.

Recipes

Google Analytics 4 purchase event

window.addEventListener('leo-cal:booked', (e) => {
  gtag('event', 'purchase', { transaction_id: e.detail.reference })
})

Meta Pixel

window.addEventListener('leo-cal:booked', () => fbq('track', 'Purchase'))

Send them to a thank-you page

window.addEventListener('leo-cal:booked', (e) => {
  window.location.href = `/thanks?ref=${encodeURIComponent(e.detail.reference)}`
})

Waiting until the customer presses Done is friendlier than redirecting the moment the event fires, since they have just been shown their confirmation. Listen for leo-cal:close after a booking if you want that:

let reference = null
window.addEventListener('leo-cal:booked', (e) => (reference = e.detail.reference))
window.addEventListener('leo-cal:close', () => {
  if (reference) window.location.href = `/thanks?ref=${encodeURIComponent(reference)}`
})

Hold the page still while the pop-up is open

The pop-up sets overflow: hidden on <html>, which a smooth-scroll library does not obey: a wheel over the dimmed backdrop would scroll the page behind it. Pause it, and anything else that moves or plays sound, between the two events:

window.addEventListener('leo-cal:open', () => { lenis.stop(); heroVideo.pause() })
window.addEventListener('leo-cal:close', () => { lenis.start(); heroVideo.play() })

Do not trust the event for anything that matters

leo-cal:booked is a message from a frame to your page, for analytics and for navigation. It is not proof of payment — anything on your page, including a visitor with the browser console open, can dispatch an event with that name. If you need to act on a booking (send a voucher, unlock something), confirm it on the server instead. The venue's dashboard is the source of truth.

Cards refresh themselves

When a booking is made in the pop-up, every card on the page is told, so a card stops offering the slot that was just sold without a page reload. You do not need to do anything for that.

Messages between the frames (for the curious)

Under the hood the frames and the loader talk with postMessage. These messages are internal and not a public contract — build on window.LeoCal and the events above, which are. For reference, the loader only accepts messages from its own origin and from frames it created, and the booking page only posts to the verified address of the page that embedded it, never to *.

On this page