/* * claim-modal.js - email popup for the free Creator Pitch Pack * (/creator-pitch-pack, added 2026-11-20). * * Chosen 2026-11-20 over Webflow's native Modal element: the native Modal * can only be opened by a Button element, so both Claim buttons (Button * component instances, i.e. links) would have to be rebuilt. With this script * they stay as they are. Build: directives/creator-pitch-pack-page-plan.md, * section 7. * * WHERE IT RUNS * Hosted like checkout-sliders: claim-modal.txt (an exact copy of this * file; Webflow Assets take no .js) is uploaded to Assets and loaded by one * script tag with src = the asset URL. The plan was the /creator-pitch-pack * page only; the published site loads it on every page (site Footer code, * seen 2026-11-24), which is fine: on a page without data-sw-modal it does * nothing. The CDN serves it as text/plain; browsers run it anyway, the * same way checkout-sliders.txt runs site-wide. * After any change: copy this file over claim-modal.txt, upload it again * and put the new asset URL into the script tag. * If it is ever pasted inline instead, this file must not contain a * closing script tag: the browser would end the script there. * * HOOKS (Webflow: Element settings → Custom attributes) * data-sw-open="claim" Any element; a click opens the popup. Goes on the * Div wrappers around both "Claim your free Pitch Pack" * buttons (a Button component instance takes no * attributes of its own). * data-sw-modal="claim" The dark overlay Div (class claim_modal) over the * whole screen. It is display: none in Webflow; the * script shows it with display: flex, which centers * the white box (class claim_modal-box) inside it. * The white box must be its first child: that is * the element that slides up. * data-sw-close="claim" The × in the right corner of the white box. * * OTHER POPUPS (since 2026-11-25) * The hooks work for any name, one popup per name. The Affiliate page * (/affiliate-program-landing-page) has the "apply" popup with Mia's * Apply Now form: data-sw-open="apply" on the Div wrappers around the * Apply Now buttons and on the Apply Now link inside the earnings * calculator embed, data-sw-modal="apply" on its overlay (a copy of the * claim popup, same classes), data-sw-close="apply" on its ×. * Only the "claim" form is sent to the SixWings API (THE FORM below). * Forms in other popups are left to Webflow: it sends them and shows its * own success block, and the notification emails are set on that Form * Block (Settings → Send to → Email notifications). Before 2026-11-25 the * script took over the form of ANY popup, so the Affiliate form would have * gone to the Pitch Pack API. * * WHAT IT DOES * Opens and closes the popup: on open the dark layer fades in and the white * box rises from below; on close both fade out and the box sinks a little. * With "reduce motion" turned on in the system the box does not move, it * only fades. Locks page scroll while the popup is open (and keeps the page * from shifting sideways where the scrollbar disappears). Puts the cursor * into the first field of the form (the email field in the claim popup, * First name in the apply popup), keeps Tab inside the popup, closes on Esc, on × and * on a click outside the white box, and gives focus back to the button that * opened it. * The hover effect of the × is plain CSS in Webflow, not part of this file. * * THE FORM (since 2026-11-23, spec from the SixWings dev via Mia; claim popup only) * The form inside the claim popup is a Webflow Form Block, but Webflow no longer * sends it: the script catches the submit before Webflow does and POSTs * JSON { email, toltReferral } to the SixWings API (CLAIM.endpoint below; * staging.sixwings.ai on every host except sixwings.ai). SixWings sends * the claim email and handles the affiliate attribution. * - toltReferral: window.tolt_referral from Tolt's tracker (site Head * code), after waiting for tolt.ready() at most 1 second, the same as * the paid checkout in checkout-sliders.js. Left out when there is none. * - While the request runs the button is disabled and shows its * "Please wait..." text (Webflow's data-wait). * - The answer appears in a message box the script adds right under the * form; the visitor stays on the page and the form stays visible. * 2xx (202): the API's message ("check your email for the claim link * and code"; repeat requests get the same one). * 400: the API's error, focus back in the email field to fix it. * 429: the API's error, the button stays disabled for Retry-After * seconds (readable only if the API exposes that header; otherwise * CLAIM.retryFallbackMs). * 503, other errors, network error, timeout: the API's error or a * generic text, the button is enabled again to retry. * - Webflow's own success and error blocks are no longer shown. * Reference wireframe only: window.SW_CLAIM_MOCK = '202' | '400' | '429' | * '503' | 'network' fakes the answer instead of calling the API. */ (function () { 'use strict'; var FOCUSABLE = 'a[href], button, input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])'; // Motion: the box rises 2.5rem on open (slow out, like it settles in place) // and sinks 1rem on close (quick). Times in ms var OPEN = { fade: 250, move: 450, from: '2.5rem', easing: 'cubic-bezier(.22, 1, .36, 1)' }; var CLOSE = { fade: 200, move: 200, to: '1rem', easing: 'cubic-bezier(.4, 0, 1, 1)' }; var REDUCED_FADE = 150; // Claim request. The production site talks to the live API, every other // host (sixwings-141e1e.webflow.io, local previews) to staging, like the // checkout in checkout-sliders.js var PRODUCTION_HOSTS = ['sixwings.ai', 'www.sixwings.ai']; var IS_PRODUCTION = PRODUCTION_HOSTS.indexOf(location.hostname) !== -1; var CLAIM = { // Production URL confirmed by the dev's full spec (2026-11-23); it accepts // requests from https://sixwings.ai. The staging one is our assumption, // same path as the checkout; not deployed there yet on 2026-11-23 (307) endpoint: IS_PRODUCTION ? 'https://app.sixwings.ai/api/promotions/pitch-pack' : 'https://staging.sixwings.ai/api/promotions/pitch-pack', timeoutMs: 15000, toltWaitMs: 1000, // 429 without a readable Retry-After header: keep the button off this long retryFallbackMs: 30000, // Used only when the API sends no text of its own successText: 'Check your email for your claim link and code.', errorText: 'Something went wrong. Please try again.' }; // Message box under the form. Error colours match checkout-sliders.js var CSS = '.sw-claim-msg{margin-top:.75rem;padding:.625rem .875rem;border-radius:8px;font-size:.875rem;line-height:1.4;text-align:left}' + '.sw-claim-msg.is-success{background:#eaf6ec;color:#1e5a2d}' + '.sw-claim-msg.is-error{background:#fff1e6;color:#a33100}'; function visible(el) { return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length); } function reducedMotion() { return !!(window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches); } function focusNoScroll(el) { try { el.focus({ preventScroll: true }); } catch (err) { el.focus(); } } // Page scroll lock. overflow: hidden on stops wheel, touch and // keyboard scrolling. Where the browser shows a classic scrollbar (Windows), // hiding it widens the page; padding on takes its place so nothing // jumps sideways. Overlay scrollbars (macOS, phones) give a gap of 0 var scrollLock = { on: false, overflow: '', padding: '' }; function lockScroll() { if (scrollLock.on) return; var html = document.documentElement; var body = document.body; var gap = window.innerWidth - html.clientWidth; scrollLock = { on: true, overflow: html.style.overflow, padding: body.style.paddingRight }; html.style.overflow = 'hidden'; if (gap > 0) body.style.paddingRight = (parseFloat(getComputedStyle(body).paddingRight) || 0) + gap + 'px'; } function unlockScroll() { if (!scrollLock.on) return; document.documentElement.style.overflow = scrollLock.overflow; document.body.style.paddingRight = scrollLock.padding; scrollLock.on = false; } function setup(modal) { var name = modal.getAttribute('data-sw-modal'); var closeSel = '[data-sw-close="' + name + '"]'; var box = modal.firstElementChild; // the white box (claim_modal-box) var isOpen = false; var returnFocus = null; // the Claim button that opened the popup var downOnOverlay = false; // mousedown started outside the white box var running = []; // animations in progress var motionTimer = null; // safety net in case the finish event is late modal.setAttribute('role', 'dialog'); modal.setAttribute('aria-modal', 'true'); modal.setAttribute('aria-hidden', 'true'); // Scrolling inside a tall box (small phone in landscape) stops at its edge // instead of passing on to the page modal.style.overscrollBehavior = 'contain'; if (box) box.style.overscrollBehavior = 'contain'; // The × is a Div with an icon in Webflow: make it a keyboard-reachable button Array.prototype.forEach.call(modal.querySelectorAll(closeSel), function (btn) { btn.setAttribute('role', 'button'); btn.setAttribute('tabindex', '0'); if (!btn.getAttribute('aria-label')) btn.setAttribute('aria-label', 'Close'); }); function focusables() { return Array.prototype.filter.call(modal.querySelectorAll(FOCUSABLE), visible); } // Name the dialog after its first visible heading: the intro line before // submit, the thank-you heading after it function label() { var heads = modal.querySelectorAll('h1, h2, h3, h4, h5, h6'); for (var i = 0; i < heads.length; i++) { if (visible(heads[i])) { if (!heads[i].id) heads[i].id = 'sw-' + name + '-title-' + i; modal.setAttribute('aria-labelledby', heads[i].id); return; } } } // Stop whatever is still running (a quick reopen during the close fade) function stopMotion() { clearTimeout(motionTimer); running.forEach(function (a) { a.onfinish = null; a.cancel(); }); running = []; } // Fade the dark layer and move the white box. then() runs when the // longest animation ends; without Web Animations it runs at once function animate(opening, then) { stopMotion(); if (!modal.animate) { if (then) then(); return; } var reduce = reducedMotion(); var spec = opening ? OPEN : CLOSE; var fade = reduce ? REDUCED_FADE : spec.fade; var opts = function (ms, easing) { return { duration: ms, easing: easing, fill: 'both' }; }; running.push(modal.animate( [{ opacity: opening ? 0 : 1 }, { opacity: opening ? 1 : 0 }], opts(fade, 'ease') )); if (box && !reduce) { running.push(box.animate( opening ? [{ transform: 'translateY(' + spec.from + ')' }, { transform: 'translateY(0)' }] : [{ transform: 'translateY(0)' }, { transform: 'translateY(' + spec.to + ')' }], opts(spec.move, spec.easing) )); } var longest = running.reduce(function (a, b) { return b.effect.getTiming().duration > a.effect.getTiming().duration ? b : a; }); // Drop the animations so the Webflow styles apply again. Runs once: // whichever comes first clears the other var done = function () { stopMotion(); if (then) then(); }; longest.onfinish = done; // A busy or throttled tab can deliver the finish event late; without // this an invisible closing layer could keep blocking the page motionTimer = setTimeout(done, longest.effect.getTiming().duration + 150); } function open(from) { if (isOpen) return; isOpen = true; returnFocus = from; lockScroll(); modal.style.display = 'flex'; modal.setAttribute('aria-hidden', 'false'); label(); animate(true); // First field of the form (claim: email, apply: First name); after a // successful submit the form is hidden, then the × var input = Array.prototype.filter.call( modal.querySelectorAll('input:not([type="hidden"]):not([type="submit"]), textarea, select'), visible )[0]; var target = input || modal.querySelector(closeSel) || focusables()[0]; if (target) focusNoScroll(target); } function close() { if (!isOpen) return; isOpen = false; modal.setAttribute('aria-hidden', 'true'); if (returnFocus && returnFocus.focus) focusNoScroll(returnFocus); // Hide and give the page its scroll back only after the fade, so the // scrollbar does not come back while the popup is still on screen animate(false, function () { modal.style.display = 'none'; unlockScroll(); }); } // A text selection dragged from the field onto the overlay must not close it modal.addEventListener('mousedown', function (e) { downOnOverlay = e.target === modal; }); document.addEventListener('click', function (e) { var opener = e.target.closest('[data-sw-open="' + name + '"]'); if (opener) { e.preventDefault(); // the Claim buttons link to "#" open(opener.matches(FOCUSABLE) ? opener : opener.querySelector(FOCUSABLE) || opener); return; } if (!isOpen) return; if (e.target.closest(closeSel) || (e.target === modal && downOnOverlay)) { e.preventDefault(); close(); } }); document.addEventListener('keydown', function (e) { if (!isOpen) return; if (e.key === 'Escape') { close(); return; } if ((e.key === 'Enter' || e.key === ' ') && e.target.closest && e.target.closest(closeSel)) { e.preventDefault(); close(); return; } if (e.key === 'Tab') { // Keep keyboard focus inside the popup var items = focusables(); if (!items.length) return; var first = items[0]; var last = items[items.length - 1]; if (!modal.contains(document.activeElement)) { e.preventDefault(); first.focus(); } else if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); } else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); } } }); // Only the claim form goes to the SixWings API. Any other popup form // (Affiliate "apply") is sent by Webflow itself, so it is not touched var form = modal.querySelector('form'); if (form && name === 'claim') setupForm(form); } // ------------------------------------------------------------------ // The claim form: sent to the SixWings API instead of Webflow // ------------------------------------------------------------------ // Resolves with the Tolt referral id, or '' when there is none. Waits for // the tracker at most CLAIM.toltWaitMs. Never rejects. Same logic as in // checkout-sliders.js function toltReferral() { var tolt = window.tolt; var wait = tolt && typeof tolt.ready === 'function' ? Promise.race([ Promise.resolve().then(function () { return tolt.ready(); }), new Promise(function (resolve) { setTimeout(resolve, CLAIM.toltWaitMs); }) ]).catch(function () {}) : Promise.resolve(); return wait.then(function () { // Dev's spec: a string only, trimmed, and at most 500 characters; // anything else is left out and the request goes without it var ref = window.tolt_referral; ref = typeof ref === 'string' ? ref.trim() : ''; return ref.length <= 500 ? ref : ''; }); } // Retry-After is either seconds or an HTTP date; 0 when missing or unreadable function retryAfterMs(value) { if (!value) return 0; var seconds = Number(value); if (isFinite(seconds)) return Math.max(0, seconds * 1000); var at = Date.parse(value); return isNaN(at) ? 0 : Math.max(0, at - Date.now()); } // Resolves with { status, data, retryAfter }; status 0 = network error or // timeout. Never rejects function requestClaim(body) { var mock = window.SW_CLAIM_MOCK; if (mock) return mockClaim(String(mock), body); var ctrl = typeof AbortController === 'function' ? new AbortController() : null; var timer = ctrl ? setTimeout(function () { ctrl.abort(); }, CLAIM.timeoutMs) : null; return fetch(CLAIM.endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'omit', body: JSON.stringify(body), signal: ctrl ? ctrl.signal : undefined }) .then(function (res) { return res.json().catch(function () { return {}; }).then(function (data) { return { status: res.status, data: data || {}, retryAfter: res.headers.get('Retry-After') }; }); }, function () { return { status: 0, data: {} }; }) .then(function (result) { if (timer) clearTimeout(timer); return result; }); } // Reference wireframe only: fake answers, the success one shows what was sent function mockClaim(mock, body) { return new Promise(function (resolve) { setTimeout(function () { var sent = 'Mock: POST ' + CLAIM.endpoint + ' ' + JSON.stringify(body); if (mock === '202') resolve({ status: 202, data: { message: 'Check your email for your claim link and code. (' + sent + ')' } }); else if (mock === '400') resolve({ status: 400, data: { error: 'Please enter a valid email address.' } }); else if (mock === '429') resolve({ status: 429, data: { error: 'Too many requests. Please try again in 10 seconds.' }, retryAfter: '10' }); else if (mock === '503') resolve({ status: 503, data: { error: 'The service is busy. Please try again.' } }); else resolve({ status: 0, data: {} }); }, 700); }); } function setupForm(form) { var input = form.querySelector('input[type="email"]'); var submit = form.querySelector('[type="submit"]'); var isInput = submit && submit.tagName === 'INPUT'; var idleText = submit ? (isInput ? submit.value : submit.textContent) : ''; var waitText = (submit && submit.getAttribute('data-wait')) || idleText; var busy = false; var cooldown = null; // timer of the 429 wait // Message box right under the form; polite live region for screen readers var msg = document.createElement('div'); msg.className = 'sw-claim-msg'; msg.setAttribute('role', 'status'); msg.setAttribute('aria-live', 'polite'); msg.style.display = 'none'; form.parentNode.insertBefore(msg, form.nextSibling); function show(text, kind) { msg.textContent = text || ''; msg.className = 'sw-claim-msg' + (kind ? ' is-' + kind : ''); msg.style.display = text ? '' : 'none'; } function setButton(disabled, text) { if (!submit) return; submit.disabled = disabled; if (isInput) submit.value = text; else submit.textContent = text; } function textOf(value) { return typeof value === 'string' && value.trim() ? value.trim() : ''; } function handle(result) { busy = false; var data = result.data || {}; if (result.status >= 200 && result.status < 300) { setButton(false, idleText); show(textOf(data.message) || CLAIM.successText, 'success'); return; } show(textOf(data.error) || CLAIM.errorText, 'error'); if (result.status === 429) { // Wait as long as the API asks before the next try setButton(true, idleText); clearTimeout(cooldown); cooldown = setTimeout(function () { setButton(false, idleText); }, retryAfterMs(result.retryAfter) || CLAIM.retryFallbackMs); return; } setButton(false, idleText); // 400: the email was not accepted, let the visitor fix it if (result.status === 400 && input) input.focus(); } // Capture phase on window runs before Webflow's own form handler (it // listens on document) and before anything on the form itself. Stopping // the event there keeps Webflow from sending the form; preventDefault // stops the browser's plain GET submit. The browser has already checked // the required email field by the time submit fires window.addEventListener('submit', function (e) { if (e.target !== form) return; e.preventDefault(); e.stopPropagation(); if (busy || (submit && submit.disabled)) return; busy = true; show(''); setButton(true, waitText); var body = { email: input ? input.value.trim() : '' }; toltReferral().then(function (ref) { if (ref) body.toltReferral = ref; return requestClaim(body); }).then(handle); }, true); } function init() { // Site-wide loading is fine: pages without the popup are left alone if (!document.querySelector('[data-sw-modal]')) return; if (!document.getElementById('sw-claim-style')) { var style = document.createElement('style'); style.id = 'sw-claim-style'; style.textContent = CSS; document.head.appendChild(style); } Array.prototype.forEach.call(document.querySelectorAll('[data-sw-modal]'), setup); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init(); })();