| 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 esc(str) { |
| 34 |
return String(str || '').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); |
| 35 |
} |
| 36 |
|
| 37 |
function initials(name) { |
| 38 |
return (name || '?').split(' ').map(function (w) { return w[0] || ''; }).filter(Boolean).slice(0, 2).join('').toUpperCase(); |
| 39 |
} |
| 40 |
|
| 41 |
function buildAvatar(c, sz, o) { |
| 42 |
var wrap = document.createElement('div'); |
| 43 |
wrap.className = 'bkbg-ctb-avatar'; |
| 44 |
wrap.style.cssText = 'width:' + sz + 'px;height:' + sz + 'px;border-radius:50%;overflow:hidden;flex-shrink:0;'; |
| 45 |
if (c.avatarUrl) { |
| 46 |
var img = document.createElement('img'); |
| 47 |
img.src = c.avatarUrl; |
| 48 |
img.alt = esc(c.name || ''); |
| 49 |
img.loading = 'lazy'; |
| 50 |
img.style.cssText = 'width:100%;height:100%;object-fit:cover;display:block;border-radius:50%;'; |
| 51 |
wrap.appendChild(img); |
| 52 |
} else { |
| 53 |
var init = document.createElement('div'); |
| 54 |
init.className = 'bkbg-ctb-avatar-initials'; |
| 55 |
init.style.cssText = 'width:' + sz + 'px;height:' + sz + 'px;border-radius:50%;background:' + o.avatarBg + ';color:' + o.avatarColor + ';display:flex;align-items:center;justify-content:center;font-weight:700;font-size:' + Math.round(sz * 0.35) + 'px;'; |
| 56 |
init.textContent = initials(c.name); |
| 57 |
wrap.appendChild(init); |
| 58 |
} |
| 59 |
return wrap; |
| 60 |
} |
| 61 |
|
| 62 |
function init() { |
| 63 |
document.querySelectorAll('.bkbg-ctb-app').forEach(function (el) { |
| 64 |
if (el.dataset.rendered) return; |
| 65 |
el.dataset.rendered = '1'; |
| 66 |
|
| 67 |
var opts; |
| 68 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 69 |
|
| 70 |
var o = Object.assign({ |
| 71 |
label: 'Written by', |
| 72 |
showLabel: true, |
| 73 |
contributors: [], |
| 74 |
layout: 'grid', |
| 75 |
showBio: true, |
| 76 |
showSocial: true, |
| 77 |
avatarSize: 60, |
| 78 |
bgColor: '#f8fafc', |
| 79 |
borderColor: '#e2e8f0', |
| 80 |
cardBg: '#ffffff', |
| 81 |
cardBorder: '#e2e8f0', |
| 82 |
labelColor: '#94a3b8', |
| 83 |
avatarBg: '#e2e8f0', |
| 84 |
avatarColor: '#64748b', |
| 85 |
nameColor: '#0f172a', |
| 86 |
titleColor: '#64748b', |
| 87 |
bioColor: '#475569', |
| 88 |
socialColor: '#94a3b8', |
| 89 |
accentColor: '#2563eb', |
| 90 |
borderRadius: 12, |
| 91 |
cardRadius: 8, |
| 92 |
paddingTop: 0, |
| 93 |
paddingBottom: 0 |
| 94 |
}, opts); |
| 95 |
|
| 96 |
var wrap = document.createElement('div'); |
| 97 |
wrap.className = 'bkbg-ctb-wrap'; |
| 98 |
wrap.style.cssText = [ |
| 99 |
'background:' + o.bgColor, |
| 100 |
'border-radius:' + o.borderRadius + 'px', |
| 101 |
'padding-top:' + o.paddingTop + 'px', |
| 102 |
'padding-bottom:' + o.paddingBottom + 'px' |
| 103 |
].join(';'); |
| 104 |
|
| 105 |
typoCssVarsForEl(o.typoName, '--bkbg-ctb-name-', wrap); |
| 106 |
typoCssVarsForEl(o.typoRole, '--bkbg-ctb-role-', wrap); |
| 107 |
typoCssVarsForEl(o.typoBio, '--bkbg-ctb-bio-', wrap); |
| 108 |
|
| 109 |
if (o.showLabel && o.label) { |
| 110 |
var labelEl = document.createElement('div'); |
| 111 |
labelEl.className = 'bkbg-ctb-label'; |
| 112 |
labelEl.style.color = o.labelColor; |
| 113 |
labelEl.textContent = o.label; |
| 114 |
wrap.appendChild(labelEl); |
| 115 |
} |
| 116 |
|
| 117 |
var isCompact = o.layout === 'compact'; |
| 118 |
var isList = o.layout === 'list'; |
| 119 |
var container = document.createElement('div'); |
| 120 |
container.className = isCompact ? 'bkbg-ctb-compact' : isList ? 'bkbg-ctb-list' : 'bkbg-ctb-grid'; |
| 121 |
|
| 122 |
(o.contributors || []).forEach(function (c) { |
| 123 |
var sz = o.avatarSize || 60; |
| 124 |
var avatar = buildAvatar(c, sz, o); |
| 125 |
|
| 126 |
if (isCompact) { |
| 127 |
var item = document.createElement('div'); |
| 128 |
item.className = 'bkbg-ctb-compact-item'; |
| 129 |
item.title = c.name + (c.title ? ' — ' + c.title : ''); |
| 130 |
item.appendChild(avatar); |
| 131 |
var compNameEl = document.createElement('div'); |
| 132 |
compNameEl.className = 'bkbg-ctb-compact-name'; |
| 133 |
compNameEl.style.cssText = 'color:' + o.nameColor + ';max-width:' + sz + 'px;'; |
| 134 |
compNameEl.textContent = c.name || ''; |
| 135 |
item.appendChild(compNameEl); |
| 136 |
container.appendChild(item); |
| 137 |
return; |
| 138 |
} |
| 139 |
|
| 140 |
var card = document.createElement('div'); |
| 141 |
card.className = 'bkbg-ctb-card'; |
| 142 |
card.style.cssText = 'background:' + o.cardBg + ';border:1px solid ' + o.cardBorder + ';border-radius:' + o.cardRadius + 'px;'; |
| 143 |
|
| 144 |
if (o.layout !== 'grid') { |
| 145 |
card.style.display = 'flex'; |
| 146 |
card.style.alignItems = 'flex-start'; |
| 147 |
card.style.gap = '14px'; |
| 148 |
} else { |
| 149 |
avatar.style.marginBottom = '10px'; |
| 150 |
} |
| 151 |
card.appendChild(avatar); |
| 152 |
|
| 153 |
var body = document.createElement('div'); |
| 154 |
body.className = 'bkbg-ctb-body'; |
| 155 |
body.style.flex = '1'; |
| 156 |
|
| 157 |
var nameEl = document.createElement('p'); |
| 158 |
nameEl.className = 'bkbg-ctb-name'; |
| 159 |
nameEl.style.color = o.nameColor; |
| 160 |
nameEl.textContent = c.name || ''; |
| 161 |
body.appendChild(nameEl); |
| 162 |
|
| 163 |
if (c.title) { |
| 164 |
var roleEl = document.createElement('p'); |
| 165 |
roleEl.className = 'bkbg-ctb-title'; |
| 166 |
roleEl.style.color = o.titleColor; |
| 167 |
roleEl.textContent = c.title; |
| 168 |
body.appendChild(roleEl); |
| 169 |
} |
| 170 |
|
| 171 |
if (o.showBio && c.bio) { |
| 172 |
var bioEl = document.createElement('p'); |
| 173 |
bioEl.className = 'bkbg-ctb-bio'; |
| 174 |
bioEl.style.color = o.bioColor; |
| 175 |
bioEl.textContent = c.bio; |
| 176 |
body.appendChild(bioEl); |
| 177 |
} |
| 178 |
|
| 179 |
if (o.showSocial && (c.twitter || c.linkedin || c.website)) { |
| 180 |
var social = document.createElement('div'); |
| 181 |
social.className = 'bkbg-ctb-social'; |
| 182 |
|
| 183 |
function socialLink(url, label) { |
| 184 |
if (!url) return; |
| 185 |
var a = document.createElement('a'); |
| 186 |
a.className = 'bkbg-ctb-social-link'; |
| 187 |
a.href = url; |
| 188 |
a.textContent = label; |
| 189 |
a.style.color = o.accentColor; |
| 190 |
a.target = '_blank'; |
| 191 |
a.rel = 'noopener noreferrer'; |
| 192 |
social.appendChild(a); |
| 193 |
} |
| 194 |
|
| 195 |
socialLink(c.twitter, '𝕏 Twitter'); |
| 196 |
socialLink(c.linkedin, 'LinkedIn'); |
| 197 |
socialLink(c.website, '🌐 Website'); |
| 198 |
body.appendChild(social); |
| 199 |
} |
| 200 |
|
| 201 |
card.appendChild(body); |
| 202 |
container.appendChild(card); |
| 203 |
}); |
| 204 |
|
| 205 |
wrap.appendChild(container); |
| 206 |
el.parentNode.insertBefore(wrap, el); |
| 207 |
}); |
| 208 |
} |
| 209 |
|
| 210 |
if (document.readyState !== 'loading') { init(); } |
| 211 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 212 |
})(); |
| 213 |
|