| 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 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', |
| 8 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m' |
| 9 |
}; |
| 10 |
function typoCssVarsForEl(el, obj, prefix) { |
| 11 |
if (!obj || typeof obj !== 'object') return; |
| 12 |
Object.keys(_typoKeys).forEach(function(k) { |
| 13 |
var v = obj[k]; |
| 14 |
if (v === undefined || v === '' || v === null) return; |
| 15 |
if (k === 'sizeDesktop' || k === 'sizeTablet' || k === 'sizeMobile') v = v + (obj.sizeUnit || 'px'); |
| 16 |
else if (k === 'lineHeightDesktop' || k === 'lineHeightTablet' || k === 'lineHeightMobile') v = v + (obj.lineHeightUnit || ''); |
| 17 |
else if (k === 'letterSpacingDesktop' || k === 'letterSpacingTablet' || k === 'letterSpacingMobile') v = v + (obj.letterSpacingUnit || 'px'); |
| 18 |
else if (k === 'wordSpacingDesktop' || k === 'wordSpacingTablet' || k === 'wordSpacingMobile') v = v + (obj.wordSpacingUnit || 'px'); |
| 19 |
el.style.setProperty(prefix + _typoKeys[k], String(v)); |
| 20 |
}); |
| 21 |
} |
| 22 |
|
| 23 |
function initScrollStickyContent(appEl) { |
| 24 |
var opts; |
| 25 |
try { opts = JSON.parse(appEl.getAttribute('data-opts') || '{}'); } catch(e) { opts = {}; } |
| 26 |
|
| 27 |
var a = { |
| 28 |
sectionTitle: opts.sectionTitle || 'Why Choose Us', |
| 29 |
sectionSubtitle: opts.sectionSubtitle || '', |
| 30 |
ctaLabel: opts.ctaLabel || 'Get Started', |
| 31 |
ctaUrl: opts.ctaUrl || '#', |
| 32 |
showCta: opts.showCta !== false, |
| 33 |
layout: opts.layout || 'left-sticky', |
| 34 |
stickyOffset: opts.stickyOffset || 80, |
| 35 |
features: opts.features || [], |
| 36 |
sectionBg: opts.sectionBg || '#0a0a0f', |
| 37 |
panelBg: opts.panelBg || '', |
| 38 |
textColor: opts.textColor || '#e2e8f0', |
| 39 |
headingColor: opts.headingColor || '#ffffff', |
| 40 |
accentColor: opts.accentColor || '#7c3aed', |
| 41 |
cardBg: opts.cardBg || '#111827', |
| 42 |
cardBorder: opts.cardBorder || '#1f2937', |
| 43 |
activeCardBg: opts.activeCardBg || '#1e1b4b', |
| 44 |
ctaBg: opts.ctaBg || '#7c3aed', |
| 45 |
ctaColor: opts.ctaColor || '#ffffff', |
| 46 |
paddingTop: opts.paddingTop || 80, |
| 47 |
paddingBottom: opts.paddingBottom || 80, |
| 48 |
titleSize: opts.titleSize || 42, |
| 49 |
subtitleSize: opts.subtitleSize || 18, |
| 50 |
cardIconSize: opts.cardIconSize || 36, |
| 51 |
cardTitleSize: opts.cardTitleSize || 20, |
| 52 |
cardDescSize: opts.cardDescSize || 15, |
| 53 |
lineConnector: opts.lineConnector !== false, |
| 54 |
animateCards: opts.animateCards !== false, |
| 55 |
threshold: opts.threshold || 0.45 |
| 56 |
}; |
| 57 |
|
| 58 |
var isRight = a.layout === 'right-sticky'; |
| 59 |
|
| 60 |
/* --- Section wrapper --- */ |
| 61 |
var section = document.createElement('section'); |
| 62 |
section.className = 'bkbg-ssc-section'; |
| 63 |
var cs = section.style; |
| 64 |
cs.setProperty('--bkbg-ssc-bg', a.sectionBg); |
| 65 |
cs.setProperty('--bkbg-ssc-pt', a.paddingTop + 'px'); |
| 66 |
cs.setProperty('--bkbg-ssc-pb', a.paddingBottom + 'px'); |
| 67 |
cs.setProperty('--bkbg-ssc-sticky-top', a.stickyOffset + 'px'); |
| 68 |
cs.setProperty('--bkbg-ssc-heading-color', a.headingColor); |
| 69 |
cs.setProperty('--bkbg-ssc-text-color', a.textColor); |
| 70 |
cs.setProperty('--bkbg-ssc-accent', a.accentColor); |
| 71 |
cs.setProperty('--bkbg-ssc-card-bg', a.cardBg); |
| 72 |
cs.setProperty('--bkbg-ssc-card-border', a.cardBorder); |
| 73 |
cs.setProperty('--bkbg-ssc-active-bg', a.activeCardBg); |
| 74 |
cs.setProperty('--bkbg-ssc-cta-bg', a.ctaBg); |
| 75 |
cs.setProperty('--bkbg-ssc-cta-color', a.ctaColor); |
| 76 |
cs.setProperty('--bkbg-ssc-title-size', a.titleSize + 'px'); |
| 77 |
cs.setProperty('--bkbg-ssc-subtitle-size', a.subtitleSize + 'px'); |
| 78 |
cs.setProperty('--bkbg-ssc-icon-size', a.cardIconSize + 'px'); |
| 79 |
cs.setProperty('--bkbg-ssc-card-title-size',a.cardTitleSize + 'px'); |
| 80 |
cs.setProperty('--bkbg-ssc-card-desc-size', a.cardDescSize + 'px'); |
| 81 |
|
| 82 |
typoCssVarsForEl(section, opts.headingTypo, '--bkssc-ht-'); |
| 83 |
typoCssVarsForEl(section, opts.subtitleTypo, '--bkssc-st-'); |
| 84 |
typoCssVarsForEl(section, opts.cardTitleTypo, '--bkssc-ct-'); |
| 85 |
typoCssVarsForEl(section, opts.cardDescTypo, '--bkssc-cd-'); |
| 86 |
|
| 87 |
var inner = document.createElement('div'); |
| 88 |
inner.className = 'bkbg-ssc-inner' + (isRight ? ' bkbg-ssc-right' : ''); |
| 89 |
|
| 90 |
/* --- Panel --- */ |
| 91 |
var panel = document.createElement('div'); |
| 92 |
panel.className = 'bkbg-ssc-panel'; |
| 93 |
if (a.panelBg) panel.style.background = a.panelBg; |
| 94 |
|
| 95 |
var heading = document.createElement('h2'); |
| 96 |
heading.className = 'bkbg-ssc-heading'; |
| 97 |
heading.textContent = a.sectionTitle; |
| 98 |
panel.appendChild(heading); |
| 99 |
|
| 100 |
if (a.sectionSubtitle) { |
| 101 |
var sub = document.createElement('p'); |
| 102 |
sub.className = 'bkbg-ssc-subtitle'; |
| 103 |
sub.textContent = a.sectionSubtitle; |
| 104 |
panel.appendChild(sub); |
| 105 |
} |
| 106 |
|
| 107 |
if (a.showCta && a.ctaLabel) { |
| 108 |
var cta = document.createElement('a'); |
| 109 |
cta.className = 'bkbg-ssc-cta'; |
| 110 |
cta.href = a.ctaUrl; |
| 111 |
cta.textContent = a.ctaLabel; |
| 112 |
panel.appendChild(cta); |
| 113 |
} |
| 114 |
|
| 115 |
/* --- Cards --- */ |
| 116 |
var cards = document.createElement('div'); |
| 117 |
cards.className = 'bkbg-ssc-cards' + (a.lineConnector ? ' bkbg-ssc-with-line' : ''); |
| 118 |
|
| 119 |
var cardEls = a.features.map(function(f) { |
| 120 |
var card = document.createElement('div'); |
| 121 |
card.className = 'bkbg-ssc-card' + (a.animateCards ? ' bkbg-ssc-animate-in' : ''); |
| 122 |
|
| 123 |
var iconEl = document.createElement('div'); |
| 124 |
iconEl.className = 'bkbg-ssc-card-icon'; |
| 125 |
var _IP = window.bkbgIconPicker; |
| 126 |
var _iType = f.iconType || 'custom-char'; |
| 127 |
if (_IP && _iType !== 'custom-char') { |
| 128 |
var _in = _IP.buildFrontendIcon(_iType, f.icon, f.iconDashicon, f.iconImageUrl, f.iconDashiconColor); |
| 129 |
if (_in) iconEl.appendChild(_in); else iconEl.textContent = f.icon || '⭐'; |
| 130 |
} else { iconEl.textContent = f.icon || '⭐'; } |
| 131 |
|
| 132 |
var body = document.createElement('div'); |
| 133 |
body.className = 'bkbg-ssc-card-body'; |
| 134 |
|
| 135 |
var title = document.createElement('div'); |
| 136 |
title.className = 'bkbg-ssc-card-title'; |
| 137 |
title.textContent = f.title; |
| 138 |
|
| 139 |
var desc = document.createElement('p'); |
| 140 |
desc.className = 'bkbg-ssc-card-desc'; |
| 141 |
desc.textContent = f.desc; |
| 142 |
|
| 143 |
body.appendChild(title); |
| 144 |
body.appendChild(desc); |
| 145 |
card.appendChild(iconEl); |
| 146 |
card.appendChild(body); |
| 147 |
cards.appendChild(card); |
| 148 |
return card; |
| 149 |
}); |
| 150 |
|
| 151 |
/* --- Layout --- */ |
| 152 |
if (isRight) { |
| 153 |
inner.appendChild(cards); |
| 154 |
inner.appendChild(panel); |
| 155 |
} else { |
| 156 |
inner.appendChild(panel); |
| 157 |
inner.appendChild(cards); |
| 158 |
} |
| 159 |
|
| 160 |
section.appendChild(inner); |
| 161 |
appEl.replaceWith(section); |
| 162 |
|
| 163 |
/* --- IntersectionObserver: highlight active card --- */ |
| 164 |
if ('IntersectionObserver' in window && cardEls.length > 0) { |
| 165 |
var activeCard = null; |
| 166 |
|
| 167 |
/* Animate-in observer */ |
| 168 |
if (a.animateCards) { |
| 169 |
var revealObs = new IntersectionObserver(function(entries) { |
| 170 |
entries.forEach(function(entry) { |
| 171 |
if (entry.isIntersecting) { |
| 172 |
entry.target.classList.remove('bkbg-ssc-animate-in'); |
| 173 |
entry.target.classList.add('bkbg-ssc-visible'); |
| 174 |
revealObs.unobserve(entry.target); |
| 175 |
} |
| 176 |
}); |
| 177 |
}, { threshold: 0.1 }); |
| 178 |
cardEls.forEach(function(c){ revealObs.observe(c); }); |
| 179 |
} |
| 180 |
|
| 181 |
/* Active-highlight observer */ |
| 182 |
var activeObs = new IntersectionObserver(function(entries) { |
| 183 |
entries.forEach(function(entry) { |
| 184 |
if (entry.isIntersecting) { |
| 185 |
if (activeCard) activeCard.classList.remove('bkbg-ssc-active'); |
| 186 |
entry.target.classList.add('bkbg-ssc-active'); |
| 187 |
activeCard = entry.target; |
| 188 |
} |
| 189 |
}); |
| 190 |
}, { threshold: a.threshold, rootMargin: '-15% 0px -15% 0px' }); |
| 191 |
|
| 192 |
/* Default first card active */ |
| 193 |
if (cardEls[0]) { |
| 194 |
cardEls[0].classList.add('bkbg-ssc-active'); |
| 195 |
cardEls[0].classList.remove('bkbg-ssc-animate-in'); |
| 196 |
cardEls[0].classList.add('bkbg-ssc-visible'); |
| 197 |
activeCard = cardEls[0]; |
| 198 |
} |
| 199 |
|
| 200 |
cardEls.forEach(function(c){ activeObs.observe(c); }); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
document.querySelectorAll('.bkbg-ssc-app').forEach(initScrollStickyContent); |
| 205 |
})(); |
| 206 |
|