PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / sponsored-disclosure / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/sponsored-disclosure/frontend.js

126 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 var _typoKeys = [['family','font-family'],['weight','font-weight'],['style','font-style'],['decoration','text-decoration'],['transform','text-transform']];
3 var _sizeKeys = [['Desktop','d'],['Tablet','t'],['Mobile','m']];
4 var _lhKeys = [['Desktop','d'],['Tablet','t'],['Mobile','m']];
5 var _lsKeys = [['Desktop','d'],['Tablet','t'],['Mobile','m']];
6 var _wsKeys = [['Desktop','d'],['Tablet','t'],['Mobile','m']];
7
8 function typoCssVarsForEl(el, obj, prefix) {
9 if (!obj || typeof obj !== 'object') return;
10 _typoKeys.forEach(function (p) { if (obj[p[0]]) el.style.setProperty(prefix + '-' + p[1], obj[p[0]]); });
11 var u = obj.sizeUnit || 'px';
12 _sizeKeys.forEach(function (p) { var v = obj['size' + p[0]]; if (v !== undefined && v !== '') el.style.setProperty(prefix + '-font-size-' + p[1], v + u); });
13 _lhKeys.forEach(function (p) { var v = obj['lineHeight' + p[0]]; if (v !== undefined && v !== '') el.style.setProperty(prefix + '-line-height-' + p[1], String(v)); });
14 _lsKeys.forEach(function (p) { var v = obj['letterSpacing' + p[0]]; if (v !== undefined && v !== '') el.style.setProperty(prefix + '-letter-spacing-' + p[1], v + 'px'); });
15 _wsKeys.forEach(function (p) { var v = obj['wordSpacing' + p[0]]; if (v !== undefined && v !== '') el.style.setProperty(prefix + '-word-spacing-' + p[1], v + 'px'); });
16 }
17
18 var DEFAULT_LABELS = {
19 'sponsored': 'Sponsored',
20 'paid-partnership': 'Paid Partnership',
21 'advertisement': 'Advertisement',
22 'native-ad': 'Native Ad',
23 'affiliate': 'Affiliate'
24 };
25
26 function init() {
27 document.querySelectorAll('.bkbg-spd-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 disclosureType: 'sponsored',
36 customLabel: '',
37 text: '',
38 showText: false,
39 showIcon: true,
40 icon: '📢',
41 iconType: 'custom-char',
42 iconDashicon: 'megaphone',
43 iconImageUrl: '',
44 style: 'pill',
45 align: 'left',
46 bgColor: '#fff7ed',
47 borderColor: '#fed7aa',
48 textColor: '#9a3412',
49 labelBg: '#f97316',
50 labelColor: '#ffffff',
51 fontSize: 12,
52 borderRadius: 999,
53 paddingTop: 0,
54 paddingBottom: 0
55 }, opts);
56
57 var label = o.disclosureType === 'custom'
58 ? (o.customLabel || 'Custom')
59 : (DEFAULT_LABELS[o.disclosureType] || 'Sponsored');
60
61 var isPill = o.style === 'pill';
62 var isBanner = o.style === 'banner';
63
64 var wrap = document.createElement('div');
65 wrap.className = 'bkbg-spd-wrap';
66 wrap.style.cssText = [
67 'padding-top:' + o.paddingTop + 'px',
68 'padding-bottom:' + o.paddingBottom + 'px',
69 'text-align:' + (o.align || 'left')
70 ].join(';');
71
72 /* Legacy + typo CSS vars */
73 wrap.style.setProperty('--bksd-lb-sz', (o.fontSize || 12) + 'px');
74 wrap.style.setProperty('--bksd-lb-w', String(o.fontWeight || '600'));
75 wrap.style.setProperty('--bksd-lb-lh', String(o.lineHeight || 1.5));
76 wrap.style.setProperty('--bksd-tx-sz', (o.fontSize || 12) + 'px');
77 wrap.style.setProperty('--bksd-tx-w', String(o.fontWeight || '600'));
78 wrap.style.setProperty('--bksd-tx-lh', String(o.lineHeight || 1.5));
79 typoCssVarsForEl(wrap, o.labelTypo, '--bksd-lb');
80 typoCssVarsForEl(wrap, o.textTypo, '--bksd-tx');
81
82 var container = document.createElement('div');
83 var baseRadius = isPill ? o.borderRadius : isBanner ? 4 : 8;
84 container.className = 'bkbg-spd-' + o.style;
85 container.style.cssText = [
86 'background:' + o.bgColor,
87 'border:1px solid ' + o.borderColor,
88 'border-radius:' + baseRadius + 'px',
89 'color:' + o.textColor,
90 isPill ? 'display:inline-flex' : 'display:flex'
91 ].join(';');
92
93 var chip = document.createElement('span');
94 chip.className = 'bkbg-spd-label-chip';
95 chip.style.cssText = 'background:' + o.labelBg + ';color:' + o.labelColor + ';display:inline-flex;align-items:center;gap:4px;';
96 if (o.showIcon) {
97 var IP = window.bkbgIconPicker;
98 var iconNode = IP ? IP.buildFrontendIcon(o.iconType, o.icon, o.iconDashicon, o.iconImageUrl, o.iconDashiconColor) : null;
99 if (iconNode) {
100 chip.appendChild(iconNode);
101 } else if (o.icon) {
102 var iconSpan = document.createElement('span');
103 iconSpan.textContent = o.icon;
104 chip.appendChild(iconSpan);
105 }
106 }
107 chip.appendChild(document.createTextNode(label));
108 container.appendChild(chip);
109
110 if (o.showText && o.text) {
111 var textEl = document.createElement('span');
112 textEl.className = 'bkbg-spd-text';
113 textEl.style.cssText = 'color:' + o.textColor;
114 textEl.innerHTML = o.text;
115 container.appendChild(textEl);
116 }
117
118 wrap.appendChild(container);
119 el.parentNode.insertBefore(wrap, el);
120 });
121 }
122
123 if (document.readyState !== 'loading') { init(); }
124 else { document.addEventListener('DOMContentLoaded', init); }
125 })();
126