| 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 init() { |
| 24 |
document.querySelectorAll('.bkbg-rc-app').forEach(function (appEl) { |
| 25 |
if (appEl.dataset.rendered) return; |
| 26 |
appEl.dataset.rendered = '1'; |
| 27 |
|
| 28 |
var opts; |
| 29 |
try { opts = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 30 |
var o = Object.assign({ |
| 31 |
columns: [], |
| 32 |
columnCount: 3, |
| 33 |
layout: 'cards', |
| 34 |
gap: 24, |
| 35 |
containerPadding: 0, |
| 36 |
maxWidth: 1100, |
| 37 |
cardRadius: 14, |
| 38 |
cardPadding: 28, |
| 39 |
iconSize: 28, |
| 40 |
iconBgSize: 56, |
| 41 |
iconBgRadius: 14, |
| 42 |
showIcon: true, |
| 43 |
showLink: true, |
| 44 |
showDivider: false, |
| 45 |
headingTag: 'h3', |
| 46 |
headingSize: 19, |
| 47 |
bodySize: 15, |
| 48 |
containerBg: '', |
| 49 |
cardBg: '#ffffff', |
| 50 |
cardBorder: '#e5e7eb', |
| 51 |
headingColor: '#111827', |
| 52 |
textColor: '#374151', |
| 53 |
linkColor: '#6366f1', |
| 54 |
iconBg: '#ede9fe', |
| 55 |
iconColor: '#6366f1', |
| 56 |
dividerColor: '#e5e7eb', |
| 57 |
}, opts); |
| 58 |
|
| 59 |
if (!o.columns || !o.columns.length) return; |
| 60 |
|
| 61 |
// Outer |
| 62 |
var outer = document.createElement('div'); |
| 63 |
outer.className = 'bkbg-rc-outer'; |
| 64 |
if (o.containerBg) outer.style.background = o.containerBg; |
| 65 |
if (o.containerPadding) outer.style.padding = o.containerPadding + 'px'; |
| 66 |
typoCssVarsForEl(outer, o.headingTypo, '--bkrc-ht-'); |
| 67 |
typoCssVarsForEl(outer, o.bodyTypo, '--bkrc-bt-'); |
| 68 |
|
| 69 |
// Grid |
| 70 |
var grid = document.createElement('div'); |
| 71 |
grid.className = 'bkbg-rc-grid cols-' + o.columnCount; |
| 72 |
grid.style.maxWidth = o.maxWidth + 'px'; |
| 73 |
grid.style.gap = o.gap + 'px'; |
| 74 |
grid.style.setProperty('--bkbg-rc-gap', o.gap + 'px'); |
| 75 |
|
| 76 |
// Column basis (accounts for gaps) |
| 77 |
var colBasis = 'calc(' + (100 / o.columnCount) + '% - ' + ((o.columnCount - 1) * o.gap / o.columnCount) + 'px)'; |
| 78 |
|
| 79 |
o.columns.forEach(function (col, i) { |
| 80 |
// Divider between flat columns |
| 81 |
if (i > 0 && o.showDivider && o.layout === 'flat') { |
| 82 |
var divider = document.createElement('div'); |
| 83 |
divider.className = 'bkbg-rc-divider'; |
| 84 |
divider.style.background = o.dividerColor; |
| 85 |
grid.appendChild(divider); |
| 86 |
} |
| 87 |
|
| 88 |
var colEl = document.createElement('div'); |
| 89 |
colEl.className = 'bkbg-rc-col layout-' + o.layout; |
| 90 |
colEl.style.flexBasis = colBasis; |
| 91 |
colEl.style.padding = o.cardPadding + 'px'; |
| 92 |
colEl.style.borderRadius = o.cardRadius + 'px'; |
| 93 |
colEl.style.boxSizing = 'border-box'; |
| 94 |
|
| 95 |
// Per-column background |
| 96 |
if (col.bgColor) { |
| 97 |
colEl.style.background = col.bgColor; |
| 98 |
} else if (o.layout === 'cards') { |
| 99 |
colEl.style.background = o.cardBg; |
| 100 |
colEl.style.boxShadow = '0 2px 10px rgba(0,0,0,0.08)'; |
| 101 |
} else if (o.layout === 'bordered') { |
| 102 |
colEl.style.background = o.cardBg; |
| 103 |
colEl.style.border = '1px solid ' + o.cardBorder; |
| 104 |
} else if (o.layout === 'icon-left') { |
| 105 |
colEl.style.background = o.cardBg; |
| 106 |
colEl.style.border = '1px solid ' + o.cardBorder; |
| 107 |
} else if (o.layout === 'icon-top-line') { |
| 108 |
colEl.style.borderTop = '3px solid ' + (col.accentColor || o.iconColor || '#6366f1'); |
| 109 |
} |
| 110 |
|
| 111 |
// Inner wrapper (used for icon-left flex) |
| 112 |
var inner = document.createElement('div'); |
| 113 |
inner.className = 'bkbg-rc-col-inner'; |
| 114 |
if (o.layout === 'icon-left') { |
| 115 |
inner.style.display = 'flex'; |
| 116 |
inner.style.alignItems = 'flex-start'; |
| 117 |
inner.style.gap = '16px'; |
| 118 |
} else { |
| 119 |
inner.style.display = 'flex'; |
| 120 |
inner.style.flexDirection = 'column'; |
| 121 |
inner.style.height = '100%'; |
| 122 |
} |
| 123 |
|
| 124 |
// Icon |
| 125 |
if (o.showIcon && (col.icon || col.iconDashicon || col.iconImageUrl)) { |
| 126 |
var iconBox = document.createElement('div'); |
| 127 |
iconBox.className = 'bkbg-rc-icon-box'; |
| 128 |
iconBox.style.width = o.iconBgSize + 'px'; |
| 129 |
iconBox.style.height = o.iconBgSize + 'px'; |
| 130 |
iconBox.style.borderRadius = o.iconBgRadius + 'px'; |
| 131 |
iconBox.style.background = col.accentColor ? col.accentColor + '22' : o.iconBg; |
| 132 |
iconBox.style.fontSize = o.iconSize + 'px'; |
| 133 |
iconBox.style.flexShrink = '0'; |
| 134 |
if (o.layout !== 'icon-left') { |
| 135 |
iconBox.style.marginBottom = '14px'; |
| 136 |
} |
| 137 |
var _IP = window.bkbgIconPicker; |
| 138 |
var _iType = col.iconPickerType || 'custom-char'; |
| 139 |
if (_IP && _iType !== 'custom-char') { |
| 140 |
var _in = _IP.buildFrontendIcon(_iType, col.icon, col.iconDashicon, col.iconImageUrl, col.iconDashiconColor); |
| 141 |
if (_in) iconBox.appendChild(_in); else iconBox.textContent = col.icon || ''; |
| 142 |
} else { iconBox.textContent = col.icon || ''; } |
| 143 |
inner.appendChild(iconBox); |
| 144 |
} |
| 145 |
|
| 146 |
// Text block |
| 147 |
var textBlock = document.createElement('div'); |
| 148 |
textBlock.className = 'bkbg-rc-text'; |
| 149 |
textBlock.style.flexGrow = '1'; |
| 150 |
textBlock.style.display = 'flex'; |
| 151 |
textBlock.style.flexDirection = 'column'; |
| 152 |
|
| 153 |
// Heading |
| 154 |
var headingEl = document.createElement(o.headingTag || 'h3'); |
| 155 |
headingEl.className = 'bkbg-rc-heading'; |
| 156 |
headingEl.textContent = col.heading; |
| 157 |
headingEl.style.color = o.headingColor; |
| 158 |
headingEl.style.margin = '0 0 10px'; |
| 159 |
textBlock.appendChild(headingEl); |
| 160 |
|
| 161 |
// Body (rich text / HTML) |
| 162 |
if (col.content) { |
| 163 |
var bodyEl = document.createElement('div'); |
| 164 |
bodyEl.className = 'bkbg-rc-body'; |
| 165 |
bodyEl.style.color = o.textColor; |
| 166 |
bodyEl.style.flexGrow = '1'; |
| 167 |
bodyEl.innerHTML = col.content; |
| 168 |
textBlock.appendChild(bodyEl); |
| 169 |
} |
| 170 |
|
| 171 |
// Link |
| 172 |
if (o.showLink && col.linkLabel && col.linkUrl) { |
| 173 |
var link = document.createElement('a'); |
| 174 |
link.className = 'bkbg-rc-link'; |
| 175 |
link.href = col.linkUrl; |
| 176 |
link.textContent = col.linkLabel + ' →'; |
| 177 |
link.style.color = o.linkColor; |
| 178 |
link.style.fontSize = '14px'; |
| 179 |
link.style.fontWeight = '600'; |
| 180 |
link.style.textDecoration = 'none'; |
| 181 |
link.style.marginTop = '14px'; |
| 182 |
if (col.linkNewTab) { |
| 183 |
link.setAttribute('target', '_blank'); |
| 184 |
link.setAttribute('rel', 'noopener noreferrer'); |
| 185 |
} |
| 186 |
textBlock.appendChild(link); |
| 187 |
} else if (o.showLink && col.linkLabel) { |
| 188 |
var linkSpan = document.createElement('span'); |
| 189 |
linkSpan.className = 'bkbg-rc-link'; |
| 190 |
linkSpan.textContent = col.linkLabel + ' →'; |
| 191 |
linkSpan.style.color = o.linkColor; |
| 192 |
linkSpan.style.fontSize = '14px'; |
| 193 |
linkSpan.style.fontWeight = '600'; |
| 194 |
linkSpan.style.marginTop = '14px'; |
| 195 |
textBlock.appendChild(linkSpan); |
| 196 |
} |
| 197 |
|
| 198 |
inner.appendChild(textBlock); |
| 199 |
colEl.appendChild(inner); |
| 200 |
grid.appendChild(colEl); |
| 201 |
}); |
| 202 |
|
| 203 |
outer.appendChild(grid); |
| 204 |
appEl.parentNode.insertBefore(outer, appEl); |
| 205 |
appEl.style.display = 'none'; |
| 206 |
}); |
| 207 |
} |
| 208 |
|
| 209 |
if (document.readyState !== 'loading') { init(); } |
| 210 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 211 |
})(); |
| 212 |
|