| 1 |
wp.domReady(function () { |
| 2 |
document.querySelectorAll('.bkbg-sps-app').forEach(function (app) { |
| 3 |
var opts = {}; |
| 4 |
try { opts = JSON.parse(app.getAttribute('data-opts') || '{}'); } catch (e) {} |
| 5 |
|
| 6 |
var logos = (opts.logos || []).filter(function (l) { return l.imageUrl; }); |
| 7 |
var stats = opts.stats || []; |
| 8 |
|
| 9 |
var wrap = document.createElement('div'); |
| 10 |
wrap.className = 'bkbg-sps-wrap'; |
| 11 |
wrap.style.background = opts.bgColor || '#f9fafb'; |
| 12 |
wrap.style.paddingTop = (opts.paddingTop || 64) + 'px'; |
| 13 |
wrap.style.paddingBottom = (opts.paddingBottom || 64) + 'px'; |
| 14 |
wrap.style.setProperty('--bkbg-sps-divider', opts.dividerColor || '#e5e7eb'); |
| 15 |
|
| 16 |
var inner = document.createElement('div'); |
| 17 |
inner.className = 'bkbg-sps-inner'; |
| 18 |
inner.style.maxWidth = (opts.maxWidth || 1000) + 'px'; |
| 19 |
|
| 20 |
// Eyebrow |
| 21 |
if (opts.showEyebrow !== false && opts.eyebrow) { |
| 22 |
var eyebrow = document.createElement('p'); |
| 23 |
eyebrow.className = 'bkbg-sps-eyebrow'; |
| 24 |
eyebrow.style.fontSize = (opts.eyebrowSize || 13) + 'px'; |
| 25 |
eyebrow.style.color = opts.eyebrowColor || '#7c3aed'; |
| 26 |
eyebrow.textContent = opts.eyebrow; |
| 27 |
inner.appendChild(eyebrow); |
| 28 |
} |
| 29 |
|
| 30 |
// Heading |
| 31 |
if (opts.showHeading && opts.heading) { |
| 32 |
var heading = document.createElement('h2'); |
| 33 |
heading.className = 'bkbg-sps-heading'; |
| 34 |
heading.style.fontSize = (opts.headingSize || 32) + 'px'; |
| 35 |
heading.style.color = opts.headingColor || '#111827'; |
| 36 |
heading.innerHTML = opts.heading; |
| 37 |
inner.appendChild(heading); |
| 38 |
} |
| 39 |
|
| 40 |
// Subtext |
| 41 |
if (opts.showSubtext && opts.subtext) { |
| 42 |
var sub = document.createElement('p'); |
| 43 |
sub.className = 'bkbg-sps-subtext'; |
| 44 |
sub.style.fontSize = '18px'; |
| 45 |
sub.style.color = opts.subtextColor || '#6b7280'; |
| 46 |
sub.innerHTML = opts.subtext; |
| 47 |
inner.appendChild(sub); |
| 48 |
} |
| 49 |
|
| 50 |
// Logos |
| 51 |
if (opts.showLogos !== false && logos.length > 0) { |
| 52 |
var filterClass = opts.logoFilter || 'grayscale-hover'; |
| 53 |
var logoStrip = document.createElement('div'); |
| 54 |
logoStrip.className = 'bkbg-sps-logos bkbg-sps-logos--' + filterClass; |
| 55 |
|
| 56 |
logos.forEach(function (logo) { |
| 57 |
var item = document.createElement('div'); |
| 58 |
item.className = 'bkbg-sps-logo'; |
| 59 |
var img = document.createElement('img'); |
| 60 |
img.src = logo.imageUrl; |
| 61 |
img.alt = logo.imageAlt || ''; |
| 62 |
img.height = opts.logoHeight || 36; |
| 63 |
img.style.height = (opts.logoHeight || 36) + 'px'; |
| 64 |
img.loading = 'lazy'; |
| 65 |
item.appendChild(img); |
| 66 |
logoStrip.appendChild(item); |
| 67 |
}); |
| 68 |
inner.appendChild(logoStrip); |
| 69 |
} |
| 70 |
|
| 71 |
// Stats |
| 72 |
if (opts.showStats !== false && stats.length > 0) { |
| 73 |
var statsRow = document.createElement('div'); |
| 74 |
statsRow.className = 'bkbg-sps-stats'; |
| 75 |
|
| 76 |
stats.forEach(function (stat, i) { |
| 77 |
var statEl = document.createElement('div'); |
| 78 |
statEl.className = 'bkbg-sps-stat'; |
| 79 |
|
| 80 |
var val = document.createElement('div'); |
| 81 |
val.className = 'bkbg-sps-stat-value'; |
| 82 |
val.style.fontSize = (opts.statValueSize || 32) + 'px'; |
| 83 |
val.style.color = opts.statValueColor || '#111827'; |
| 84 |
val.textContent = stat.value || ''; |
| 85 |
statEl.appendChild(val); |
| 86 |
|
| 87 |
var label = document.createElement('div'); |
| 88 |
label.className = 'bkbg-sps-stat-label'; |
| 89 |
label.style.fontSize = (opts.statLabelSize || 14) + 'px'; |
| 90 |
label.style.color = opts.statLabelColor || '#6b7280'; |
| 91 |
label.textContent = stat.label || ''; |
| 92 |
statEl.appendChild(label); |
| 93 |
|
| 94 |
statsRow.appendChild(statEl); |
| 95 |
}); |
| 96 |
inner.appendChild(statsRow); |
| 97 |
} |
| 98 |
|
| 99 |
// Quote |
| 100 |
if (opts.showQuote !== false && opts.quote) { |
| 101 |
var card = document.createElement('div'); |
| 102 |
card.className = 'bkbg-sps-quote-card'; |
| 103 |
card.style.background = opts.quoteBg || '#ffffff'; |
| 104 |
|
| 105 |
var qMark = document.createElement('div'); |
| 106 |
qMark.className = 'bkbg-sps-quote-mark'; |
| 107 |
qMark.style.color = opts.accentColor || '#7c3aed'; |
| 108 |
qMark.textContent = '\u201C'; |
| 109 |
card.appendChild(qMark); |
| 110 |
|
| 111 |
var qText = document.createElement('p'); |
| 112 |
qText.className = 'bkbg-sps-quote-text'; |
| 113 |
qText.style.fontSize = (opts.quoteSize || 18) + 'px'; |
| 114 |
qText.style.color = opts.quoteColor || '#1f2937'; |
| 115 |
qText.innerHTML = opts.quote; |
| 116 |
card.appendChild(qText); |
| 117 |
|
| 118 |
var authorRow = document.createElement('div'); |
| 119 |
authorRow.className = 'bkbg-sps-author-row'; |
| 120 |
|
| 121 |
if (opts.quoteAvatarUrl) { |
| 122 |
var av = document.createElement('img'); |
| 123 |
av.className = 'bkbg-sps-author-avatar'; |
| 124 |
av.src = opts.quoteAvatarUrl; |
| 125 |
av.alt = opts.quoteAuthor || ''; |
| 126 |
authorRow.appendChild(av); |
| 127 |
} else { |
| 128 |
var avPh = document.createElement('div'); |
| 129 |
avPh.className = 'bkbg-sps-author-avatar-ph'; |
| 130 |
avPh.style.background = (opts.accentColor || '#7c3aed') + '22'; |
| 131 |
authorRow.appendChild(avPh); |
| 132 |
} |
| 133 |
|
| 134 |
var authorInfo = document.createElement('div'); |
| 135 |
var authorName = document.createElement('div'); |
| 136 |
authorName.className = 'bkbg-sps-author-name'; |
| 137 |
authorName.style.color = opts.authorColor || '#111827'; |
| 138 |
authorName.textContent = opts.quoteAuthor || ''; |
| 139 |
authorInfo.appendChild(authorName); |
| 140 |
|
| 141 |
if (opts.quoteRole) { |
| 142 |
var authorRole = document.createElement('div'); |
| 143 |
authorRole.className = 'bkbg-sps-author-role'; |
| 144 |
authorRole.style.color = opts.roleColor || '#6b7280'; |
| 145 |
authorRole.textContent = opts.quoteRole; |
| 146 |
authorInfo.appendChild(authorRole); |
| 147 |
} |
| 148 |
authorRow.appendChild(authorInfo); |
| 149 |
card.appendChild(authorRow); |
| 150 |
inner.appendChild(card); |
| 151 |
} |
| 152 |
|
| 153 |
wrap.appendChild(inner); |
| 154 |
app.parentNode.replaceChild(wrap, app); |
| 155 |
}); |
| 156 |
}); |
| 157 |
|