| 1 |
(function () { |
| 2 |
var _typoKeys = { |
| 3 |
quoteTypo: '--bkqcl-qt-', |
| 4 |
authorTypo: '--bkqcl-au-' |
| 5 |
}; |
| 6 |
var _tvf; function _getTV() { return _tvf || (_tvf = window.bkbgTypoCssVars); } |
| 7 |
function typoCssVarsForEl(opts, el) { |
| 8 |
var fn = _getTV(); if (!fn) return; |
| 9 |
Object.keys(_typoKeys).forEach(function (k) { |
| 10 |
var vars = fn(opts[k] || {}, _typoKeys[k]); |
| 11 |
Object.keys(vars).forEach(function (p) { el.style.setProperty(p, vars[p]); }); |
| 12 |
}); |
| 13 |
} |
| 14 |
|
| 15 |
function init() { |
| 16 |
document.querySelectorAll('.bkbg-qcl-app').forEach(function (el) { |
| 17 |
if (el.dataset.rendered) return; |
| 18 |
el.dataset.rendered = '1'; |
| 19 |
var opts; |
| 20 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 21 |
var o = Object.assign({ |
| 22 |
sectionTitle: '', sectionSubtitle: '', showHeader: false, |
| 23 |
quotes: [{ text: '', author: '', role: '', source: '' }], |
| 24 |
layout: 'grid', columns: 2, quoteStyle: 'classic', showQuoteMark: true, |
| 25 |
bgColor: '#f8f9fa', cardBg: '#ffffff', cardBorder: '#e9ecef', |
| 26 |
accentColor: '#6366f1', quoteMarkColor: '#e0e7ff', |
| 27 |
quoteColor: '#111827', authorColor: '#374151', roleColor: '#9ca3af', |
| 28 |
titleColor: '#111827', subtitleColor: '#6b7280', |
| 29 |
gap: 20, cardRadius: 12, paddingTop: 0, paddingBottom: 0 |
| 30 |
}, opts); |
| 31 |
|
| 32 |
function mk(tag, cls, style, text) { |
| 33 |
var n = document.createElement(tag); |
| 34 |
if (cls) n.className = cls; |
| 35 |
if (style) Object.assign(n.style, style); |
| 36 |
if (text != null) n.textContent = text; |
| 37 |
return n; |
| 38 |
} |
| 39 |
|
| 40 |
/* outer */ |
| 41 |
var section = mk('div', 'bkbg-qcl-section', { |
| 42 |
background: o.bgColor, |
| 43 |
paddingTop: o.paddingTop + 'px', |
| 44 |
paddingBottom: o.paddingBottom + 'px' |
| 45 |
}); |
| 46 |
typoCssVarsForEl(o, section); |
| 47 |
|
| 48 |
/* header */ |
| 49 |
if (o.showHeader && (o.sectionTitle || o.sectionSubtitle)) { |
| 50 |
var hdr = mk('div', 'bkbg-qcl-header'); |
| 51 |
if (o.sectionTitle) { |
| 52 |
var title = mk('h2', 'bkbg-qcl-title', { color: o.titleColor }, o.sectionTitle); |
| 53 |
hdr.appendChild(title); |
| 54 |
} |
| 55 |
if (o.sectionSubtitle) { |
| 56 |
var sub = mk('p', 'bkbg-qcl-subtitle', { color: o.subtitleColor }, o.sectionSubtitle); |
| 57 |
hdr.appendChild(sub); |
| 58 |
} |
| 59 |
section.appendChild(hdr); |
| 60 |
} |
| 61 |
|
| 62 |
/* grid wrapper */ |
| 63 |
var layoutClass = 'bkbg-qcl-' + (o.layout === 'masonry' ? 'masonry' : o.layout === 'list' ? 'list' : 'grid'); |
| 64 |
var grid = mk('div', layoutClass + ' bkbg-qcl-style-' + o.quoteStyle); |
| 65 |
if (o.layout === 'grid') { |
| 66 |
grid.style.gridTemplateColumns = 'repeat(' + o.columns + ', 1fr)'; |
| 67 |
grid.style.gap = o.gap + 'px'; |
| 68 |
} else if (o.layout === 'list') { |
| 69 |
grid.style.gap = o.gap + 'px'; |
| 70 |
} else if (o.layout === 'masonry') { |
| 71 |
grid.style.columnCount = o.columns; |
| 72 |
grid.style.columnGap = o.gap + 'px'; |
| 73 |
} |
| 74 |
|
| 75 |
(o.quotes || []).forEach(function (q) { |
| 76 |
if (!q.text && !q.author) return; |
| 77 |
|
| 78 |
var card = mk('div', 'bkbg-qcl-card', { |
| 79 |
background: o.cardBg, |
| 80 |
borderRadius: o.cardRadius + 'px', |
| 81 |
borderColor: o.cardBorder |
| 82 |
}); |
| 83 |
if (o.layout === 'masonry') { |
| 84 |
card.style.marginBottom = o.gap + 'px'; |
| 85 |
} |
| 86 |
|
| 87 |
/* extra border styles */ |
| 88 |
if (o.quoteStyle === 'highlight') { |
| 89 |
card.style.borderLeftColor = o.accentColor; |
| 90 |
} else if (o.quoteStyle === 'card') { |
| 91 |
card.style.boxShadow = '0 4px 12px rgba(0,0,0,0.08)'; |
| 92 |
} |
| 93 |
|
| 94 |
/* quote mark */ |
| 95 |
if (o.showQuoteMark) { |
| 96 |
var qmark = mk('span', 'bkbg-qcl-qmark', { color: o.quoteMarkColor }, '"'); |
| 97 |
card.appendChild(qmark); |
| 98 |
} |
| 99 |
|
| 100 |
/* quote text */ |
| 101 |
if (q.text) { |
| 102 |
var textEl = mk('p', 'bkbg-qcl-text', { color: o.quoteColor }, ''); |
| 103 |
textEl.innerHTML = q.text; |
| 104 |
card.appendChild(textEl); |
| 105 |
} |
| 106 |
|
| 107 |
/* attribution */ |
| 108 |
if (q.author || q.role || q.source) { |
| 109 |
var attrib = mk('div', 'bkbg-qcl-attribution'); |
| 110 |
|
| 111 |
var authorLine = mk('div', 'bkbg-qcl-author-line'); |
| 112 |
var dot = mk('span', 'bkbg-qcl-author-dot', { background: o.accentColor }); |
| 113 |
authorLine.appendChild(dot); |
| 114 |
|
| 115 |
var authorWrap = mk('div', ''); |
| 116 |
if (q.author) { |
| 117 |
authorWrap.appendChild(mk('p', 'bkbg-qcl-author', { color: o.authorColor }, q.author)); |
| 118 |
} |
| 119 |
if (q.role) { |
| 120 |
authorWrap.appendChild(mk('p', 'bkbg-qcl-role', { color: o.roleColor }, q.role)); |
| 121 |
} |
| 122 |
if (q.source) { |
| 123 |
var srcEl = mk('p', 'bkbg-qcl-source', { color: o.roleColor }, ''); |
| 124 |
srcEl.textContent = '— ' + q.source; |
| 125 |
authorWrap.appendChild(srcEl); |
| 126 |
} |
| 127 |
authorLine.appendChild(authorWrap); |
| 128 |
attrib.appendChild(authorLine); |
| 129 |
card.appendChild(attrib); |
| 130 |
} |
| 131 |
|
| 132 |
grid.appendChild(card); |
| 133 |
}); |
| 134 |
|
| 135 |
section.appendChild(grid); |
| 136 |
el.parentNode.insertBefore(section, el); |
| 137 |
}); |
| 138 |
} |
| 139 |
|
| 140 |
if (document.readyState !== 'loading') { init(); } |
| 141 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 142 |
})(); |
| 143 |
|