Embedding
The script, the booking card, the pop-up, preselecting a sport or court, and placing it with your own CSS.
The script
One tag, once per page. It carries your browser key:
<script src="https://cal.turfleo.com/v1/embed.js" data-key="gxp_…" async></script>It is small, loads asynchronously, and does nothing until your page asks for a card or a pop-up. Pasting it twice is harmless — the second copy sees the first and stops.
The version is in the address
/v1/ is the loader's contract with your page — the attributes and events on this
page. Fixes ship to it without you changing anything; a breaking change would be a
/v2/, and /v1/ would keep working.
The booking card
A div with data-leo-cal-inline is filled with the booking form:
<div data-leo-cal-inline style="width: 380px"></div>The card is as wide as its div and as tall as its content — it measures itself and
resizes as the customer moves between steps, so there is no scrollbar to fight and no
fixed height to guess. Place the div with your own CSS:
/* floating over a hero image */
.hero { position: relative; }
.hero [data-leo-cal-inline] {
position: absolute;
top: 96px;
right: 36px;
width: 380px;
}
/* fixed to the corner of the screen */
.book-corner {
position: fixed;
right: 16px;
bottom: 16px;
width: 360px;
max-width: calc(100vw - 32px);
}On a narrow screen, give the div the width of the column (width: 100%) rather than a
fixed 380px.
When the customer picks a slot and presses Confirm & Pay, the card opens the pop-up on that exact slot for their details and the payment. Once they have paid, the card marks the slot as taken without a page reload.
The pop-up
Any element with data-leo-cal opens it when clicked — a button, a link, a menu item:
<button data-leo-cal>Book a court</button>
<a href="#book" data-leo-cal>Book now</a>It also works for elements your framework or page builder adds later; nothing needs re-initialising.
The pop-up closes with the ✕, by clicking the dimmed area, or with Esc, and returns focus to the button that opened it. While it is open the page behind it does not scroll. On a screen 520px wide or less it fills the whole screen instead of floating.
A sheet from the top
On a desktop the pop-up is a box in the middle of the page. To have it drop from the top
of the window instead — full width, like a menu — add data-popup="sheet" to the script
tag:
<script src="https://cal.turfleo.com/v1/embed.js" data-key="gxp_…"
data-popup="sheet" data-popup-header="#site-header" async></script>data-popup-header is optional: a CSS selector for your site's fixed header. The sheet
then slides in just under it, so your header — logo, menu, links — stays on top,
clickable, over a band of the sheet's paper. Your header needs a z-index for this, and
it is yours to restyle for the light background while the sheet is open:
window.addEventListener('leo-cal:open', () => header.classList.add('on-light'))
window.addEventListener('leo-cal:close', () => header.classList.remove('on-light'))A "Book" link in that header does nothing while the sheet is open, and if your header
opens a menu of its own, close the sheet first (LeoCal.close()) — the menu would
otherwise open underneath it.
A single button can choose for itself with data-popup="sheet" or data-popup="modal",
and LeoCal.open({ popup: 'sheet' }) does the same. A slot chosen on a
card always opens in the box, since it goes straight to the details.
Phones get the full screen either way.
Preselect a branch, sport or court
Both shapes accept the same attributes, to open on something specific rather than the venue's first sport:
| Attribute | Selects | Example |
|---|---|---|
data-branch | A branch, by name or id | data-branch="gandipet" |
data-sport | A sport, by name, slug or id | data-sport="football" |
data-court | A court, by name or id | data-court="court-1" |
Names are matched loosely — case and punctuation are ignored, so Table Tennis,
table-tennis and table_tennis all find the same sport. Part of a name works too:
cricket finds "Box Cricket", though a sport called exactly "Tennis" wins over "Table
Tennis" for tennis. Ids work as well, if you would rather not depend on a name.
<a href="#" data-leo-cal data-sport="football" data-branch="gandipet">Book football</a>
<div data-leo-cal-inline data-sport="tennis"></div>An attribute that matches nothing is ignored, and the widget opens on its default. The customer can still change sport, branch and court on the card — preselecting chooses where they start, not what they are allowed to book.
Changing a card's sport later
All three are optional, and on a card they can change after it has loaded. Set the attribute again and the card follows — a hero carousel can give the card each slide's sport, and in React a changing prop just works:
// a carousel moving to the next slide
document.querySelector('[data-leo-cal-inline]').dataset.sport = slide.sport<div data-leo-cal-inline data-sport={currentSport} />The card follows until the customer picks a branch, sport or court on it themselves; from
then on it is theirs, and later changes are ignored. That moment fires
leo-cal:change, so the page can follow the
customer instead — show the slide for the sport they chose, say. A sport the card's
branch doesn't have is ignored rather than moving the card to another branch.
The nearest branch
A venue with several branches can have the widget open on the one nearest the customer.
Give each branch a map position in the dashboard (Settings → Branches → a branch
→ Map position: on Google Maps, right-click the branch and copy the first line of
the menu, 17.392, 78.318). With two or more branches placed:
- The branch menu shows each branch's distance, marks the nearest, and offers Find my nearest branch.
- Location is asked for when the pop-up opens, or on the first tap on a card — never by itself as the page loads, which browsers flag and customers refuse. If the customer has already allowed location on your site, it is used straight away, with no prompt.
- The widget moves to the nearest branch only if nothing else has decided: not over a
data-branchordata-court, not over a branch the customer picked, and not once they have started choosing (a time picked at one branch is never swapped away). - What was found, and a branch picked by hand, are kept for the visit — every card and pop-up on every page of your site starts from them.
With no branch asked for and no location, the widget opens on the first branch that can take an online payment.
Several venues, one page?
data-key on a button or a card overrides the page's key for that one element, so a
site that promotes two venues can give each its own button. Each key opens its own
venue's courts.
Single-page apps and React
Load the script once, in index.html, not inside a component. Cards mount as soon as
their div renders; pop-ups open from any element with the attribute or from code:
export function BookingSection() {
return (
<section>
<div data-leo-cal-inline data-sport="football" className="booking-card" />
<button onClick={() => window.LeoCal?.open({ sport: 'football' })}>
Book a court
</button>
</section>
)
}window.LeoCal is added when the script has loaded, so use window.LeoCal?.open(…) —
a click before it arrives does nothing rather than throwing. The full list of functions
is in JavaScript API & events.
For TypeScript, tell the compiler about the global once:
declare global {
interface Window {
LeoCal?: {
open: (options?: { branch?: string; sport?: string; court?: string }) => void
close: () => void
mount: (element: HTMLElement, options?: { branch?: string; sport?: string; court?: string }) => void
version: string
}
}
}A booking link
The widget is also a page of its own, for places you cannot paste a script — an Instagram bio, a WhatsApp message, a QR code on a poster:
https://cal.turfleo.com/?key=gxp_…
https://cal.turfleo.com/?key=gxp_…&sport=football&branch=gandipetOpened directly there is no host page, so the website-address check does not apply: the page works from anywhere. Anyone with the link can book, exactly as they could from your website.
Content-Security-Policy
If your site sets a CSP, allow the script and the frame, both from one origin:
script-src https://cal.turfleo.com
frame-src https://cal.turfleo.comNothing else is needed. The payment window opens inside the Leo Cal frame, so the payment gateway's own scripts load there and your page's policy never sees them.
What the script does to your page
Only three things, so you know what you are inviting in:
- It adds an
iframeinside eachdata-leo-cal-inlineelement — once the element is displayed. A card you hide withdisplay: none(say, a desktop-only spot on a phone) loads nothing until it is shown. - When a pop-up is open it appends one full-screen overlay to
<body>and setsoverflow: hiddenon<html>, restoring it when the pop-up closes. A smooth-scroll library (Lenis, Locomotive) scrolls past that; pause it on theleo-cal:openandleo-cal:closeevents (JavaScript API). - It listens for clicks on
[data-leo-cal]and for messages from its own frames.
It adds no global styles and reads nothing from your page — not your forms, cookies or other scripts.