| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function typoCssVarsForEl(typo, prefix, el) { |
| 5 |
if (!typo) return; |
| 6 |
if (typo.family) el.style.setProperty(prefix + 'font-family', "'" + typo.family + "', sans-serif"); |
| 7 |
if (typo.weight) el.style.setProperty(prefix + 'font-weight', typo.weight); |
| 8 |
if (typo.transform) el.style.setProperty(prefix + 'text-transform', typo.transform); |
| 9 |
if (typo.style) el.style.setProperty(prefix + 'font-style', typo.style); |
| 10 |
if (typo.decoration) el.style.setProperty(prefix + 'text-decoration', typo.decoration); |
| 11 |
var su = typo.sizeUnit || 'px'; |
| 12 |
if (typo.sizeDesktop !== '' && typo.sizeDesktop != null) el.style.setProperty(prefix + 'font-size-d', typo.sizeDesktop + su); |
| 13 |
if (typo.sizeTablet !== '' && typo.sizeTablet != null) el.style.setProperty(prefix + 'font-size-t', typo.sizeTablet + su); |
| 14 |
if (typo.sizeMobile !== '' && typo.sizeMobile != null) el.style.setProperty(prefix + 'font-size-m', typo.sizeMobile + su); |
| 15 |
var lhu = typo.lineHeightUnit || 'px'; |
| 16 |
if (typo.lineHeightDesktop !== '' && typo.lineHeightDesktop != null) el.style.setProperty(prefix + 'line-height-d', typo.lineHeightDesktop + lhu); |
| 17 |
if (typo.lineHeightTablet !== '' && typo.lineHeightTablet != null) el.style.setProperty(prefix + 'line-height-t', typo.lineHeightTablet + lhu); |
| 18 |
if (typo.lineHeightMobile !== '' && typo.lineHeightMobile != null) el.style.setProperty(prefix + 'line-height-m', typo.lineHeightMobile + lhu); |
| 19 |
var lsu = typo.letterSpacingUnit || 'px'; |
| 20 |
if (typo.letterSpacingDesktop !== '' && typo.letterSpacingDesktop != null) { el.style.setProperty(prefix + 'letter-spacing-d', typo.letterSpacingDesktop + lsu); el.style.setProperty(prefix + 'letter-spacing', typo.letterSpacingDesktop + lsu); } |
| 21 |
if (typo.letterSpacingTablet !== '' && typo.letterSpacingTablet != null) el.style.setProperty(prefix + 'letter-spacing-t', typo.letterSpacingTablet + lsu); |
| 22 |
if (typo.letterSpacingMobile !== '' && typo.letterSpacingMobile != null) el.style.setProperty(prefix + 'letter-spacing-m', typo.letterSpacingMobile + lsu); |
| 23 |
var wsu = typo.wordSpacingUnit || 'px'; |
| 24 |
if (typo.wordSpacingDesktop !== '' && typo.wordSpacingDesktop != null) { el.style.setProperty(prefix + 'word-spacing-d', typo.wordSpacingDesktop + wsu); el.style.setProperty(prefix + 'word-spacing', typo.wordSpacingDesktop + wsu); } |
| 25 |
if (typo.wordSpacingTablet !== '' && typo.wordSpacingTablet != null) el.style.setProperty(prefix + 'word-spacing-t', typo.wordSpacingTablet + wsu); |
| 26 |
if (typo.wordSpacingMobile !== '' && typo.wordSpacingMobile != null) el.style.setProperty(prefix + 'word-spacing-m', typo.wordSpacingMobile + wsu); |
| 27 |
} |
| 28 |
|
| 29 |
function initBlock(root) { |
| 30 |
var optsRaw = root.getAttribute('data-opts'); |
| 31 |
var opts; |
| 32 |
try { opts = JSON.parse(optsRaw); } catch (e) { opts = {}; } |
| 33 |
|
| 34 |
var minAge = opts.minimumAge || 18; |
| 35 |
var mode = opts.verificationMode || 'yesno'; |
| 36 |
var logoUrl = opts.logoUrl || ''; |
| 37 |
var confirmTx = opts.confirmText || 'Yes, I am old enough'; |
| 38 |
var denyTx = opts.denyText || 'No, take me back'; |
| 39 |
var denyUrl = opts.denyRedirectUrl || ''; |
| 40 |
var remDays = opts.rememberDays >= 0 ? opts.rememberDays : 30; |
| 41 |
var disclaimer = opts.disclaimer || ''; |
| 42 |
|
| 43 |
var STORAGE_KEY = 'bkbg_age_gate_' + (window.location.hostname || 'site'); |
| 44 |
|
| 45 |
// Check if already verified |
| 46 |
if (remDays > 0) { |
| 47 |
try { |
| 48 |
var stored = localStorage.getItem(STORAGE_KEY); |
| 49 |
if (stored) { |
| 50 |
var exp = parseInt(stored, 10); |
| 51 |
if (exp > Date.now()) { |
| 52 |
root.style.display = 'none'; // already verified |
| 53 |
return; |
| 54 |
} |
| 55 |
} |
| 56 |
} catch (e) {} |
| 57 |
} |
| 58 |
|
| 59 |
// Get content from saved rich text elements |
| 60 |
var titleSrc = root.querySelector('.bkbg-ag-title-src'); |
| 61 |
var messageSrc = root.querySelector('.bkbg-ag-message-src'); |
| 62 |
var titleHTML = titleSrc ? titleSrc.innerHTML : 'Age Verification Required'; |
| 63 |
var messageHTML = messageSrc ? messageSrc.innerHTML : ''; |
| 64 |
root.innerHTML = ''; // clear |
| 65 |
|
| 66 |
// Build overlay |
| 67 |
var overlay = document.createElement('div'); |
| 68 |
overlay.className = 'bkbg-ag-overlay'; |
| 69 |
overlay.style.background = opts.overlayBg || 'rgba(0,0,0,0.75)'; |
| 70 |
|
| 71 |
var card = document.createElement('div'); |
| 72 |
card.className = 'bkbg-ag-card'; |
| 73 |
card.style.cssText = [ |
| 74 |
'background:' + (opts.cardBg || '#ffffff'), |
| 75 |
'border-radius:' + (opts.cardRadius || 16) + 'px', |
| 76 |
'padding:' + (opts.cardPadding || 48) + 'px', |
| 77 |
'max-width:' + (opts.cardMaxWidth || 480) + 'px', |
| 78 |
'box-shadow:0 24px 64px rgba(0,0,0,0.3)', |
| 79 |
'width:100%', |
| 80 |
'box-sizing:border-box' |
| 81 |
].join(';'); |
| 82 |
|
| 83 |
overlay.appendChild(card); |
| 84 |
|
| 85 |
/* Typography CSS vars on card */ |
| 86 |
card.style.setProperty('--bkbg-ag-title-sz', (opts.titleSize || 26) + 'px'); |
| 87 |
card.style.setProperty('--bkbg-ag-message-sz', (opts.messageSize || 15) + 'px'); |
| 88 |
typoCssVarsForEl(opts.titleTypo, '--bkbg-ag-title-', card); |
| 89 |
typoCssVarsForEl(opts.messageTypo, '--bkbg-ag-message-', card); |
| 90 |
|
| 91 |
// Logo |
| 92 |
if (logoUrl) { |
| 93 |
var logo = document.createElement('img'); |
| 94 |
logo.src = logoUrl; |
| 95 |
logo.alt = 'Logo'; |
| 96 |
logo.className = 'bkbg-ag-logo'; |
| 97 |
logo.style.cssText = 'max-height:' + (opts.logoSize || 80) + 'px;margin:0 auto 20px;display:block;'; |
| 98 |
card.appendChild(logo); |
| 99 |
} |
| 100 |
|
| 101 |
// Title |
| 102 |
var titleEl = document.createElement('h3'); |
| 103 |
titleEl.className = 'bkbg-ag-title'; |
| 104 |
titleEl.innerHTML = titleHTML; |
| 105 |
titleEl.style.cssText = 'color:' + (opts.titleColor || '#1e1b4b') + ';margin:0 0 16px;'; |
| 106 |
card.appendChild(titleEl); |
| 107 |
|
| 108 |
// Message |
| 109 |
var msgEl = document.createElement('div'); |
| 110 |
msgEl.className = 'bkbg-ag-message'; |
| 111 |
msgEl.innerHTML = messageHTML; |
| 112 |
msgEl.style.cssText = 'color:' + (opts.messageColor || '#64748b') + ';margin:0 0 28px;line-height:1.6;'; |
| 113 |
card.appendChild(msgEl); |
| 114 |
|
| 115 |
// DOB input (if mode = dob) |
| 116 |
var dobInput = null; |
| 117 |
var dobError = null; |
| 118 |
if (mode === 'dob') { |
| 119 |
var dobWrap = document.createElement('div'); |
| 120 |
dobWrap.className = 'bkbg-ag-dob-wrap'; |
| 121 |
var dobLabel = document.createElement('label'); |
| 122 |
dobLabel.className = 'bkbg-ag-dob-label'; |
| 123 |
dobLabel.textContent = 'Date of Birth'; |
| 124 |
dobLabel.style.color = opts.messageColor || '#64748b'; |
| 125 |
dobInput = document.createElement('input'); |
| 126 |
dobInput.type = 'date'; |
| 127 |
dobInput.className = 'bkbg-ag-dob-input'; |
| 128 |
// Max date = today |
| 129 |
var today = new Date(); |
| 130 |
dobInput.max = today.toISOString().split('T')[0]; |
| 131 |
dobError = document.createElement('div'); |
| 132 |
dobError.className = 'bkbg-ag-dob-error'; |
| 133 |
dobError.textContent = 'You must be at least ' + minAge + ' years old to continue.'; |
| 134 |
dobWrap.appendChild(dobLabel); |
| 135 |
dobWrap.appendChild(dobInput); |
| 136 |
dobWrap.appendChild(dobError); |
| 137 |
card.appendChild(dobWrap); |
| 138 |
} |
| 139 |
|
| 140 |
// Buttons |
| 141 |
var btns = document.createElement('div'); |
| 142 |
btns.className = 'bkbg-ag-btns'; |
| 143 |
|
| 144 |
var confirmBtn = document.createElement('button'); |
| 145 |
confirmBtn.className = 'bkbg-ag-confirm-btn'; |
| 146 |
confirmBtn.textContent = confirmTx; |
| 147 |
confirmBtn.style.cssText = 'background:' + (opts.confirmBg || '#6366f1') + ';color:' + (opts.confirmColor || '#ffffff') + ';'; |
| 148 |
|
| 149 |
var denyBtn = document.createElement('button'); |
| 150 |
denyBtn.className = 'bkbg-ag-deny-btn'; |
| 151 |
denyBtn.textContent = denyTx; |
| 152 |
denyBtn.style.cssText = 'background:' + (opts.denyBg || '#f1f5f9') + ';color:' + (opts.denyColor || '#64748b') + ';'; |
| 153 |
|
| 154 |
btns.appendChild(confirmBtn); |
| 155 |
btns.appendChild(denyBtn); |
| 156 |
card.appendChild(btns); |
| 157 |
|
| 158 |
// Disclaimer |
| 159 |
if (disclaimer) { |
| 160 |
var discEl = document.createElement('p'); |
| 161 |
discEl.className = 'bkbg-ag-disclaimer'; |
| 162 |
discEl.textContent = disclaimer; |
| 163 |
discEl.style.color = opts.messageColor || '#64748b'; |
| 164 |
card.appendChild(discEl); |
| 165 |
} |
| 166 |
|
| 167 |
document.body.appendChild(overlay); |
| 168 |
document.body.style.overflow = 'hidden'; |
| 169 |
|
| 170 |
function grantAccess() { |
| 171 |
if (remDays > 0) { |
| 172 |
try { |
| 173 |
var exp = Date.now() + remDays * 24 * 60 * 60 * 1000; |
| 174 |
localStorage.setItem(STORAGE_KEY, String(exp)); |
| 175 |
} catch (e) {} |
| 176 |
} |
| 177 |
overlay.style.animation = 'bkbg-ag-fade-out 0.25s ease forwards'; |
| 178 |
setTimeout(function () { |
| 179 |
if (overlay.parentNode) overlay.parentNode.removeChild(overlay); |
| 180 |
document.body.style.overflow = ''; |
| 181 |
root.style.display = 'none'; |
| 182 |
}, 250); |
| 183 |
} |
| 184 |
|
| 185 |
function denyAccess() { |
| 186 |
if (denyUrl) { |
| 187 |
window.location.href = denyUrl; |
| 188 |
} else { |
| 189 |
window.history.back(); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
function checkAge() { |
| 194 |
if (mode === 'dob' && dobInput) { |
| 195 |
var dob = new Date(dobInput.value); |
| 196 |
if (!dobInput.value || isNaN(dob.getTime())) { |
| 197 |
if (dobError) { |
| 198 |
dobError.textContent = 'Please enter your date of birth.'; |
| 199 |
dobError.classList.add('bkbg-ag-visible'); |
| 200 |
} |
| 201 |
return; |
| 202 |
} |
| 203 |
var ageMs = Date.now() - dob.getTime(); |
| 204 |
var ageYears = ageMs / (365.25 * 24 * 60 * 60 * 1000); |
| 205 |
if (ageYears < minAge) { |
| 206 |
if (dobError) { |
| 207 |
dobError.textContent = 'You must be at least ' + minAge + ' years old to continue.'; |
| 208 |
dobError.classList.add('bkbg-ag-visible'); |
| 209 |
} |
| 210 |
return; |
| 211 |
} |
| 212 |
if (dobError) dobError.classList.remove('bkbg-ag-visible'); |
| 213 |
} |
| 214 |
grantAccess(); |
| 215 |
} |
| 216 |
|
| 217 |
confirmBtn.addEventListener('click', checkAge); |
| 218 |
denyBtn.addEventListener('click', denyAccess); |
| 219 |
if (dobInput) { |
| 220 |
dobInput.addEventListener('keydown', function (e) { |
| 221 |
if (e.key === 'Enter') checkAge(); |
| 222 |
}); |
| 223 |
} |
| 224 |
|
| 225 |
// Inject fade-out keyframe if needed |
| 226 |
var styleEl = document.getElementById('bkbg-ag-keyframes'); |
| 227 |
if (!styleEl) { |
| 228 |
styleEl = document.createElement('style'); |
| 229 |
styleEl.id = 'bkbg-ag-keyframes'; |
| 230 |
styleEl.textContent = '@keyframes bkbg-ag-fade-out{from{opacity:1}to{opacity:0}}'; |
| 231 |
document.head.appendChild(styleEl); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
document.querySelectorAll('.bkbg-ag-app').forEach(function (root) { |
| 236 |
initBlock(root); |
| 237 |
}); |
| 238 |
})(); |
| 239 |
|