| 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-ss-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 |
|
| 31 |
var o = Object.assign({ |
| 32 |
sidebarSide: 'left', |
| 33 |
sidebarWidth: '30', |
| 34 |
stickyTop: 80, |
| 35 |
sidebarStyle: 'card', |
| 36 |
gap: 40, |
| 37 |
containerPadding: 0, |
| 38 |
mainContent: '', |
| 39 |
imageUrl: '', |
| 40 |
imageAlt: '', |
| 41 |
imageStyle: 'rounded', |
| 42 |
imageSize: 80, |
| 43 |
showImage: false, |
| 44 |
heading: '', |
| 45 |
showHeading: true, |
| 46 |
headingTag: 'h3', |
| 47 |
subText: '', |
| 48 |
showSubText: true, |
| 49 |
bullets: [], |
| 50 |
showBullets: true, |
| 51 |
bulletIcon: '✓', |
| 52 |
showCta: true, |
| 53 |
ctaLabel: 'Get Started', |
| 54 |
ctaUrl: '#', |
| 55 |
ctaNewTab: false, |
| 56 |
ctaStyle: 'filled', |
| 57 |
showRatingBox: false, |
| 58 |
ratingStars: 5, |
| 59 |
ratingCount: '4.9 / 5', |
| 60 |
ratingLabel: 'based on 120 reviews', |
| 61 |
showContactInfo: false, |
| 62 |
contactPhone: '', |
| 63 |
contactEmail: '', |
| 64 |
borderRadius: 12, |
| 65 |
sidebarPadding: 24, |
| 66 |
containerBg: '', |
| 67 |
mainBg: '', |
| 68 |
sidebarBg: '#f8fafc', |
| 69 |
sidebarBorderColor: '#e2e8f0', |
| 70 |
headingColor: '#111827', |
| 71 |
textColor: '#374151', |
| 72 |
bulletIconColor: '#6366f1', |
| 73 |
ctaBg: '#6366f1', |
| 74 |
ctaColor: '#ffffff', |
| 75 |
starColor: '#f59e0b', |
| 76 |
linkColor: '#6366f1', |
| 77 |
}, opts); |
| 78 |
|
| 79 |
var sidebarFlex = parseInt(o.sidebarWidth) || 30; |
| 80 |
|
| 81 |
// Outer wrapper |
| 82 |
var wrap = document.createElement('div'); |
| 83 |
wrap.className = 'bkbg-ss-wrap'; |
| 84 |
wrap.style.display = 'flex'; |
| 85 |
wrap.style.gap = o.gap + 'px'; |
| 86 |
wrap.style.padding = o.containerPadding + 'px'; |
| 87 |
wrap.style.alignItems = 'flex-start'; |
| 88 |
if (o.containerBg) wrap.style.background = o.containerBg; |
| 89 |
|
| 90 |
typoCssVarsForEl(wrap, o.headingTypo, '--bkssb-hd-'); |
| 91 |
typoCssVarsForEl(wrap, o.subTextTypo, '--bkssb-st-'); |
| 92 |
wrap.style.setProperty('--bkssb-heading-color', o.headingColor || '#111827'); |
| 93 |
wrap.style.setProperty('--bkssb-text-color', o.textColor || '#374151'); |
| 94 |
wrap.style.setProperty('--bkssb-st-fw', o.subTextFontWeight || '400'); |
| 95 |
wrap.style.setProperty('--bkssb-st-lh', String(o.subTextLineHeight || 1.5)); |
| 96 |
|
| 97 |
// ── Sidebar ── |
| 98 |
var sidebar = document.createElement('div'); |
| 99 |
sidebar.className = 'bkbg-ss-sidebar is-sticky style-' + o.sidebarStyle; |
| 100 |
sidebar.style.flex = '0 0 ' + sidebarFlex + '%'; |
| 101 |
sidebar.style.maxWidth = sidebarFlex + '%'; |
| 102 |
sidebar.style.top = o.stickyTop + 'px'; |
| 103 |
sidebar.style.padding = o.sidebarPadding + 'px'; |
| 104 |
sidebar.style.borderRadius = o.borderRadius + 'px'; |
| 105 |
sidebar.style.display = 'flex'; |
| 106 |
sidebar.style.flexDirection = 'column'; |
| 107 |
sidebar.style.gap = '16px'; |
| 108 |
sidebar.style.boxSizing = 'border-box'; |
| 109 |
|
| 110 |
if (o.sidebarStyle === 'card') { |
| 111 |
sidebar.style.background = o.sidebarBg; |
| 112 |
sidebar.style.boxShadow = '0 1px 12px rgba(0,0,0,0.08)'; |
| 113 |
sidebar.style.border = '1px solid ' + o.sidebarBorderColor; |
| 114 |
} else if (o.sidebarStyle === 'border') { |
| 115 |
sidebar.style.border = '1px solid ' + o.sidebarBorderColor; |
| 116 |
} |
| 117 |
|
| 118 |
// Image |
| 119 |
if (o.showImage && o.imageUrl) { |
| 120 |
var imgWrap = document.createElement('div'); |
| 121 |
imgWrap.className = 'bkbg-ss-img-wrap'; |
| 122 |
imgWrap.style.display = 'flex'; |
| 123 |
imgWrap.style.justifyContent = 'center'; |
| 124 |
var img = document.createElement('img'); |
| 125 |
img.className = 'bkbg-ss-img'; |
| 126 |
img.src = o.imageUrl; |
| 127 |
img.alt = o.imageAlt; |
| 128 |
img.style.display = 'block'; |
| 129 |
img.style.objectFit = 'cover'; |
| 130 |
if (o.imageStyle === 'full') { |
| 131 |
img.style.width = '100%'; |
| 132 |
img.style.height = 'auto'; |
| 133 |
img.style.borderRadius = o.borderRadius + 'px'; |
| 134 |
} else { |
| 135 |
img.style.width = o.imageSize + 'px'; |
| 136 |
img.style.height = o.imageSize + 'px'; |
| 137 |
img.style.borderRadius = o.imageStyle === 'circle' ? '50%' : o.imageStyle === 'rounded' ? '10px' : '0'; |
| 138 |
} |
| 139 |
imgWrap.appendChild(img); |
| 140 |
sidebar.appendChild(imgWrap); |
| 141 |
} |
| 142 |
|
| 143 |
// Heading |
| 144 |
if (o.showHeading && o.heading) { |
| 145 |
var headingEl = document.createElement(o.headingTag); |
| 146 |
headingEl.className = 'bkbg-ss-heading'; |
| 147 |
headingEl.textContent = o.heading; |
| 148 |
headingEl.style.margin = '0'; |
| 149 |
headingEl.style.color = o.headingColor; |
| 150 |
sidebar.appendChild(headingEl); |
| 151 |
} |
| 152 |
|
| 153 |
// Sub-text |
| 154 |
if (o.showSubText && o.subText) { |
| 155 |
var subEl = document.createElement('p'); |
| 156 |
subEl.className = 'bkbg-ss-subtext'; |
| 157 |
subEl.textContent = o.subText; |
| 158 |
subEl.style.margin = '0'; |
| 159 |
subEl.style.color = o.textColor; |
| 160 |
sidebar.appendChild(subEl); |
| 161 |
} |
| 162 |
|
| 163 |
// Rating |
| 164 |
if (o.showRatingBox) { |
| 165 |
var ratingBox = document.createElement('div'); |
| 166 |
ratingBox.className = 'bkbg-ss-rating'; |
| 167 |
ratingBox.style.background = 'rgba(0,0,0,0.04)'; |
| 168 |
ratingBox.style.borderRadius = '8px'; |
| 169 |
ratingBox.style.padding = '10px 14px'; |
| 170 |
|
| 171 |
var stars = document.createElement('div'); |
| 172 |
stars.className = 'bkbg-ss-stars'; |
| 173 |
stars.textContent = '� |
| 174 |
'.repeat(Math.round(o.ratingStars)) + '☆'.repeat(5 - Math.round(o.ratingStars)); |
| 175 |
stars.style.color = o.starColor; |
| 176 |
stars.style.fontSize = '18px'; |
| 177 |
stars.style.letterSpacing = '2px'; |
| 178 |
ratingBox.appendChild(stars); |
| 179 |
|
| 180 |
var score = document.createElement('div'); |
| 181 |
score.className = 'bkbg-ss-rating-score'; |
| 182 |
score.textContent = o.ratingCount; |
| 183 |
score.style.fontWeight = '700'; |
| 184 |
score.style.color = o.headingColor; |
| 185 |
score.style.fontSize = '15px'; |
| 186 |
score.style.marginTop = '4px'; |
| 187 |
ratingBox.appendChild(score); |
| 188 |
|
| 189 |
var rlabel = document.createElement('div'); |
| 190 |
rlabel.className = 'bkbg-ss-rating-label'; |
| 191 |
rlabel.textContent = o.ratingLabel; |
| 192 |
rlabel.style.fontSize = '12px'; |
| 193 |
rlabel.style.opacity = '0.7'; |
| 194 |
rlabel.style.color = o.textColor; |
| 195 |
ratingBox.appendChild(rlabel); |
| 196 |
|
| 197 |
sidebar.appendChild(ratingBox); |
| 198 |
} |
| 199 |
|
| 200 |
// Bullets |
| 201 |
if (o.showBullets && o.bullets && o.bullets.length > 0) { |
| 202 |
var ul = document.createElement('ul'); |
| 203 |
ul.className = 'bkbg-ss-bullets'; |
| 204 |
ul.style.listStyle = 'none'; |
| 205 |
ul.style.margin = '0'; |
| 206 |
ul.style.padding = '0'; |
| 207 |
ul.style.display = 'flex'; |
| 208 |
ul.style.flexDirection = 'column'; |
| 209 |
ul.style.gap = '8px'; |
| 210 |
o.bullets.forEach(function (b) { |
| 211 |
var li = document.createElement('li'); |
| 212 |
li.className = 'bkbg-ss-bullet'; |
| 213 |
li.style.display = 'flex'; |
| 214 |
li.style.alignItems = 'flex-start'; |
| 215 |
li.style.gap = '8px'; |
| 216 |
li.style.fontSize = '14px'; |
| 217 |
li.style.color = o.textColor; |
| 218 |
li.style.lineHeight = '1.5'; |
| 219 |
var icon = document.createElement('span'); |
| 220 |
icon.className = 'bkbg-ss-bullet-icon'; |
| 221 |
icon.textContent = o.bulletIcon; |
| 222 |
icon.style.color = o.bulletIconColor; |
| 223 |
icon.style.fontWeight = '700'; |
| 224 |
icon.style.flexShrink = '0'; |
| 225 |
var text = document.createElement('span'); |
| 226 |
text.textContent = b.text; |
| 227 |
li.appendChild(icon); |
| 228 |
li.appendChild(text); |
| 229 |
ul.appendChild(li); |
| 230 |
}); |
| 231 |
sidebar.appendChild(ul); |
| 232 |
} |
| 233 |
|
| 234 |
// Contact info |
| 235 |
if (o.showContactInfo && (o.contactPhone || o.contactEmail)) { |
| 236 |
var contact = document.createElement('div'); |
| 237 |
contact.className = 'bkbg-ss-contact'; |
| 238 |
contact.style.display = 'flex'; |
| 239 |
contact.style.flexDirection = 'column'; |
| 240 |
contact.style.gap = '6px'; |
| 241 |
contact.style.fontSize = '14px'; |
| 242 |
if (o.contactPhone) { |
| 243 |
var phone = document.createElement('a'); |
| 244 |
phone.href = 'tel:' + o.contactPhone.replace(/\s+/g, ''); |
| 245 |
phone.textContent = '📞 ' + o.contactPhone; |
| 246 |
phone.style.color = o.textColor; |
| 247 |
phone.style.textDecoration = 'none'; |
| 248 |
contact.appendChild(phone); |
| 249 |
} |
| 250 |
if (o.contactEmail) { |
| 251 |
var email = document.createElement('a'); |
| 252 |
email.href = 'mailto:' + o.contactEmail; |
| 253 |
email.textContent = '✉️ ' + o.contactEmail; |
| 254 |
email.style.color = o.linkColor; |
| 255 |
email.style.textDecoration = 'none'; |
| 256 |
contact.appendChild(email); |
| 257 |
} |
| 258 |
sidebar.appendChild(contact); |
| 259 |
} |
| 260 |
|
| 261 |
// CTA button |
| 262 |
if (o.showCta && o.ctaLabel) { |
| 263 |
var cta = document.createElement('a'); |
| 264 |
cta.className = 'bkbg-ss-cta'; |
| 265 |
cta.href = o.ctaUrl || '#'; |
| 266 |
cta.textContent = o.ctaLabel; |
| 267 |
if (o.ctaNewTab) { cta.target = '_blank'; cta.rel = 'noopener noreferrer'; } |
| 268 |
cta.style.display = 'block'; |
| 269 |
cta.style.textAlign = 'center'; |
| 270 |
cta.style.padding = '10px 20px'; |
| 271 |
cta.style.borderRadius = '8px'; |
| 272 |
cta.style.fontWeight = '600'; |
| 273 |
cta.style.fontSize = '15px'; |
| 274 |
cta.style.textDecoration = 'none'; |
| 275 |
cta.style.boxSizing = 'border-box'; |
| 276 |
cta.style.borderWidth = '2px'; |
| 277 |
cta.style.borderStyle = 'solid'; |
| 278 |
cta.style.borderColor = o.ctaBg; |
| 279 |
if (o.ctaStyle === 'filled') { |
| 280 |
cta.style.background = o.ctaBg; |
| 281 |
cta.style.color = o.ctaColor; |
| 282 |
} else if (o.ctaStyle === 'outline') { |
| 283 |
cta.style.background = 'transparent'; |
| 284 |
cta.style.color = o.ctaBg; |
| 285 |
} else { |
| 286 |
cta.style.background = 'transparent'; |
| 287 |
cta.style.color = o.ctaBg; |
| 288 |
cta.style.borderColor = 'transparent'; |
| 289 |
} |
| 290 |
sidebar.appendChild(cta); |
| 291 |
} |
| 292 |
|
| 293 |
// ── Main content ── |
| 294 |
var main = document.createElement('div'); |
| 295 |
main.className = 'bkbg-ss-main'; |
| 296 |
main.style.flex = '1'; |
| 297 |
main.style.minWidth = '0'; |
| 298 |
main.style.boxSizing = 'border-box'; |
| 299 |
if (o.mainBg) main.style.background = o.mainBg; |
| 300 |
|
| 301 |
var mainContent = document.createElement('div'); |
| 302 |
mainContent.className = 'bkbg-ss-main-content'; |
| 303 |
mainContent.style.lineHeight = '1.7'; |
| 304 |
mainContent.innerHTML = o.mainContent; |
| 305 |
main.appendChild(mainContent); |
| 306 |
|
| 307 |
// Assemble sidebar side |
| 308 |
if (o.sidebarSide === 'left') { |
| 309 |
wrap.appendChild(sidebar); |
| 310 |
wrap.appendChild(main); |
| 311 |
} else { |
| 312 |
wrap.appendChild(main); |
| 313 |
wrap.appendChild(sidebar); |
| 314 |
} |
| 315 |
|
| 316 |
appEl.parentNode.insertBefore(wrap, appEl); |
| 317 |
appEl.style.display = 'none'; |
| 318 |
}); |
| 319 |
} |
| 320 |
|
| 321 |
if (document.readyState !== 'loading') { |
| 322 |
init(); |
| 323 |
} else { |
| 324 |
document.addEventListener('DOMContentLoaded', init); |
| 325 |
} |
| 326 |
})(); |
| 327 |
|