| 1 |
(function () { |
| 2 |
var _typoKeys = { |
| 3 |
family: 'font-family', weight: 'font-weight', style: 'font-style', |
| 4 |
decoration: 'text-decoration', transform: 'text-transform', |
| 5 |
sizeDesktop: 'font-size-d', sizeTablet: 'font-size-t', sizeMobile: 'font-size-m', |
| 6 |
lineHeightDesktop: 'line-height-d', lineHeightTablet: 'line-height-t', lineHeightMobile: 'line-height-m', |
| 7 |
letterSpacing: 'letter-spacing', wordSpacing: 'word-spacing' |
| 8 |
}; |
| 9 |
function typoCssVarsForEl(el, typo, prefix) { |
| 10 |
if (!typo || typeof typo !== 'object') return; |
| 11 |
Object.keys(typo).forEach(function (k) { |
| 12 |
var v = typo[k]; if (v === '' || v == null) return; |
| 13 |
var css = _typoKeys[k]; if (!css) return; |
| 14 |
if ((k === 'letterSpacing' || k === 'wordSpacing') && typeof v === 'number') v = v + 'px'; |
| 15 |
if ((/^(sizeDesktop|sizeTablet|sizeMobile)$/).test(k) && typeof v === 'number') v = v + 'px'; |
| 16 |
el.style.setProperty(prefix + css, '' + v); |
| 17 |
}); |
| 18 |
} |
| 19 |
|
| 20 |
function init() { |
| 21 |
document.querySelectorAll('.bkbg-lwl-app').forEach(function (el) { |
| 22 |
if (el.dataset.rendered) return; |
| 23 |
el.dataset.rendered = '1'; |
| 24 |
|
| 25 |
var opts; |
| 26 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 27 |
|
| 28 |
var o = Object.assign({ |
| 29 |
badge: '🚀 Coming Soon', |
| 30 |
heading: 'Something Big Is Coming', |
| 31 |
subtext: 'Join the waitlist to get early access and an exclusive discount.', |
| 32 |
launchDate: '', |
| 33 |
showCountdown: true, |
| 34 |
formPlaceholder: 'Enter your email address', |
| 35 |
formSubmitLabel: 'Join the Waitlist', |
| 36 |
formAction: '', |
| 37 |
successMessage: '🎉 You\'re on the list! We\'ll be in touch soon.', |
| 38 |
benefits: [ |
| 39 |
{ text: 'Early access before public launch' }, |
| 40 |
{ text: 'Exclusive founding member discount' }, |
| 41 |
{ text: 'Shape the product with your feedback' } |
| 42 |
], |
| 43 |
showBenefits: true, |
| 44 |
socialProof: 'Join 1,200+ people already on the list', |
| 45 |
showSocialProof: true, |
| 46 |
layout: 'centered', |
| 47 |
bgColor: '#0f172a', |
| 48 |
accentColor: '#6366f1', |
| 49 |
headingColor: '#f8fafc', |
| 50 |
subColor: '#94a3b8', |
| 51 |
badgeBg: 'rgba(99,102,241,0.2)', |
| 52 |
badgeColor: '#a5b4fc', |
| 53 |
countdownBg: '#1e293b', |
| 54 |
countdownNumColor: '#f8fafc', |
| 55 |
countdownLabelColor: '#64748b', |
| 56 |
inputBg: '#1e293b', |
| 57 |
inputColor: '#f1f5f9', |
| 58 |
inputBorder: '#334155', |
| 59 |
submitBg: '#6366f1', |
| 60 |
submitColor: '#ffffff', |
| 61 |
benefitColor: '#cbd5e1', |
| 62 |
socialProofColor: '#64748b', |
| 63 |
maxWidth: 680, |
| 64 |
paddingTop: 100, |
| 65 |
paddingBottom: 100 |
| 66 |
}, opts); |
| 67 |
|
| 68 |
el.parentElement && (el.parentElement.style.background = o.bgColor); |
| 69 |
|
| 70 |
var isSplit = o.layout === 'split'; |
| 71 |
|
| 72 |
var inner = document.createElement('div'); |
| 73 |
inner.className = 'bkbg-lwl-inner layout-' + o.layout; |
| 74 |
inner.style.cssText = 'max-width:' + o.maxWidth + 'px;margin:0 auto;padding:' + o.paddingTop + 'px 24px ' + o.paddingBottom + 'px;'; |
| 75 |
|
| 76 |
typoCssVarsForEl(inner, o.headingTypo, '--bkbg-lwl-h-'); |
| 77 |
typoCssVarsForEl(inner, o.subtextTypo, '--bkbg-lwl-st-'); |
| 78 |
typoCssVarsForEl(inner, o.buttonTypo, '--bkbg-lwl-bt-'); |
| 79 |
|
| 80 |
/* Split grid wrapper */ |
| 81 |
var contentTarget = inner; |
| 82 |
var leftCol, rightCol; |
| 83 |
if (isSplit) { |
| 84 |
var splitGrid = document.createElement('div'); |
| 85 |
splitGrid.className = 'bkbg-lwl-split-grid'; |
| 86 |
|
| 87 |
leftCol = document.createElement('div'); |
| 88 |
rightCol = document.createElement('div'); |
| 89 |
splitGrid.appendChild(leftCol); |
| 90 |
splitGrid.appendChild(rightCol); |
| 91 |
inner.appendChild(splitGrid); |
| 92 |
} |
| 93 |
|
| 94 |
/* Badge */ |
| 95 |
var badge = document.createElement('div'); |
| 96 |
badge.className = 'bkbg-lwl-badge'; |
| 97 |
badge.style.cssText = 'background:' + o.badgeBg + ';color:' + o.badgeColor; |
| 98 |
badge.innerHTML = o.badge; |
| 99 |
(isSplit ? leftCol : inner).appendChild(badge); |
| 100 |
|
| 101 |
/* Heading */ |
| 102 |
var heading = document.createElement('h2'); |
| 103 |
heading.className = 'bkbg-lwl-heading'; |
| 104 |
heading.style.color = o.headingColor; |
| 105 |
heading.innerHTML = o.heading; |
| 106 |
(isSplit ? leftCol : inner).appendChild(heading); |
| 107 |
|
| 108 |
/* Subtext */ |
| 109 |
var sub = document.createElement('p'); |
| 110 |
sub.className = 'bkbg-lwl-sub'; |
| 111 |
sub.style.color = o.subColor; |
| 112 |
sub.innerHTML = o.subtext; |
| 113 |
(isSplit ? leftCol : inner).appendChild(sub); |
| 114 |
|
| 115 |
/* Countdown */ |
| 116 |
if (o.showCountdown) { |
| 117 |
var countdown = document.createElement('div'); |
| 118 |
countdown.className = 'bkbg-lwl-countdown'; |
| 119 |
|
| 120 |
var units = ['days', 'hours', 'mins', 'secs']; |
| 121 |
var unitEls = {}; |
| 122 |
|
| 123 |
units.forEach(function (u) { |
| 124 |
var box = document.createElement('div'); |
| 125 |
box.className = 'bkbg-lwl-unit'; |
| 126 |
box.style.background = o.countdownBg; |
| 127 |
|
| 128 |
var num = document.createElement('div'); |
| 129 |
num.className = 'bkbg-lwl-num'; |
| 130 |
num.style.color = o.countdownNumColor; |
| 131 |
num.textContent = '00'; |
| 132 |
|
| 133 |
var lbl = document.createElement('div'); |
| 134 |
lbl.className = 'bkbg-lwl-label'; |
| 135 |
lbl.style.color = o.countdownLabelColor; |
| 136 |
lbl.textContent = u.toUpperCase(); |
| 137 |
|
| 138 |
box.appendChild(num); |
| 139 |
box.appendChild(lbl); |
| 140 |
countdown.appendChild(box); |
| 141 |
unitEls[u] = num; |
| 142 |
}); |
| 143 |
|
| 144 |
/* Tick */ |
| 145 |
var endTime = o.launchDate ? new Date(o.launchDate).getTime() : (Date.now() + 14 * 86400000); |
| 146 |
|
| 147 |
function tick() { |
| 148 |
var now = Date.now(); |
| 149 |
var diff = Math.max(0, endTime - now); |
| 150 |
var d = Math.floor(diff / 86400000); |
| 151 |
var h = Math.floor((diff % 86400000) / 3600000); |
| 152 |
var m = Math.floor((diff % 3600000) / 60000); |
| 153 |
var s = Math.floor((diff % 60000) / 1000); |
| 154 |
unitEls.days.textContent = String(d).padStart(2, '0'); |
| 155 |
unitEls.hours.textContent = String(h).padStart(2, '0'); |
| 156 |
unitEls.mins.textContent = String(m).padStart(2, '0'); |
| 157 |
unitEls.secs.textContent = String(s).padStart(2, '0'); |
| 158 |
} |
| 159 |
tick(); |
| 160 |
setInterval(tick, 1000); |
| 161 |
|
| 162 |
(isSplit ? rightCol : inner).appendChild(countdown); |
| 163 |
} |
| 164 |
|
| 165 |
/* Form */ |
| 166 |
var formWrap = document.createElement('div'); |
| 167 |
formWrap.className = 'bkbg-lwl-form-wrap'; |
| 168 |
formWrap.style.borderColor = o.inputBorder; |
| 169 |
|
| 170 |
var input = document.createElement('input'); |
| 171 |
input.type = 'email'; |
| 172 |
input.className = 'bkbg-lwl-input'; |
| 173 |
input.placeholder = o.formPlaceholder; |
| 174 |
input.required = true; |
| 175 |
input.style.cssText = 'background:' + o.inputBg + ';color:' + o.inputColor; |
| 176 |
|
| 177 |
var submit = document.createElement('button'); |
| 178 |
submit.className = 'bkbg-lwl-submit'; |
| 179 |
submit.type = 'submit'; |
| 180 |
submit.style.cssText = 'background:' + o.submitBg + ';color:' + o.submitColor; |
| 181 |
submit.textContent = o.formSubmitLabel; |
| 182 |
|
| 183 |
var successDiv = document.createElement('div'); |
| 184 |
successDiv.className = 'bkbg-lwl-success'; |
| 185 |
successDiv.style.cssText = 'display:none;background:rgba(34,197,94,0.1);color:#86efac;border:1px solid rgba(34,197,94,0.2)'; |
| 186 |
successDiv.innerHTML = o.successMessage; |
| 187 |
|
| 188 |
submit.addEventListener('click', function (e) { |
| 189 |
e.preventDefault(); |
| 190 |
if (!input.value || !input.validity.valid) { |
| 191 |
input.style.outline = '2px solid #ef4444'; |
| 192 |
setTimeout(function () { input.style.outline = 'none'; }, 2000); |
| 193 |
return; |
| 194 |
} |
| 195 |
if (o.formAction) { |
| 196 |
var formData = new FormData(); |
| 197 |
formData.append('email', input.value); |
| 198 |
fetch(o.formAction, { method: 'POST', body: formData }).catch(function () {}); |
| 199 |
} |
| 200 |
formWrap.style.display = 'none'; |
| 201 |
successDiv.style.display = 'block'; |
| 202 |
}); |
| 203 |
|
| 204 |
formWrap.appendChild(input); |
| 205 |
formWrap.appendChild(submit); |
| 206 |
(isSplit ? rightCol : inner).appendChild(formWrap); |
| 207 |
(isSplit ? rightCol : inner).appendChild(successDiv); |
| 208 |
|
| 209 |
/* Benefits */ |
| 210 |
if (o.showBenefits && o.benefits && o.benefits.length) { |
| 211 |
var benefits = document.createElement('div'); |
| 212 |
benefits.className = 'bkbg-lwl-benefits'; |
| 213 |
|
| 214 |
o.benefits.forEach(function (b) { |
| 215 |
var item = document.createElement('span'); |
| 216 |
item.className = 'bkbg-lwl-benefit'; |
| 217 |
item.style.color = o.benefitColor; |
| 218 |
|
| 219 |
var check = document.createElement('em'); |
| 220 |
check.style.cssText = 'color:' + o.accentColor + ';font-style:normal;font-weight:700'; |
| 221 |
check.textContent = '✓'; |
| 222 |
|
| 223 |
item.appendChild(check); |
| 224 |
item.appendChild(document.createTextNode(' ' + b.text)); |
| 225 |
benefits.appendChild(item); |
| 226 |
}); |
| 227 |
|
| 228 |
(isSplit ? rightCol : inner).appendChild(benefits); |
| 229 |
} |
| 230 |
|
| 231 |
/* Social proof */ |
| 232 |
if (o.showSocialProof && o.socialProof) { |
| 233 |
var sp = document.createElement('p'); |
| 234 |
sp.className = 'bkbg-lwl-social-proof'; |
| 235 |
sp.style.color = o.socialProofColor; |
| 236 |
sp.textContent = o.socialProof; |
| 237 |
(isSplit ? rightCol : inner).appendChild(sp); |
| 238 |
} |
| 239 |
|
| 240 |
el.appendChild(inner); |
| 241 |
}); |
| 242 |
} |
| 243 |
|
| 244 |
if (document.readyState !== 'loading') { init(); } |
| 245 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 246 |
})(); |
| 247 |
|