| 1 |
(function () { |
| 2 |
var TYPES = { |
| 3 |
updated: { icon: '🔄', label: 'Updated' }, |
| 4 |
corrected: { icon: '✏️', label: 'Correction' }, |
| 5 |
added: { icon: '➕', label: 'Addition' }, |
| 6 |
deprecated: { icon: '⚠️', label: 'Deprecated' }, |
| 7 |
reviewed: { icon: '� |
| 8 |
', label: 'Reviewed' } |
| 9 |
}; |
| 10 |
|
| 11 |
function esc(str) { |
| 12 |
return String(str || '').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); |
| 13 |
} |
| 14 |
|
| 15 |
function init() { |
| 16 |
document.querySelectorAll('.bkbg-upn-app').forEach(function (el) { |
| 17 |
if (el.dataset.rendered) return; |
| 18 |
el.dataset.rendered = '1'; |
| 19 |
|
| 20 |
var opts; |
| 21 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 22 |
|
| 23 |
var o = Object.assign({ |
| 24 |
type: 'updated', |
| 25 |
primaryDate: '', |
| 26 |
primarySummary: '', |
| 27 |
showOriginalDate: false, |
| 28 |
originalPublishDate: '', |
| 29 |
showHistory: false, |
| 30 |
history: [], |
| 31 |
style: 'banner', |
| 32 |
bgColor: '#eff6ff', |
| 33 |
borderColor: '#bfdbfe', |
| 34 |
accentColor: '#2563eb', |
| 35 |
labelColor: '#1d4ed8', |
| 36 |
dateColor: '#3b82f6', |
| 37 |
textColor: '#1e3a8a', |
| 38 |
historyTextColor: '#1e40af', |
| 39 |
borderRadius: 6, |
| 40 |
paddingTop: 0, |
| 41 |
paddingBottom: 0 |
| 42 |
}, opts); |
| 43 |
|
| 44 |
var typeInfo = TYPES[o.type] || TYPES.updated; |
| 45 |
var styleClass = 'bkbg-upn-' + o.style; |
| 46 |
|
| 47 |
/* wrapper */ |
| 48 |
var wrap = document.createElement('div'); |
| 49 |
wrap.className = 'bkbg-upn-wrap ' + styleClass; |
| 50 |
wrap.style.background = o.bgColor; |
| 51 |
wrap.style.borderRadius = o.borderRadius + 'px'; |
| 52 |
wrap.style.overflow = 'hidden'; |
| 53 |
wrap.style.paddingTop = o.paddingTop + 'px'; |
| 54 |
wrap.style.paddingBottom = o.paddingBottom + 'px'; |
| 55 |
if (o.style === 'banner') { |
| 56 |
wrap.style.borderLeft = '4px solid ' + o.accentColor; |
| 57 |
wrap.style.padding = (o.paddingTop || 12) + 'px 16px ' + (o.paddingBottom || 12) + 'px'; |
| 58 |
} else if (o.style === 'box') { |
| 59 |
wrap.style.border = '1px solid ' + o.borderColor; |
| 60 |
wrap.style.borderLeft = '4px solid ' + o.accentColor; |
| 61 |
wrap.style.padding = (o.paddingTop || 14) + 'px 18px ' + (o.paddingBottom || 14) + 'px'; |
| 62 |
} else { /* pill */ |
| 63 |
wrap.style.display = 'inline-flex'; |
| 64 |
wrap.style.alignItems = 'center'; |
| 65 |
wrap.style.gap = '8px'; |
| 66 |
wrap.style.padding = '6px 14px'; |
| 67 |
wrap.style.border = '1px solid ' + o.borderColor; |
| 68 |
} |
| 69 |
|
| 70 |
/* top row */ |
| 71 |
var topRow = document.createElement('div'); |
| 72 |
topRow.className = 'bkbg-upn-top-row'; |
| 73 |
|
| 74 |
var typeLabel = document.createElement('div'); |
| 75 |
typeLabel.className = 'bkbg-upn-type-label'; |
| 76 |
var iconSpan = document.createElement('span'); |
| 77 |
iconSpan.className = 'bkbg-upn-icon'; |
| 78 |
iconSpan.textContent = typeInfo.icon; |
| 79 |
var labelSpan = document.createElement('span'); |
| 80 |
labelSpan.className = 'bkbg-upn-label'; |
| 81 |
labelSpan.style.color = o.labelColor; |
| 82 |
labelSpan.textContent = typeInfo.label + ':'; |
| 83 |
typeLabel.appendChild(iconSpan); |
| 84 |
typeLabel.appendChild(labelSpan); |
| 85 |
topRow.appendChild(typeLabel); |
| 86 |
|
| 87 |
if (o.primaryDate) { |
| 88 |
var dateSpan = document.createElement('span'); |
| 89 |
dateSpan.className = 'bkbg-upn-date'; |
| 90 |
dateSpan.style.color = o.dateColor; |
| 91 |
dateSpan.textContent = o.primaryDate; |
| 92 |
topRow.appendChild(dateSpan); |
| 93 |
} |
| 94 |
|
| 95 |
if (o.showOriginalDate && o.originalPublishDate) { |
| 96 |
var origSpan = document.createElement('span'); |
| 97 |
origSpan.className = 'bkbg-upn-orig-date'; |
| 98 |
origSpan.style.color = o.textColor; |
| 99 |
origSpan.textContent = '(originally published ' + esc(o.originalPublishDate) + ')'; |
| 100 |
topRow.appendChild(origSpan); |
| 101 |
} |
| 102 |
|
| 103 |
wrap.appendChild(topRow); |
| 104 |
|
| 105 |
/* summary — pill style skips summary/history */ |
| 106 |
if (o.style !== 'pill' && o.primarySummary) { |
| 107 |
var summaryDiv = document.createElement('div'); |
| 108 |
summaryDiv.className = 'bkbg-upn-summary'; |
| 109 |
summaryDiv.style.color = o.textColor; |
| 110 |
summaryDiv.innerHTML = o.primarySummary; |
| 111 |
wrap.appendChild(summaryDiv); |
| 112 |
} |
| 113 |
|
| 114 |
/* history */ |
| 115 |
if (o.style !== 'pill' && o.showHistory && o.history && o.history.length) { |
| 116 |
var histDiv = document.createElement('div'); |
| 117 |
histDiv.className = 'bkbg-upn-history'; |
| 118 |
histDiv.style.borderTop = '1px solid ' + o.borderColor; |
| 119 |
|
| 120 |
var histTitle = document.createElement('div'); |
| 121 |
histTitle.className = 'bkbg-upn-history-title'; |
| 122 |
histTitle.style.color = o.labelColor; |
| 123 |
histTitle.textContent = 'Change History'; |
| 124 |
histDiv.appendChild(histTitle); |
| 125 |
|
| 126 |
var ul = document.createElement('ul'); |
| 127 |
ul.className = 'bkbg-upn-history-list'; |
| 128 |
o.history.forEach(function (h) { |
| 129 |
if (!h.date && !h.summary) return; |
| 130 |
var li = document.createElement('li'); |
| 131 |
li.className = 'bkbg-upn-history-item'; |
| 132 |
li.style.color = o.historyTextColor; |
| 133 |
if (h.date) { |
| 134 |
var strong = document.createElement('strong'); |
| 135 |
strong.textContent = esc(h.date) + ': '; |
| 136 |
li.appendChild(strong); |
| 137 |
} |
| 138 |
li.appendChild(document.createTextNode(h.summary || '')); |
| 139 |
ul.appendChild(li); |
| 140 |
}); |
| 141 |
histDiv.appendChild(ul); |
| 142 |
wrap.appendChild(histDiv); |
| 143 |
} |
| 144 |
|
| 145 |
el.parentNode.insertBefore(wrap, el); |
| 146 |
}); |
| 147 |
} |
| 148 |
|
| 149 |
if (document.readyState !== 'loading') { init(); } |
| 150 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 151 |
})(); |
| 152 |
|