tvt-popup

  • public/js/tvt-popup.js
  • public/css/tvt-popup.css
  • resources/views/components/assets/tvt-popup.blade.php
  • resources/views/components/popups/popup-shell.blade.php
  • resources/views/components/popups/popup-campaigns.blade.php
  • resources/views/components/popups/popup-*.blade.php
  • app/View/DemoPopups.php
  • config/demo-popups.php

The promotional pop-ups of a page: a newsletter sign-up, a sale, later an announcement or a quiz. Each kind is a template, components/popups/popup-<template>, in the same shell (popups/popup-shell, a // MODAL of scripts.js); a campaign (config/demo-popups.php) gives it its texts, its pages, its audience, its period and its trigger.

Only one pop-up per visit, never while the visitor is busy (another modal, a menu, typing), not again until the browser is closed and opened again once closed, and never again once answered. On phones it is a bottom sheet, which leaves the top of the page visible.

1. Templates

Opened here as a preview ([data-tvt-popup-open="<id>"]): their rules and the browser's memory are left aside. Narrow the window below 768px to see the bottom sheet.

Black Friday sale

promo-countdown

A sale with a deadline on a dark photo: the discount in huge type, "off" outlined, a countdown whose numbers drop in, the three biggest discounts of the moment, a ribbon running across the bottom. At zero it shows that the sale is over.

Exit: price alert on the hotels viewed

exit-recover

When a visitor who opened hotels leaves the page: those hotels as bookmarks with a bell, and a price alert by e-mail. Shown only with hotels in tvt-viewed-hotels; this preview lists the first offers of the home page when there are none.

Newsletter: welcome discount

newsletter-split

The newsletter sign-up with a welcome discount: a title of light and black words, the e-mail and its button on one line, the kinds of trips, a photo with a diagonal edge and a swaying sticker. Once subscribed the card turns over and shows the code as a ticket, with a copy button.

Greece: early booking 2027

promo-fullbleed

A destination like a magazine cover: the photo fills the pop-up, the place's name runs huge across the top, blended into it, a tilted price tag, and at the bottom a title of light and black words, what is included as glass chips and the button.

Antalya: €150 off code

promo-boarding-pass

A promo code as a boarding pass: the route as two airport codes under a dashed arc, the passenger ("You"), the date, the gate and the seat; the code and a barcode on the stub, which tears off when the code is copied. The stub moves below on phones.

Scratch & save

promo-scratch

A scratch card: the prize, drawn on each load, hides under a silver canvas that the mouse or a finger scratches away, or a "Reveal" button for the keyboard. Past 45% the silver fades out and the code shows as a ticket.

Newsletter: postcard

newsletter-postcard

The newsletter as a postcard lying askew: "Greetings from" over the photo, a stamp and a postmark with today's date, the message in serif italics, the e-mail written on the address line. Once posted, a rubber stamp falls on the card, then it turns over to the code.

Quiz: where to next?

quiz-where-next

Three questions as big tiles, one at a time, with a progress bar; the answers pick the three best of 19 trips taken from the sections (countries, tours by plane or by coach, cruises), each tagged with its kind, its budget and who it suits.

Call me back

callback

A call back from a holiday expert, anonymous (photo with the online dot, role, rating): name, phone, what the trip is about and when to call as chips. On the page it opens from its launcher, the round button at the bottom right. Once sent, the photo with a ringing phone: "We will call you in 15 minutes about your cruise".

News: coach tours

announce-corner

An announcement in a corner card: no backdrop, the page stays usable, the focus stays where it is. Corner cards have their own turn, one per visit besides the modal pop-up.

Black Friday sale, ending in 15 s

promo-countdown

A sale with a deadline on a dark photo: the discount in huge type, "off" outlined, a countdown whose numbers drop in, the three biggest discounts of the moment, a ribbon running across the bottom. At zero it shows that the sale is over.

Open a pop-up.

2. On a page

A page that shows pop-ups names itself with popup="<page key>" on <x-master>, which renders popups/popup-campaigns once. App\View\DemoPopups::forPage() keeps the campaigns of that page whose audience and period match, highest priority first; each becomes a <template data-tvt-popup>, so nothing of it is loaded (images, form) until it shows. The home page (templates/home/home-1) has one campaign, the Black Friday sale after 5 s; the others have no page ('pages' => []) and are shown here only, or on any page with ?popup=<id>. With several campaigns on a page, the highest priority one of each trigger is armed and the first to fire is the visit's pop-up.

Blade
<x-master title="..." header="hero-img" popup="home">
config/demo-popups.php
'newsletter-welcome' => [
    'name' => 'Newsletter: welcome discount',
    'template' => 'newsletter-split',   // components/popups/popup-newsletter-split
    'pages' => ['home'],
    'audience' => 'guest',              // guest | logged | all
    'trigger' => 'delay',               // delay | scroll | exit | manual
    'delay' => 8,                       // seconds ('scroll' => 40: % of the page)
    'priority' => 10,                   // the higher first
    'starts_in_days' => null,           // from today, so the demo never goes stale
    'ends_in_days' => null,
    'content' => [ ... ],               // the template's texts and image
],

3. When it shows

The server keeps the rules it knows (page, audience, period); the browser those that need the visitor's memory (localStorage tvt-popups, sessionStorage tvt-popup-shown):

  • delay: after the seconds of delay; scroll: past scroll% of the page; exit: when the mouse leaves the window towards the tabs (desktop only); manual: only from a button.
  • One pop-up per visit: of the campaigns not closed in this browser session, the highest priority one of each trigger is armed and the first to fire wins; the others wait for another visit. Corner cards (popups/popup-corner-shell) have their own turn.
  • 'requires' => 'viewed': only for a visitor who has opened hotels (tvt-viewed-hotels). 'launcher' => '…': a round button at the bottom right opens it ([data-tvt-popup-launch]), not counted as the visit's pop-up.
  • Closed (×, backdrop, Esc, "Not now"): hidden until the browser is closed and opened again (a session cookie, tvt_popups_session, shared by the tabs). Answered (subscribed, its offer clicked, [data-tvt-popup-done]): never again (localStorage tvt-popups).
  • A busy visitor makes it wait: another modal, the mobile menu or a dropdown open, a field focused, the tab in the background. It tries again every 1.5 s.
  • The focus goes into the pop-up and stays there; it goes back where it was once closed.

4. URL parameters

  • ?popup=<campaign or template> on any page: that one, at once, as a preview (/?popup=newsletter-split).
  • ?popup=0: none on that page, e.g. to measure it in PageSpeed.
  • ?popup-reset=1: forgets the closed and answered pop-ups and the visit's one (/?popup-reset=1).
  • ?admin=1: the admin gets no pop-up by itself, but a cyan "Pop-ups" button at the bottom left that lists the campaigns of the page with their status and rules, and opens each one.

5. A new template

A file components/popups/popup-<name>.blade.php that takes campaign, its texts from $campaign['content'] and its labels as props, inside the shell. The behaviours come from attributes, so a template writes no script.

Blade
<x-popups.popup-shell :labelledby="$titleId" size="lg" tone="dark">
    <h2 id="...">...</h2>
    <form data-tvt-popup-form data-tvt-error-required="..." data-tvt-error-email="..." data-tvt-error-consent="...">...</form>
    <a href="..." data-tvt-popup-done>See the deals</a>
    <button type="button" data-tvt-dismiss="modal">Not now</button>
</x-popups.popup-shell>

Props, attributes, events, functions

<x-popups.popup-shell> / -corner-shell

  • popup-corner-shell: labelledby, close-label; no backdrop
  • labelledby: the id of the title
  • size: md (w-160) or lg (w-200), from md
  • tone: light or dark (the template paints its background)
  • close-label

Attributes inside a pop-up

  • data-tvt-popup-form, with data-tvt-error-required / -email / -consent
  • data-tvt-popup-flip with data-tvt-popup-face="front|back" (back inert), data-tvt-popup-success-focus
  • data-tvt-popup-done: answers it
  • data-tvt-popup-countdown="<ISO date>", data-tvt-popup-unit="d|h|m|s", data-tvt-popup-running / -expired
  • data-tvt-popup-on-done (class is-done once sent), data-tvt-popup-flip-delay, data-tvt-popup-fill="<field>"
  • data-tvt-popup-quiz with -step, -back, -progress, -results (data-show), -result data-tags, -restart; radios with data-weight
  • data-tvt-popup-viewed with -list, <template data-tvt-popup-viewed-item>, -name, -count, -input
  • data-tvt-popup-tear (with data-tvt-copy) inside a data-tvt-popup-stub: tears it off, answers it
  • data-tvt-popup-scratch with <canvas data-tvt-popup-scratch-canvas data-label>, data-tvt-popup-scratch-prize (aria-hidden until revealed), -reveal, -before / -after
  • data-tvt-dismiss="modal" closes a modal, data-tvt-dismiss="popup" a corner card

Events, functions

  • tvt:popup-show { id, preview }
  • tvt:popup-submit { id, form, data }: the backend sends it later
  • tvt:popup-reveal { id }: a scratch card; tvt:popup-quiz { id, answers }
  • tvt:popup-close { id, done }
  • tvtShowPopup(id, trigger?), tvtHidePopup(), tvtForgetPopups(id?)