Rail Pass Cards Embed
The Rail Pass Cards embed shows rail passes that your own code gives it, one card for each pass with its price in 2nd and 1st class.
It makes no API requests and needs no API key. You get the passes from the API wherever you make your own calls, and set them on the element. Use it when you already have the passes, or when the page can't hold an API key, such as a frame inside a chat app.
If you want an embed that fetches the passes and sells them through All Aboard's hosted checkout, use the Rail Pass List.
The cards are responsive and adapt to the user's screen size. Scroll down to see an example.
Getting started
First load the script. It is a standard JavaScript module, so the script tag needs type="module".
<script src="https://allaboard.eu/embed/aa-passes.js" type="module"></script>The script registers the custom element aa-passes. Add it to your page like any other HTML element.
<aa-passes></aa-passes>Then set its passBundles property from JavaScript.
const cards = document.querySelector('aa-passes')
cards.passBundles = passBundlesThe pass bundles
passBundles is an array of PassBundle objects, as getPassBundles returns them. A card can only show the fields it is given, so ask for the ones in this example.
query GetPassBundles {
getPassBundles(
passengers: [{ type: ADULT }, { type: YOUTH, age: 20 }]
filter: { product: "interrail-global-pass" }
) {
id
class
product
price {
amount
currency
}
travelDayCount
validityPeriod
passengers {
count
type
}
}
}The API returns a pass as one bundle for each class. The embed shows the two on one card, with a price for each. The cards are in the order their passes first appear in the array.
Below the cards, the embed says who the prices are for, such as "1× Adult pass, 1× Youth pass". It takes this from the passengers of the first bundle, so give it the bundles of one query at a time.
Prices are shown in the currency of the bundles. Use the currency argument of getPassBundles to choose it.
To change the list, set a new array. The embed doesn't notice a change made inside the array it already has.
Attributes
Set these attributes on the <aa-passes> element.
| Name | Description | Required |
|---|---|---|
passBundles |
The pass bundles to show. Set it as a property from JavaScript. As an attribute, it takes the same array as a JSON string. | Yes |
selectable |
Makes each price a button, so the user can select a pass in a class. See below for details. This is a boolean attribute: add it to show the buttons, and remove it to make the cards read-only. | No |
selected |
The id of the selected pass bundle. The embed sets it when the user selects a price. Set it yourself to show a price as selected, or remove it to clear the selection. It has no effect without selectable. |
No |
language |
The language of the cards: en (the default), da, de, es, fr, nb or sv. |
No |
theme |
The color theme: light (the default), dark, or auto, which follows the visitor's light or dark system setting. |
No |
Selecting a pass
Without selectable, the cards are read-only. With it, each price is a button. When the user clicks one, the embed emits aa-passes-select and shows that price as selected.
The embed doesn't open a checkout. Use the passBundleId from the event to create a booking in your own code.
const cards = document.querySelector('aa-passes')
cards.addEventListener('aa-passes-select', (event) => {
const { passBundleId } = event.detail
// Create a booking with the pass bundle
})Events
Listen for the Rail Pass Cards' event with addEventListener. It is only emitted with selectable.
| Name | Description |
|---|---|
aa-passes-select |
Emitted when the user selects a PassBundle. The event's detail has the passBundleId, which you can use to create a booking. |
Example
The demo gives the embed stored Interrail Global Pass bundles for one adult and one youth.