| 1 |
(function () { |
| 2 |
function typoCssVarsForEl(typo, prefix, el) { |
| 3 |
if (!typo) return; |
| 4 |
if (typo.family) el.style.setProperty(prefix + 'font-family', "'" + typo.family + "', sans-serif"); |
| 5 |
if (typo.weight) el.style.setProperty(prefix + 'font-weight', typo.weight); |
| 6 |
if (typo.transform) el.style.setProperty(prefix + 'text-transform', typo.transform); |
| 7 |
if (typo.style) el.style.setProperty(prefix + 'font-style', typo.style); |
| 8 |
if (typo.decoration) el.style.setProperty(prefix + 'text-decoration', typo.decoration); |
| 9 |
var su = typo.sizeUnit || 'px'; |
| 10 |
if (typo.sizeDesktop !== '' && typo.sizeDesktop != null) el.style.setProperty(prefix + 'font-size-d', typo.sizeDesktop + su); |
| 11 |
if (typo.sizeTablet !== '' && typo.sizeTablet != null) el.style.setProperty(prefix + 'font-size-t', typo.sizeTablet + su); |
| 12 |
if (typo.sizeMobile !== '' && typo.sizeMobile != null) el.style.setProperty(prefix + 'font-size-m', typo.sizeMobile + su); |
| 13 |
var lhu = typo.lineHeightUnit || 'px'; |
| 14 |
if (typo.lineHeightDesktop !== '' && typo.lineHeightDesktop != null) el.style.setProperty(prefix + 'line-height-d', typo.lineHeightDesktop + lhu); |
| 15 |
if (typo.lineHeightTablet !== '' && typo.lineHeightTablet != null) el.style.setProperty(prefix + 'line-height-t', typo.lineHeightTablet + lhu); |
| 16 |
if (typo.lineHeightMobile !== '' && typo.lineHeightMobile != null) el.style.setProperty(prefix + 'line-height-m', typo.lineHeightMobile + lhu); |
| 17 |
var lsu = typo.letterSpacingUnit || 'px'; |
| 18 |
if (typo.letterSpacingDesktop !== '' && typo.letterSpacingDesktop != null) { |
| 19 |
el.style.setProperty(prefix + 'letter-spacing-d', typo.letterSpacingDesktop + lsu); |
| 20 |
el.style.setProperty(prefix + 'letter-spacing', typo.letterSpacingDesktop + lsu); |
| 21 |
} |
| 22 |
if (typo.letterSpacingTablet !== '' && typo.letterSpacingTablet != null) el.style.setProperty(prefix + 'letter-spacing-t', typo.letterSpacingTablet + lsu); |
| 23 |
if (typo.letterSpacingMobile !== '' && typo.letterSpacingMobile != null) el.style.setProperty(prefix + 'letter-spacing-m', typo.letterSpacingMobile + lsu); |
| 24 |
var wsu = typo.wordSpacingUnit || 'px'; |
| 25 |
if (typo.wordSpacingDesktop !== '' && typo.wordSpacingDesktop != null) { |
| 26 |
el.style.setProperty(prefix + 'word-spacing-d', typo.wordSpacingDesktop + wsu); |
| 27 |
el.style.setProperty(prefix + 'word-spacing', typo.wordSpacingDesktop + wsu); |
| 28 |
} |
| 29 |
if (typo.wordSpacingTablet !== '' && typo.wordSpacingTablet != null) el.style.setProperty(prefix + 'word-spacing-t', typo.wordSpacingTablet + wsu); |
| 30 |
if (typo.wordSpacingMobile !== '' && typo.wordSpacingMobile != null) el.style.setProperty(prefix + 'word-spacing-m', typo.wordSpacingMobile + wsu); |
| 31 |
} |
| 32 |
|
| 33 |
function init() { |
| 34 |
document.querySelectorAll('.bkbg-cup-app').forEach(function (el) { |
| 35 |
if (el.dataset.rendered) return; |
| 36 |
el.dataset.rendered = '1'; |
| 37 |
|
| 38 |
var opts; |
| 39 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 40 |
|
| 41 |
var o = Object.assign({ |
| 42 |
heading: '🎁 Free Bonus: Download the Checklist', |
| 43 |
description: 'Get the complete step-by-step checklist we use to implement everything covered in this article. Instant download, no spam.', |
| 44 |
imageUrl: '', imageAlt: '', style: 'boxed', |
| 45 |
formPlaceholder: 'Enter your email address', formSubmitLabel: 'Send Me the Checklist', |
| 46 |
formAction: '#', successMessage: '🎉 Check your inbox! The download is on its way.', |
| 47 |
paddingTop: 40, paddingBottom: 40, borderRadius: 12, |
| 48 |
accentColor: '#6366f1', bgColor: '#f5f3ff', borderColor: '#ddd6fe', |
| 49 |
headingColor: '#1e1b4b', descColor: '#4b5563', inputBg: '#ffffff', |
| 50 |
inputBorder: '#d1d5db', inputColor: '#111827', |
| 51 |
submitBg: '#6366f1', submitColor: '#ffffff' |
| 52 |
}, opts); |
| 53 |
|
| 54 |
var wrap = document.createElement('div'); |
| 55 |
wrap.className = 'bkbg-cup-wrap style-' + o.style; |
| 56 |
wrap.style.cssText = |
| 57 |
'padding:' + o.paddingTop + 'px 32px ' + o.paddingBottom + 'px;' + |
| 58 |
'background:' + (o.style === 'minimal' ? 'transparent' : o.bgColor) + ';' + |
| 59 |
'border-color:' + o.borderColor + ';' + |
| 60 |
'border-radius:' + (o.style === 'minimal' ? '0' : o.borderRadius + 'px') + ';' + |
| 61 |
(o.style === 'minimal' ? 'border-left-color:' + o.accentColor + ';' : ''); |
| 62 |
|
| 63 |
typoCssVarsForEl(o.typoHeading, '--bkcup-head-', wrap); |
| 64 |
typoCssVarsForEl(o.typoDesc, '--bkcup-desc-', wrap); |
| 65 |
|
| 66 |
/* Image column */ |
| 67 |
var imgCol; |
| 68 |
if (o.imageUrl) { |
| 69 |
imgCol = document.createElement('div'); |
| 70 |
imgCol.className = 'bkbg-cup-image-col'; |
| 71 |
var img = document.createElement('img'); |
| 72 |
img.src = o.imageUrl; img.alt = o.imageAlt; |
| 73 |
imgCol.appendChild(img); |
| 74 |
} else { |
| 75 |
imgCol = document.createElement('div'); |
| 76 |
imgCol.className = 'bkbg-cup-image-placeholder'; |
| 77 |
imgCol.style.background = o.accentColor + '22'; |
| 78 |
imgCol.textContent = '🎁'; |
| 79 |
} |
| 80 |
wrap.appendChild(imgCol); |
| 81 |
|
| 82 |
/* Content column */ |
| 83 |
var content = document.createElement('div'); |
| 84 |
content.className = 'bkbg-cup-content'; |
| 85 |
|
| 86 |
var heading = document.createElement('p'); |
| 87 |
heading.className = 'bkbg-cup-heading'; heading.style.color = o.headingColor; |
| 88 |
heading.innerHTML = o.heading; |
| 89 |
content.appendChild(heading); |
| 90 |
|
| 91 |
var desc = document.createElement('p'); |
| 92 |
desc.className = 'bkbg-cup-desc'; desc.style.color = o.descColor; |
| 93 |
desc.innerHTML = o.description; |
| 94 |
content.appendChild(desc); |
| 95 |
|
| 96 |
/* Form */ |
| 97 |
var form = document.createElement('form'); |
| 98 |
form.className = 'bkbg-cup-form'; |
| 99 |
form.action = o.formAction; form.method = 'post'; |
| 100 |
|
| 101 |
var input = document.createElement('input'); |
| 102 |
input.type = 'email'; input.name = 'email'; input.required = true; |
| 103 |
input.className = 'bkbg-cup-input'; input.placeholder = o.formPlaceholder; |
| 104 |
input.style.cssText = 'background:' + o.inputBg + ';border-color:' + o.inputBorder + ';color:' + o.inputColor; |
| 105 |
|
| 106 |
var submit = document.createElement('button'); |
| 107 |
submit.type = 'submit'; submit.className = 'bkbg-cup-submit'; |
| 108 |
submit.style.cssText = 'background:' + o.submitBg + ';color:' + o.submitColor; |
| 109 |
submit.textContent = o.formSubmitLabel; |
| 110 |
|
| 111 |
form.appendChild(input); form.appendChild(submit); |
| 112 |
content.appendChild(form); |
| 113 |
|
| 114 |
/* Success message */ |
| 115 |
var success = document.createElement('p'); |
| 116 |
success.className = 'bkbg-cup-success'; |
| 117 |
success.style.cssText = 'background:' + o.accentColor + '22;color:' + o.headingColor; |
| 118 |
success.textContent = o.successMessage; |
| 119 |
content.appendChild(success); |
| 120 |
|
| 121 |
form.addEventListener('submit', function (e) { |
| 122 |
if (o.formAction === '#' || o.formAction === '') { |
| 123 |
e.preventDefault(); |
| 124 |
form.style.display = 'none'; |
| 125 |
success.classList.add('visible'); |
| 126 |
} |
| 127 |
}); |
| 128 |
|
| 129 |
wrap.appendChild(content); |
| 130 |
el.appendChild(wrap); |
| 131 |
}); |
| 132 |
} |
| 133 |
|
| 134 |
if (document.readyState !== 'loading') { init(); } |
| 135 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 136 |
})(); |
| 137 |
|