| 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-sdn-app').forEach(function (el) { |
| 25 |
if (el.dataset.rendered) return; |
| 26 |
el.dataset.rendered = '1'; |
| 27 |
|
| 28 |
var opts; |
| 29 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 30 |
|
| 31 |
var o = Object.assign({ |
| 32 |
text: '', |
| 33 |
label: 'Note', |
| 34 |
showLabel: true, |
| 35 |
icon: '📝', |
| 36 |
iconType: 'custom-char', |
| 37 |
iconDashicon: 'edit', |
| 38 |
iconImageUrl: '', |
| 39 |
showIcon: true, |
| 40 |
position: 'right', |
| 41 |
style: 'bordered', |
| 42 |
width: 260, |
| 43 |
bgColor: '#fffbeb', |
| 44 |
borderColor: '#fbbf24', |
| 45 |
accentColor: '#d97706', |
| 46 |
labelColor: '#92400e', |
| 47 |
textColor: '#78350f', |
| 48 |
iconColor: '#d97706', |
| 49 |
fontSize: 13, |
| 50 |
borderRadius: 6, |
| 51 |
paddingTop: 0, |
| 52 |
paddingBottom: 0 |
| 53 |
}, opts); |
| 54 |
|
| 55 |
var isInline = o.position === 'inline'; |
| 56 |
|
| 57 |
/* outer wrapper for padding */ |
| 58 |
var outer = document.createElement('div'); |
| 59 |
outer.style.cssText = 'padding-top:' + o.paddingTop + 'px;padding-bottom:' + o.paddingBottom + 'px;'; |
| 60 |
typoCssVarsForEl(outer, o.labelTypo, '--bksdn-lt-'); |
| 61 |
typoCssVarsForEl(outer, o.textTypo, '--bksdn-tt-'); |
| 62 |
|
| 63 |
/* sidenote element */ |
| 64 |
var wrap = document.createElement('div'); |
| 65 |
wrap.className = 'bkbg-sdn-wrap bkbg-sdn-' + o.position + ' bkbg-sdn-' + o.style; |
| 66 |
|
| 67 |
if (!isInline) { |
| 68 |
wrap.style.width = o.width + 'px'; |
| 69 |
} |
| 70 |
wrap.style.background = o.bgColor; |
| 71 |
wrap.style.borderRadius = o.borderRadius + 'px'; |
| 72 |
wrap.style.color = o.textColor; |
| 73 |
wrap.style.boxSizing = 'border-box'; |
| 74 |
wrap.style.overflow = 'hidden'; |
| 75 |
|
| 76 |
/* apply style-specific overrides */ |
| 77 |
if (o.style === 'bordered') { |
| 78 |
wrap.style.border = '1px solid ' + o.borderColor; |
| 79 |
wrap.style.borderLeft = '4px solid ' + o.accentColor; |
| 80 |
wrap.style.padding = '10px 13px'; |
| 81 |
} else if (o.style === 'filled') { |
| 82 |
wrap.style.border = '1px solid ' + o.borderColor; |
| 83 |
wrap.style.padding = '10px 13px'; |
| 84 |
} else if (o.style === 'minimal') { |
| 85 |
wrap.style.borderLeft = '3px solid ' + o.accentColor; |
| 86 |
wrap.style.paddingLeft = '10px'; |
| 87 |
wrap.style.background = 'transparent'; |
| 88 |
} else if (o.style === 'sticky') { |
| 89 |
wrap.style.border = '1px solid ' + o.borderColor; |
| 90 |
wrap.style.padding = '10px 13px 16px'; |
| 91 |
wrap.style.boxShadow = '2px 3px 8px rgba(0,0,0,0.10)'; |
| 92 |
} |
| 93 |
|
| 94 |
/* label row */ |
| 95 |
if (o.showLabel || o.showIcon) { |
| 96 |
var labelRow = document.createElement('div'); |
| 97 |
labelRow.className = 'bkbg-sdn-label-row'; |
| 98 |
|
| 99 |
if (o.showIcon) { |
| 100 |
var IP = window.bkbgIconPicker; |
| 101 |
var iconNode = IP ? IP.buildFrontendIcon(o.iconType, o.icon, o.iconDashicon, o.iconImageUrl, o.iconDashiconColor) : null; |
| 102 |
if (iconNode) { |
| 103 |
iconNode.classList.add('bkbg-sdn-icon'); |
| 104 |
iconNode.style.color = o.iconColor; |
| 105 |
labelRow.appendChild(iconNode); |
| 106 |
} else if (o.icon) { |
| 107 |
var iconEl = document.createElement('span'); |
| 108 |
iconEl.className = 'bkbg-sdn-icon'; |
| 109 |
iconEl.style.color = o.iconColor; |
| 110 |
iconEl.textContent = o.icon; |
| 111 |
labelRow.appendChild(iconEl); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
if (o.showLabel && o.label) { |
| 116 |
var labelEl = document.createElement('span'); |
| 117 |
labelEl.className = 'bkbg-sdn-label'; |
| 118 |
labelEl.style.color = o.labelColor; |
| 119 |
labelEl.textContent = o.label; |
| 120 |
labelRow.appendChild(labelEl); |
| 121 |
} |
| 122 |
|
| 123 |
wrap.appendChild(labelRow); |
| 124 |
} |
| 125 |
|
| 126 |
/* text */ |
| 127 |
if (o.text) { |
| 128 |
var textEl = document.createElement('p'); |
| 129 |
textEl.className = 'bkbg-sdn-text'; |
| 130 |
textEl.style.color = o.textColor; |
| 131 |
textEl.innerHTML = o.text; |
| 132 |
wrap.appendChild(textEl); |
| 133 |
} |
| 134 |
|
| 135 |
outer.appendChild(wrap); |
| 136 |
|
| 137 |
/* clearfix after floating notes */ |
| 138 |
if (!isInline) { |
| 139 |
var clear = document.createElement('div'); |
| 140 |
clear.className = 'bkbg-sdn-clear'; |
| 141 |
outer.appendChild(clear); |
| 142 |
} |
| 143 |
|
| 144 |
el.parentNode.insertBefore(outer, el); |
| 145 |
}); |
| 146 |
} |
| 147 |
|
| 148 |
if (document.readyState !== 'loading') { init(); } |
| 149 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 150 |
})(); |
| 151 |
|