| 1 |
(function () { |
| 2 |
var typeIcons = { guide: '📖', video: '🎬', template: '📋', tool: '🛠', podcast: '🎙', other: '📌' }; |
| 3 |
|
| 4 |
var _typoKeys = { |
| 5 |
family:'font-family', weight:'font-weight', style:'font-style', |
| 6 |
decoration:'text-decoration', transform:'text-transform', |
| 7 |
sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m', |
| 8 |
lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m', |
| 9 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', |
| 10 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m' |
| 11 |
}; |
| 12 |
function typoCssVarsForEl(typo, prefix, el) { |
| 13 |
if (!typo || typeof typo !== 'object') return; |
| 14 |
Object.keys(_typoKeys).forEach(function(k) { |
| 15 |
if (typo[k] !== undefined && typo[k] !== '') { |
| 16 |
var v = typo[k]; |
| 17 |
if (['sizeDesktop','sizeTablet','sizeMobile'].indexOf(k) !== -1) v = v + (typo.sizeUnit || 'px'); |
| 18 |
else if (['lineHeightDesktop','lineHeightTablet','lineHeightMobile'].indexOf(k) !== -1) v = v + (typo.lineHeightUnit || ''); |
| 19 |
else if (['letterSpacingDesktop','letterSpacingTablet','letterSpacingMobile'].indexOf(k) !== -1) v = v + (typo.letterSpacingUnit || 'px'); |
| 20 |
else if (['wordSpacingDesktop','wordSpacingTablet','wordSpacingMobile'].indexOf(k) !== -1) v = v + (typo.wordSpacingUnit || 'px'); |
| 21 |
el.style.setProperty(prefix + _typoKeys[k], String(v)); |
| 22 |
} |
| 23 |
}); |
| 24 |
} |
| 25 |
|
| 26 |
function init() { |
| 27 |
document.querySelectorAll('.bkbg-rhb-app').forEach(function (el) { |
| 28 |
if (el.dataset.rendered) return; |
| 29 |
el.dataset.rendered = '1'; |
| 30 |
|
| 31 |
var opts; |
| 32 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 33 |
|
| 34 |
var o = Object.assign({ |
| 35 |
eyebrow: 'Free Resources', heading: 'Level Up Your Skills', |
| 36 |
subtext: 'Guides, templates, and tools to help you grow faster.', |
| 37 |
resources: [ |
| 38 |
{ title: 'The Ultimate SEO Checklist', description: 'A comprehensive SEO audit checklist.', category: 'Guides', type: 'guide', imageUrl: '', url: '#', featured: false }, |
| 39 |
{ title: 'Email Marketing Templates', description: '10 proven email sequences.', category: 'Templates', type: 'template', imageUrl: '', url: '#', featured: false } |
| 40 |
], |
| 41 |
showFilter: true, layout: 'grid', columns: 3, showType: true, |
| 42 |
ctaLabel: 'Download Free', |
| 43 |
bgColor: '#ffffff', headingColor: '#111827', subColor: '#6b7280', eyebrowColor: '#6366f1', |
| 44 |
cardBg: '#f8fafc', cardBorder: '#e2e8f0', titleColor: '#111827', descColor: '#6b7280', |
| 45 |
filterBg: '#f1f5f9', filterColor: '#6b7280', filterActiveBg: '#6366f1', filterActiveColor: '#ffffff', |
| 46 |
ctaBg: '#6366f1', ctaColor: '#ffffff', accentColor: '#6366f1', |
| 47 |
maxWidth: 1200, paddingTop: 80, paddingBottom: 80 |
| 48 |
}, opts); |
| 49 |
|
| 50 |
el.parentElement && (el.parentElement.style.background = o.bgColor); |
| 51 |
|
| 52 |
var inner = document.createElement('div'); |
| 53 |
inner.className = 'bkbg-rhb-inner'; |
| 54 |
inner.style.cssText = 'max-width:' + o.maxWidth + 'px;margin:0 auto;padding:' + o.paddingTop + 'px 24px ' + o.paddingBottom + 'px;'; |
| 55 |
|
| 56 |
typoCssVarsForEl(o.headingTypo, '--bkrh-ht-', inner); |
| 57 |
typoCssVarsForEl(o.subtextTypo, '--bkrh-st-', inner); |
| 58 |
|
| 59 |
/* Header */ |
| 60 |
var header = document.createElement('div'); |
| 61 |
header.className = 'bkbg-rhb-header'; |
| 62 |
var eyebrow = document.createElement('p'); |
| 63 |
eyebrow.className = 'bkbg-rhb-eyebrow'; |
| 64 |
eyebrow.style.color = o.eyebrowColor; |
| 65 |
eyebrow.innerHTML = o.eyebrow; |
| 66 |
var heading = document.createElement('h2'); |
| 67 |
heading.className = 'bkbg-rhb-heading'; |
| 68 |
heading.style.color = o.headingColor; |
| 69 |
heading.innerHTML = o.heading; |
| 70 |
var sub = document.createElement('p'); |
| 71 |
sub.className = 'bkbg-rhb-sub'; |
| 72 |
sub.style.color = o.subColor; |
| 73 |
sub.innerHTML = o.subtext; |
| 74 |
header.appendChild(eyebrow); |
| 75 |
header.appendChild(heading); |
| 76 |
header.appendChild(sub); |
| 77 |
inner.appendChild(header); |
| 78 |
|
| 79 |
/* Derive unique categories */ |
| 80 |
var allCats = ['All']; |
| 81 |
(o.resources || []).forEach(function (r) { |
| 82 |
if (r.category && allCats.indexOf(r.category) === -1) allCats.push(r.category); |
| 83 |
}); |
| 84 |
|
| 85 |
/* Filter */ |
| 86 |
var activeFilter = 'All'; |
| 87 |
var cardEls = []; |
| 88 |
|
| 89 |
if (o.showFilter) { |
| 90 |
var filterRow = document.createElement('div'); |
| 91 |
filterRow.className = 'bkbg-rhb-filter'; |
| 92 |
|
| 93 |
allCats.forEach(function (cat) { |
| 94 |
var pill = document.createElement('button'); |
| 95 |
pill.className = 'bkbg-rhb-pill'; |
| 96 |
pill.textContent = cat; |
| 97 |
pill.style.cssText = (cat === activeFilter) |
| 98 |
? 'background:' + o.filterActiveBg + ';color:' + o.filterActiveColor |
| 99 |
: 'background:' + o.filterBg + ';color:' + o.filterColor; |
| 100 |
|
| 101 |
pill.addEventListener('click', function () { |
| 102 |
activeFilter = cat; |
| 103 |
filterRow.querySelectorAll('.bkbg-rhb-pill').forEach(function (p) { |
| 104 |
p.style.cssText = (p.textContent === activeFilter) |
| 105 |
? 'background:' + o.filterActiveBg + ';color:' + o.filterActiveColor |
| 106 |
: 'background:' + o.filterBg + ';color:' + o.filterColor; |
| 107 |
}); |
| 108 |
cardEls.forEach(function (info) { |
| 109 |
info.card.classList.toggle('hidden', activeFilter !== 'All' && info.category !== activeFilter); |
| 110 |
}); |
| 111 |
}); |
| 112 |
|
| 113 |
filterRow.appendChild(pill); |
| 114 |
}); |
| 115 |
|
| 116 |
inner.appendChild(filterRow); |
| 117 |
} |
| 118 |
|
| 119 |
/* Grid */ |
| 120 |
var isList = o.layout === 'list'; |
| 121 |
var isFeatured = o.layout === 'featured'; |
| 122 |
|
| 123 |
var grid = document.createElement('div'); |
| 124 |
grid.className = 'bkbg-rhb-grid layout-' + o.layout; |
| 125 |
if (!isList) { |
| 126 |
grid.style.gridTemplateColumns = 'repeat(' + o.columns + ',1fr)'; |
| 127 |
} |
| 128 |
|
| 129 |
(o.resources || []).forEach(function (r) { |
| 130 |
var card = document.createElement('div'); |
| 131 |
card.className = 'bkbg-rhb-card' + (r.featured && isFeatured ? ' featured' : ''); |
| 132 |
card.style.cssText = 'background:' + o.cardBg + ';border-color:' + o.cardBorder; |
| 133 |
|
| 134 |
/* Thumbnail or placeholder */ |
| 135 |
if (r.imageUrl) { |
| 136 |
var img = document.createElement('img'); |
| 137 |
img.className = 'bkbg-rhb-card-thumb'; |
| 138 |
img.src = r.imageUrl; |
| 139 |
img.alt = r.title; |
| 140 |
card.appendChild(img); |
| 141 |
} else { |
| 142 |
var placeholder = document.createElement('div'); |
| 143 |
placeholder.className = 'bkbg-rhb-card-placeholder'; |
| 144 |
placeholder.style.cssText = 'background:linear-gradient(135deg,' + o.accentColor + '22,' + o.accentColor + '44)'; |
| 145 |
placeholder.textContent = typeIcons[r.type] || '📌'; |
| 146 |
card.appendChild(placeholder); |
| 147 |
} |
| 148 |
|
| 149 |
/* Body */ |
| 150 |
var body = document.createElement('div'); |
| 151 |
body.className = 'bkbg-rhb-card-body'; |
| 152 |
|
| 153 |
if (o.showType && r.type) { |
| 154 |
var typeLabel = document.createElement('span'); |
| 155 |
typeLabel.className = 'bkbg-rhb-type-label'; |
| 156 |
typeLabel.style.color = o.accentColor; |
| 157 |
typeLabel.textContent = (typeIcons[r.type] || '') + ' ' + r.type; |
| 158 |
body.appendChild(typeLabel); |
| 159 |
} |
| 160 |
|
| 161 |
var title = document.createElement('div'); |
| 162 |
title.className = 'bkbg-rhb-card-title'; |
| 163 |
title.style.color = o.titleColor; |
| 164 |
title.textContent = r.title; |
| 165 |
|
| 166 |
var desc = document.createElement('div'); |
| 167 |
desc.className = 'bkbg-rhb-card-desc'; |
| 168 |
desc.style.color = o.descColor; |
| 169 |
desc.textContent = r.description; |
| 170 |
|
| 171 |
var cta = document.createElement('a'); |
| 172 |
cta.className = 'bkbg-rhb-card-cta'; |
| 173 |
cta.href = r.url; |
| 174 |
cta.style.cssText = 'background:' + o.ctaBg + ';color:' + o.ctaColor; |
| 175 |
cta.textContent = o.ctaLabel; |
| 176 |
|
| 177 |
body.appendChild(title); |
| 178 |
body.appendChild(desc); |
| 179 |
body.appendChild(cta); |
| 180 |
card.appendChild(body); |
| 181 |
grid.appendChild(card); |
| 182 |
|
| 183 |
cardEls.push({ card: card, category: r.category }); |
| 184 |
}); |
| 185 |
|
| 186 |
inner.appendChild(grid); |
| 187 |
el.appendChild(inner); |
| 188 |
}); |
| 189 |
} |
| 190 |
|
| 191 |
if (document.readyState !== 'loading') { init(); } |
| 192 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 193 |
})(); |
| 194 |
|