Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Web Components are added to HTML as custom elements which look like regular HTML tags, e.g.:

Code Block
<rs-lottery-countdown>Loading...</rs-lottery-countdown>

Any text or HTML inside the tags is rendered as usual, until the component custom elements have been defined, at which point their content is replaced with the correct web component body.

...

Code Block
languagehtml
<body>
    <!-- Page body, including Rubiq Web Components, go here -->
    <rs-lottery-countdown loading-message="Please wait...">
        Please wait...
    </rs-lottery-countdown>

    <!-- Load/activate Web Components -->
    <script defer src="https://testapi.dialogportal.com/v1/components/lottery-online.js"></script>
</body>

Web Components

...

Code Block
languagehtml
<rs-lottery-countdown loading-message="henter aktiv lotteriet..."></rs-lottery-countdown>

Input set on element dynamically using JavaScript:

Code Block
function reserve(packageSize) {
    var cmpNumbers = document.querySelector('rs-lottery-package-numbers');
    cmpNumbers.setAttribute('package-size', packageSize);
}

...

Code Block
function onLottery(lotteryEvent) {
    console.log(lotteryEvent.detail.name);
}
var cmpCountdown = document.querySelector('rs-lottery-countdown');
cmpCountdown.addEventListener('lottery', onLottery);

...

lottery: All Lottery web components except <rs-lottery-purchase-failure> have a lottery event, which contains an object describing the active Lottery, or (in the case of <rs-lottery-puchasepurchase-success>) the Lottery that has just been purchased. The event contains these properties:

...

noActiveLottery: This event is emitted when no active Lottery is available.

<rs-lottery-countdown>

Fetches the currently active Lottery and displays a self-updating countdown:

...

loading-message: The message displayed while the active Lottery is being fetched from the API

<rs-lottery-quickdraw>

Fetches the currently active Lottery and if the quickdraw deadline has not passed, displays a message, e.g.:

“Hvis du spiller med inden d. 23/5 deltager du også i Hurtigtrækning om en ekstrapræmie på 1000”

<rs-lottery-package-numbers>

Requests a “package” of Lottery numbers and displays them. This component also has a button used to refresh the numbers.

...

Code Block
languagejs
var cmpNumbers = document.querySelector('rs-lottery-package-numbers');
console.log("ReservationID: " + cmpNumbers.reservation.id);

...

expired: Emitted with the reservation expires

<rs-lottery-purchase-details>

Presents a form for users to enter their details, in order to complete the purchase. Some of the inputs for this component are required; if any of reservationID, successUrl or failureUrl are missing, an error message will be displayed instead of the form.

...

reservationID: The ID of the reserved package that is being purchased. This should be retrieved from the <rs-lottery-package-numbers> component.

successUrl: The URL that the user should be redirected to after a successful purchase (should contain an <rs-lottery-purchase-success> component).

failureUrl: The URL that the user should be redirected to after they cancel a purchase (should contain an <rs-lottery-purchase-failure> component).

...

statusChanges: Emitted when the form validation state changes.

<rs-lottery-purchase-success>

To be used in a “success” page, the result of a purchase callback. The component reads the purchase order ID from the URL and completes the purchase. It also outputs the lottery and reservation details in events, allowing the details to be displayed.

...

  • size: Number of tickets purchased

  • price: Amount paid

<rs-lottery-purchase-failure>

To be used in a “failure” page, the result of an unsuccessful purchase callback. The component reads the purchase order ID from the URL and cancels the purchase.

...