| 1 |
wp.domReady(function () { |
| 2 |
function typoCssVarsForEl(typo, prefix, el) { |
| 3 |
if (!typo || typeof typo !== 'object') return; |
| 4 |
var m = { |
| 5 |
family: 'font-family', weight: 'font-weight', |
| 6 |
transform: 'text-transform', style: 'font-style', decoration: 'text-decoration' |
| 7 |
}; |
| 8 |
Object.keys(m).forEach(function (k) { |
| 9 |
if (typo[k]) el.style.setProperty(prefix + m[k], typo[k]); |
| 10 |
}); |
| 11 |
var r = { |
| 12 |
size: 'font-size', lineHeight: 'line-height', |
| 13 |
letterSpacing: 'letter-spacing', wordSpacing: 'word-spacing' |
| 14 |
}; |
| 15 |
Object.keys(r).forEach(function (k) { |
| 16 |
['Desktop', 'Tablet', 'Mobile'].forEach(function (d, i) { |
| 17 |
var v = typo[k + d]; |
| 18 |
if (v === undefined || v === '') return; |
| 19 |
var suffix = ['-d', '-t', '-m'][i]; |
| 20 |
var unit = typo[k + 'Unit'] || ('size' === k ? 'px' : (k === 'lineHeight' ? '' : 'px')); |
| 21 |
el.style.setProperty(prefix + r[k] + suffix, v + unit); |
| 22 |
}); |
| 23 |
}); |
| 24 |
} |
| 25 |
|
| 26 |
document.querySelectorAll('.bkbg-faqs-app').forEach(function (el) { |
| 27 |
var a = JSON.parse(el.dataset.opts || '{}'); |
| 28 |
var items = a.items || []; |
| 29 |
var isSplit = a.layout === 'split'; |
| 30 |
var isTwoCol = a.layout === 'two-column'; |
| 31 |
var openItems = a.expandFirst ? [0] : []; |
| 32 |
|
| 33 |
/* === Wrap === */ |
| 34 |
var wrap = document.createElement('div'); |
| 35 |
wrap.className = 'bkbg-faqs-wrap'; |
| 36 |
wrap.style.background = a.bgColor || '#ffffff'; |
| 37 |
wrap.style.paddingTop = (a.paddingTop || 80) + 'px'; |
| 38 |
wrap.style.paddingBottom = (a.paddingBottom || 80) + 'px'; |
| 39 |
typoCssVarsForEl(a.typoEyebrow, '--bkbg-fsec-eb-', wrap); |
| 40 |
typoCssVarsForEl(a.typoHeading, '--bkbg-fsec-hd-', wrap); |
| 41 |
typoCssVarsForEl(a.typoSubtext, '--bkbg-fsec-st-', wrap); |
| 42 |
typoCssVarsForEl(a.typoQuestion, '--bkbg-fsec-qt-', wrap); |
| 43 |
typoCssVarsForEl(a.typoAnswer, '--bkbg-fsec-an-', wrap); |
| 44 |
|
| 45 |
/* === Inner === */ |
| 46 |
var inner = document.createElement('div'); |
| 47 |
inner.style.maxWidth = (a.maxWidth || 800) + 'px'; |
| 48 |
inner.style.margin = '0 auto'; |
| 49 |
inner.style.padding = '0 20px'; |
| 50 |
if (isSplit) { inner.className = 'bkbg-faqs-inner--split'; inner.style.maxWidth = '1100px'; } |
| 51 |
if (isTwoCol) { inner.className = 'bkbg-faqs-inner--two-column'; } |
| 52 |
|
| 53 |
/* === Header === */ |
| 54 |
var header = document.createElement('div'); |
| 55 |
header.className = 'bkbg-faqs-header'; |
| 56 |
if (!isSplit) { header.style.textAlign = 'center'; } |
| 57 |
|
| 58 |
if (a.showEyebrow && a.eyebrow) { |
| 59 |
var eyebrow = document.createElement('span'); |
| 60 |
eyebrow.className = 'bkbg-faqs-eyebrow'; |
| 61 |
eyebrow.style.cssText = 'display:inline-block;background:' + (a.eyebrowBg || '#f3f0ff') + ';color:' + (a.eyebrowColor || '#7c3aed') + ';padding:4px 14px;border-radius:999px;margin-bottom:16px;'; |
| 62 |
eyebrow.innerHTML = a.eyebrow; |
| 63 |
header.appendChild(eyebrow); |
| 64 |
} |
| 65 |
|
| 66 |
var heading = document.createElement('h2'); |
| 67 |
heading.className = 'bkbg-faqs-heading'; |
| 68 |
heading.style.cssText = 'color:' + (a.headingColor || '#111827') + ';margin:0 0 16px;'; |
| 69 |
heading.innerHTML = a.heading || 'Frequently Asked Questions'; |
| 70 |
header.appendChild(heading); |
| 71 |
|
| 72 |
if (a.showSubtext && a.subtext) { |
| 73 |
var sub = document.createElement('p'); |
| 74 |
sub.className = 'bkbg-faqs-subtext'; |
| 75 |
sub.style.cssText = 'color:' + (a.subtextColor || '#6b7280') + ';max-width:560px;margin:' + (isSplit ? '0' : '0 auto') + ';'; |
| 76 |
sub.innerHTML = a.subtext; |
| 77 |
header.appendChild(sub); |
| 78 |
} |
| 79 |
|
| 80 |
/* === Accordion === */ |
| 81 |
var accordion = document.createElement('div'); |
| 82 |
accordion.className = 'bkbg-faqs-accordion'; |
| 83 |
|
| 84 |
/* Icon helper */ |
| 85 |
function makeIcon(open) { |
| 86 |
var span = document.createElement('span'); |
| 87 |
span.className = 'bkbg-faqs-icon bkbg-faqs-icon--' + (a.iconType || 'chevron'); |
| 88 |
span.style.color = a.iconColor || '#7c3aed'; |
| 89 |
if (a.iconType === 'plus') { |
| 90 |
span.textContent = open ? '−' : '+'; |
| 91 |
span.style.fontSize = '20px'; |
| 92 |
} else if (a.iconType === 'arrow') { |
| 93 |
span.textContent = '→'; |
| 94 |
span.style.fontSize = '14px'; |
| 95 |
if (open) { span.style.transform = 'rotate(90deg)'; } |
| 96 |
} else { |
| 97 |
span.textContent = '▾'; |
| 98 |
span.style.fontSize = '14px'; |
| 99 |
if (open) { span.style.transform = 'rotate(180deg)'; } |
| 100 |
} |
| 101 |
return span; |
| 102 |
} |
| 103 |
|
| 104 |
var itemEls = []; |
| 105 |
|
| 106 |
items.forEach(function (item, idx) { |
| 107 |
var isOpen = openItems.indexOf(idx) !== -1; |
| 108 |
|
| 109 |
var itemEl = document.createElement('div'); |
| 110 |
itemEl.className = 'bkbg-faqs-item' + (isOpen ? ' bkbg-faqs-item--open' : ''); |
| 111 |
itemEl.style.borderBottom = (a.showDividers !== false) ? '1px solid ' + (a.dividerColor || '#e5e7eb') : 'none'; |
| 112 |
itemEl.style.borderRadius = (a.itemRadius || 10) + 'px'; |
| 113 |
|
| 114 |
var row = document.createElement('div'); |
| 115 |
row.className = 'bkbg-faqs-question-row'; |
| 116 |
|
| 117 |
var qSpan = document.createElement('span'); |
| 118 |
qSpan.className = 'bkbg-faqs-question'; |
| 119 |
qSpan.style.color = isOpen ? (a.activeAccent || '#7c3aed') : (a.questionColor || '#111827'); |
| 120 |
qSpan.innerHTML = item.question || ''; |
| 121 |
|
| 122 |
var icon = makeIcon(isOpen); |
| 123 |
|
| 124 |
row.appendChild(qSpan); |
| 125 |
row.appendChild(icon); |
| 126 |
|
| 127 |
var answerWrap = document.createElement('div'); |
| 128 |
answerWrap.className = 'bkbg-faqs-answer'; |
| 129 |
var answerP = document.createElement('p'); |
| 130 |
answerP.style.color = a.answerColor || '#4b5563'; |
| 131 |
answerP.innerHTML = item.answer || ''; |
| 132 |
answerWrap.appendChild(answerP); |
| 133 |
|
| 134 |
/* Set initial open state */ |
| 135 |
if (isOpen) { itemEl.classList.add('bkbg-faqs-item--open'); } |
| 136 |
|
| 137 |
row.addEventListener('click', function () { |
| 138 |
var wasOpen = itemEl.classList.contains('bkbg-faqs-item--open'); |
| 139 |
|
| 140 |
if (!a.allowMultiple) { |
| 141 |
itemEls.forEach(function (otherEl, i) { |
| 142 |
otherEl.classList.remove('bkbg-faqs-item--open'); |
| 143 |
var otherQ = otherEl.querySelector('.bkbg-faqs-question'); |
| 144 |
if (otherQ) { otherQ.style.color = a.questionColor || '#111827'; } |
| 145 |
var otherIcon = otherEl.querySelector('.bkbg-faqs-icon'); |
| 146 |
if (otherIcon) { |
| 147 |
if (a.iconType === 'plus') { otherIcon.textContent = '+'; } |
| 148 |
else { otherIcon.style.transform = 'none'; } |
| 149 |
} |
| 150 |
}); |
| 151 |
} |
| 152 |
|
| 153 |
if (!wasOpen) { |
| 154 |
itemEl.classList.add('bkbg-faqs-item--open'); |
| 155 |
qSpan.style.color = a.activeAccent || '#7c3aed'; |
| 156 |
if (a.iconType === 'plus') { icon.textContent = '−'; } |
| 157 |
else { icon.style.transform = a.iconType === 'arrow' ? 'rotate(90deg)' : 'rotate(180deg)'; } |
| 158 |
} else { |
| 159 |
itemEl.classList.remove('bkbg-faqs-item--open'); |
| 160 |
qSpan.style.color = a.questionColor || '#111827'; |
| 161 |
if (a.iconType === 'plus') { icon.textContent = '+'; } |
| 162 |
else { icon.style.transform = 'none'; } |
| 163 |
} |
| 164 |
}); |
| 165 |
|
| 166 |
itemEl.appendChild(row); |
| 167 |
itemEl.appendChild(answerWrap); |
| 168 |
accordion.appendChild(itemEl); |
| 169 |
itemEls.push(itemEl); |
| 170 |
}); |
| 171 |
|
| 172 |
/* === CTA row === */ |
| 173 |
var body = document.createElement('div'); |
| 174 |
body.className = 'bkbg-faqs-body'; |
| 175 |
body.appendChild(accordion); |
| 176 |
|
| 177 |
if (a.showCta && (a.ctaText || a.ctaLabel)) { |
| 178 |
var ctaRow = document.createElement('div'); |
| 179 |
ctaRow.className = 'bkbg-faqs-cta-row'; |
| 180 |
ctaRow.style.borderTopColor = a.dividerColor || '#e5e7eb'; |
| 181 |
ctaRow.style.borderTopStyle = 'solid'; |
| 182 |
ctaRow.style.borderTopWidth = '1px'; |
| 183 |
|
| 184 |
if (a.ctaText) { |
| 185 |
var ctaText = document.createElement('span'); |
| 186 |
ctaText.className = 'bkbg-faqs-cta-text'; |
| 187 |
ctaText.style.cssText = 'color:' + (a.subtextColor || '#6b7280') + ';margin-right:8px;'; |
| 188 |
ctaText.innerHTML = a.ctaText; |
| 189 |
ctaRow.appendChild(ctaText); |
| 190 |
} |
| 191 |
if (a.ctaLabel) { |
| 192 |
var ctaLink = document.createElement('a'); |
| 193 |
ctaLink.href = a.ctaUrl || '#'; |
| 194 |
ctaLink.className = 'bkbg-faqs-cta-link'; |
| 195 |
ctaLink.style.cssText = 'color:' + (a.ctaLinkColor || '#7c3aed') + ';text-decoration:underline;'; |
| 196 |
ctaLink.innerHTML = a.ctaLabel; |
| 197 |
ctaRow.appendChild(ctaLink); |
| 198 |
} |
| 199 |
body.appendChild(ctaRow); |
| 200 |
} |
| 201 |
|
| 202 |
/* === Assemble === */ |
| 203 |
if (isSplit) { |
| 204 |
inner.appendChild(header); |
| 205 |
inner.appendChild(body); |
| 206 |
} else { |
| 207 |
inner.appendChild(header); |
| 208 |
inner.appendChild(body); |
| 209 |
} |
| 210 |
wrap.appendChild(inner); |
| 211 |
el.replaceWith(wrap); |
| 212 |
}); |
| 213 |
}); |
| 214 |
|