| 1 |
(function () { |
| 2 |
function typoCssVarsForEl(typo, prefix, el) { |
| 3 |
if (!typo || typeof typo !== 'object') return; |
| 4 |
var map = { |
| 5 |
family:'font-family', weight:'font-weight', style:'font-style', |
| 6 |
decoration:'text-decoration', transform:'text-transform', |
| 7 |
sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m', |
| 8 |
lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m', |
| 9 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', |
| 10 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m' |
| 11 |
}; |
| 12 |
Object.keys(map).forEach(function(k) { |
| 13 |
if (typo[k] !== undefined && typo[k] !== '') { |
| 14 |
var v = typo[k]; |
| 15 |
if (['sizeDesktop','sizeTablet','sizeMobile'].indexOf(k) !== -1) v = v + (typo.sizeUnit || 'px'); |
| 16 |
else if (['lineHeightDesktop','lineHeightTablet','lineHeightMobile'].indexOf(k) !== -1) v = v + (typo.lineHeightUnit || ''); |
| 17 |
else if (['letterSpacingDesktop','letterSpacingTablet','letterSpacingMobile'].indexOf(k) !== -1) v = v + (typo.letterSpacingUnit || 'px'); |
| 18 |
else if (['wordSpacingDesktop','wordSpacingTablet','wordSpacingMobile'].indexOf(k) !== -1) v = v + (typo.wordSpacingUnit || 'px'); |
| 19 |
el.style.setProperty(prefix + map[k], String(v)); |
| 20 |
} |
| 21 |
}); |
| 22 |
} |
| 23 |
|
| 24 |
document.querySelectorAll('.bkbg-hs-app').forEach(function (app) { |
| 25 |
var opts = {}; |
| 26 |
try { opts = JSON.parse(app.getAttribute('data-opts') || '{}'); } catch (e) {} |
| 27 |
|
| 28 |
var textAlign = opts.textAlign || 'center'; |
| 29 |
|
| 30 |
var wrap = document.createElement('div'); |
| 31 |
wrap.className = 'bkbg-hs-wrap'; |
| 32 |
wrap.style.background = opts.bgColor || '#fff'; |
| 33 |
wrap.style.paddingTop = (opts.paddingTop || 100) + 'px'; |
| 34 |
wrap.style.paddingBottom = (opts.paddingBottom || 100) + 'px'; |
| 35 |
wrap.style.textAlign = textAlign; |
| 36 |
|
| 37 |
/* typo CSS vars on wrapper */ |
| 38 |
typoCssVarsForEl(opts.headingTypo, '--bkbg-hs-h-', wrap); |
| 39 |
typoCssVarsForEl(opts.subtextTypo, '--bkbg-hs-st-', wrap); |
| 40 |
typoCssVarsForEl(opts.ctaTypo, '--bkbg-hs-cta-', wrap); |
| 41 |
/* legacy fallback */ |
| 42 |
if (opts.headingSize && opts.headingSize !== 56) wrap.style.setProperty('--bkbg-hs-h-sz', opts.headingSize + 'px'); |
| 43 |
if (opts.headingFontWeight && opts.headingFontWeight !== '800') wrap.style.setProperty('--bkbg-hs-h-fw', opts.headingFontWeight); |
| 44 |
if (opts.headingLineHeight && opts.headingLineHeight !== 1.15) wrap.style.setProperty('--bkbg-hs-h-lh', String(opts.headingLineHeight)); |
| 45 |
if (opts.subtextSize && opts.subtextSize !== 20) wrap.style.setProperty('--bkbg-hs-st-sz', opts.subtextSize + 'px'); |
| 46 |
if (opts.subtextFontWeight && opts.subtextFontWeight !== '400') wrap.style.setProperty('--bkbg-hs-st-fw', opts.subtextFontWeight); |
| 47 |
if (opts.subtextLineHeight && opts.subtextLineHeight !== 1.6) wrap.style.setProperty('--bkbg-hs-st-lh', String(opts.subtextLineHeight)); |
| 48 |
if (opts.ctaFontSize && opts.ctaFontSize !== 16) wrap.style.setProperty('--bkbg-hs-cta-sz', opts.ctaFontSize + 'px'); |
| 49 |
if (opts.ctaFontWeight && opts.ctaFontWeight !== '600') wrap.style.setProperty('--bkbg-hs-cta-fw', opts.ctaFontWeight); |
| 50 |
|
| 51 |
// Background decorative word |
| 52 |
if (opts.showBgWord !== false && opts.bgWord) { |
| 53 |
var bgWord = document.createElement('div'); |
| 54 |
bgWord.className = 'bkbg-hs-bg-word'; |
| 55 |
bgWord.textContent = opts.bgWord; |
| 56 |
bgWord.style.fontSize = (opts.bgWordSize || 240) + 'px'; |
| 57 |
bgWord.style.fontWeight = opts.bgWordWeight || '900'; |
| 58 |
bgWord.style.color = opts.bgWordColor || 'rgba(0,0,0,0.05)'; |
| 59 |
wrap.appendChild(bgWord); |
| 60 |
} |
| 61 |
|
| 62 |
var inner = document.createElement('div'); |
| 63 |
inner.className = 'bkbg-hs-inner'; |
| 64 |
inner.style.maxWidth = (opts.maxWidth || 880) + 'px'; |
| 65 |
|
| 66 |
var heading = document.createElement('h2'); |
| 67 |
heading.className = 'bkbg-hs-heading'; |
| 68 |
heading.style.color = opts.headingColor || '#111827'; |
| 69 |
heading.innerHTML = opts.heading || ''; |
| 70 |
inner.appendChild(heading); |
| 71 |
|
| 72 |
if (opts.showSubtext !== false && opts.subtext) { |
| 73 |
var sub = document.createElement('p'); |
| 74 |
sub.className = 'bkbg-hs-subtext'; |
| 75 |
sub.style.color = opts.subtextColor || '#4b5563'; |
| 76 |
sub.innerHTML = opts.subtext; |
| 77 |
inner.appendChild(sub); |
| 78 |
} |
| 79 |
|
| 80 |
if (opts.showCta !== false && opts.ctaLabel) { |
| 81 |
var ctaWrap = document.createElement('div'); |
| 82 |
ctaWrap.className = 'bkbg-hs-cta-wrap bkbg-hs-cta-wrap--' + textAlign; |
| 83 |
|
| 84 |
var btn = document.createElement('a'); |
| 85 |
btn.className = 'bkbg-hs-cta-btn'; |
| 86 |
btn.href = opts.ctaUrl || '#'; |
| 87 |
btn.textContent = opts.ctaLabel; |
| 88 |
btn.style.background = opts.ctaBg || '#7c3aed'; |
| 89 |
btn.style.color = opts.ctaColor || '#ffffff'; |
| 90 |
|
| 91 |
if (opts.ctaOpenNewTab) { |
| 92 |
btn.target = '_blank'; |
| 93 |
btn.rel = 'noopener noreferrer'; |
| 94 |
} |
| 95 |
|
| 96 |
ctaWrap.appendChild(btn); |
| 97 |
inner.appendChild(ctaWrap); |
| 98 |
} |
| 99 |
|
| 100 |
wrap.appendChild(inner); |
| 101 |
app.parentNode.replaceChild(wrap, app); |
| 102 |
}); |
| 103 |
})(); |
| 104 |
|