| 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) { el.style.setProperty(prefix + 'letter-spacing-d', typo.letterSpacingDesktop + lsu); el.style.setProperty(prefix + 'letter-spacing', typo.letterSpacingDesktop + lsu); } |
| 19 |
if (typo.letterSpacingTablet !== '' && typo.letterSpacingTablet != null) el.style.setProperty(prefix + 'letter-spacing-t', typo.letterSpacingTablet + lsu); |
| 20 |
if (typo.letterSpacingMobile !== '' && typo.letterSpacingMobile != null) el.style.setProperty(prefix + 'letter-spacing-m', typo.letterSpacingMobile + lsu); |
| 21 |
var wsu = typo.wordSpacingUnit || 'px'; |
| 22 |
if (typo.wordSpacingDesktop !== '' && typo.wordSpacingDesktop != null) { el.style.setProperty(prefix + 'word-spacing-d', typo.wordSpacingDesktop + wsu); el.style.setProperty(prefix + 'word-spacing', typo.wordSpacingDesktop + wsu); } |
| 23 |
if (typo.wordSpacingTablet !== '' && typo.wordSpacingTablet != null) el.style.setProperty(prefix + 'word-spacing-t', typo.wordSpacingTablet + wsu); |
| 24 |
if (typo.wordSpacingMobile !== '' && typo.wordSpacingMobile != null) el.style.setProperty(prefix + 'word-spacing-m', typo.wordSpacingMobile + wsu); |
| 25 |
} |
| 26 |
|
| 27 |
function init() { |
| 28 |
document.querySelectorAll('.bkbg-afd-app').forEach(function (el) { |
| 29 |
if (el.dataset.rendered) return; |
| 30 |
el.dataset.rendered = '1'; |
| 31 |
|
| 32 |
var opts; |
| 33 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 34 |
|
| 35 |
var o = Object.assign({ |
| 36 |
icon: '🔗', showIcon: true, label: 'Affiliate Disclosure', showLabel: true, |
| 37 |
text: 'This article contains affiliate links. If you click through and make a purchase, we may earn a commission — at no extra cost to you.', |
| 38 |
linkText: 'Read our full affiliate policy', linkUrl: '', showLink: false, |
| 39 |
style: 'banner', collapsible: false, borderRadius: 8, |
| 40 |
bgColor: '#fffbeb', borderColor: '#fcd34d', accentColor: '#d97706', |
| 41 |
textColor: '#78350f', labelColor: '#92400e', linkColor: '#d97706' |
| 42 |
}, opts); |
| 43 |
|
| 44 |
var wrap = document.createElement('div'); |
| 45 |
wrap.className = 'bkbg-afd-wrap bkbg-afd-' + o.style; |
| 46 |
|
| 47 |
/* Typography CSS vars */ |
| 48 |
wrap.style.setProperty('--bkbg-afd-text-sz', (o.textFontSize || 13) + 'px'); |
| 49 |
typoCssVarsForEl(o.textTypo, '--bkbg-afd-text-', wrap); |
| 50 |
|
| 51 |
/* Apply style-specific appearance */ |
| 52 |
if (o.style === 'banner') { |
| 53 |
wrap.style.cssText = 'padding:14px 18px;border:1px solid ' + o.borderColor + ';border-top:3px solid ' + o.accentColor + ';border-radius:' + o.borderRadius + 'px;background:' + o.bgColor; |
| 54 |
} else if (o.style === 'left-bar') { |
| 55 |
wrap.style.cssText = 'padding:12px 16px;border-left:4px solid ' + o.accentColor + ';border-radius:0 ' + o.borderRadius + 'px ' + o.borderRadius + 'px 0;background:' + o.bgColor; |
| 56 |
} else if (o.style === 'box') { |
| 57 |
wrap.style.cssText = 'padding:16px 20px;border:2px solid ' + o.borderColor + ';border-radius:' + o.borderRadius + 'px;background:' + o.bgColor; |
| 58 |
} else { |
| 59 |
wrap.style.cssText = 'padding:8px 0;background:transparent;border:none;border-radius:0;'; |
| 60 |
} |
| 61 |
|
| 62 |
/* Body content */ |
| 63 |
function buildBody() { |
| 64 |
var body = document.createElement('div'); |
| 65 |
body.className = 'bkbg-afd-body'; |
| 66 |
body.style.flex = '1'; |
| 67 |
|
| 68 |
var line = document.createElement('p'); |
| 69 |
line.style.cssText = 'margin:0;font-size:13px;line-height:1.55;color:' + o.textColor; |
| 70 |
|
| 71 |
if (o.showLabel) { |
| 72 |
var lbl = document.createElement('strong'); |
| 73 |
lbl.className = 'bkbg-afd-label'; lbl.style.color = o.labelColor; |
| 74 |
lbl.textContent = o.label + ': '; |
| 75 |
line.appendChild(lbl); |
| 76 |
} |
| 77 |
line.appendChild(document.createTextNode(o.text.replace(/<[^>]+>/g, ''))); |
| 78 |
body.appendChild(line); |
| 79 |
|
| 80 |
if (o.showLink && o.linkUrl) { |
| 81 |
var a = document.createElement('a'); |
| 82 |
a.className = 'bkbg-afd-link'; a.href = o.linkUrl; a.style.color = o.linkColor; |
| 83 |
a.textContent = o.linkText; |
| 84 |
body.appendChild(a); |
| 85 |
} |
| 86 |
return body; |
| 87 |
} |
| 88 |
|
| 89 |
if (o.collapsible) { |
| 90 |
var details = document.createElement('details'); |
| 91 |
details.style.width = '100%'; |
| 92 |
var summary = document.createElement('summary'); |
| 93 |
summary.className = 'bkbg-afd-summary'; |
| 94 |
|
| 95 |
if (o.showIcon) { |
| 96 |
var ico = document.createElement('span'); ico.textContent = o.icon; ico.style.fontSize = '18px'; |
| 97 |
summary.appendChild(ico); |
| 98 |
} |
| 99 |
var ltext = document.createElement('span'); |
| 100 |
ltext.style.cssText = 'font-weight:700;font-size:13px;color:' + o.labelColor + ';flex:1'; |
| 101 |
ltext.textContent = o.label; |
| 102 |
var arrow = document.createElement('span'); arrow.className = 'bkbg-afd-arrow'; arrow.textContent = '▶'; arrow.style.color = o.accentColor; |
| 103 |
summary.appendChild(ltext); summary.appendChild(arrow); |
| 104 |
details.appendChild(summary); |
| 105 |
|
| 106 |
var detBody = document.createElement('div'); |
| 107 |
detBody.className = 'bkbg-afd-detail-body'; |
| 108 |
detBody.appendChild(buildBody()); |
| 109 |
details.appendChild(detBody); |
| 110 |
wrap.appendChild(details); |
| 111 |
} else { |
| 112 |
if (o.showIcon) { |
| 113 |
var iconEl = document.createElement('span'); |
| 114 |
iconEl.className = 'bkbg-afd-icon'; iconEl.textContent = o.icon; |
| 115 |
wrap.appendChild(iconEl); |
| 116 |
} |
| 117 |
wrap.appendChild(buildBody()); |
| 118 |
} |
| 119 |
|
| 120 |
el.appendChild(wrap); |
| 121 |
}); |
| 122 |
} |
| 123 |
|
| 124 |
if (document.readyState !== 'loading') { init(); } |
| 125 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 126 |
})(); |
| 127 |
|