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 / opinion-box / frontend.js

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

156 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 var _typoKeys = {
3 family:'font-family', weight:'font-weight', style:'font-style',
4 transform:'text-transform', decoration:'text-decoration',
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 var _typoUnits = { size:'sizeUnit', lineHeight:'lineHeightUnit', letterSpacing:'letterSpacingUnit', wordSpacing:'wordSpacingUnit' };
11 var _typoUnitDefaults = { size:'px', lineHeight:'', letterSpacing:'px', wordSpacing:'px' };
12 function typoCssVarsForEl(el, obj, prefix) {
13 if (!obj || typeof obj !== 'object') return;
14 Object.keys(_typoKeys).forEach(function (k) {
15 var v = obj[k]; if (v === undefined || v === '') return;
16 var prop = _typoKeys[k];
17 var base = k.replace(/Desktop|Tablet|Mobile/, '');
18 var uKey = _typoUnits[base];
19 if (uKey && typeof v === 'number') v = v + (obj[uKey] || _typoUnitDefaults[base] || '');
20 el.style.setProperty(prefix + prop, v);
21 });
22 }
23 function init() {
24 document.querySelectorAll('.bkbg-opb-app').forEach(function (el) {
25 if (el.dataset.rendered) return;
26 el.dataset.rendered = '1';
27 var opts;
28 try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; }
29 var o = Object.assign({
30 badgeText: 'My Take',
31 opinion: '',
32 authorName: '',
33 authorTitle: '',
34 avatarUrl: '',
35 avatarAlt: '',
36 style: 'featured',
37 showAvatar: true,
38 showBadge: true,
39 bgColor: '#fefce8',
40 borderColor: '#fde047',
41 accentColor: '#ca8a04',
42 badgeBg: '#ca8a04',
43 badgeColor: '#ffffff',
44 textColor: '#1c1917',
45 authorColor: '#57534e',
46 titleColor: '#78716c',
47 avatarBg: '#d97706',
48 avatarColor: '#ffffff',
49 quoteMarkColor: '#fde047',
50 borderRadius: 10,
51 paddingTop: 4,
52 paddingBottom: 4
53 }, opts);
54
55 var outer = document.createElement('div');
56 outer.style.cssText = 'padding:' + (o.paddingTop * 8) + 'px 0 ' + (o.paddingBottom * 8) + 'px;';
57
58 var wrap = document.createElement('div');
59 wrap.className = 'bkbg-opb-wrap bkbg-opb-' + o.style;
60
61 typoCssVarsForEl(wrap, o.opinionTypo, '--bkbg-opb-op-');
62 typoCssVarsForEl(wrap, o.authorNameTypo, '--bkbg-opb-an-');
63 typoCssVarsForEl(wrap, o.authorTitleTypo, '--bkbg-opb-at-');
64
65 if (o.style === 'featured') {
66 wrap.style.cssText = 'background:' + o.bgColor + ';border:1px solid ' + o.borderColor + ';border-radius:' + o.borderRadius + 'px;padding:20px 24px;position:relative;overflow:hidden;box-sizing:border-box;font-family:inherit;';
67 } else if (o.style === 'inline') {
68 wrap.style.cssText = 'border-left:4px solid ' + o.accentColor + ';padding:4px 16px 4px 20px;box-sizing:border-box;font-family:inherit;';
69 } else {
70 /* quote */
71 wrap.style.cssText = 'background:' + o.bgColor + ';border-radius:' + o.borderRadius + 'px;padding:24px 28px 20px;position:relative;box-sizing:border-box;font-family:inherit;';
72 }
73
74 /* Badge */
75 if (o.showBadge && o.badgeText) {
76 var badge = document.createElement('span');
77 badge.className = 'bkbg-opb-badge';
78 badge.style.cssText = 'display:inline-block;background:' + o.badgeBg + ';color:' + o.badgeColor + ';padding:3px 10px;border-radius:20px;margin-bottom:10px;';
79 badge.textContent = o.badgeText;
80 wrap.appendChild(badge);
81 }
82
83 /* Quote mark decoration */
84 if (o.style === 'quote') {
85 var qm = document.createElement('div');
86 qm.className = 'bkbg-opb-quote-mark';
87 qm.style.cssText = 'font-size:80px;line-height:.8;font-family:Georgia,serif;margin-bottom:12px;user-select:none;color:' + o.quoteMarkColor + ';';
88 qm.textContent = '\u201C';
89 wrap.appendChild(qm);
90 }
91
92 /* Opinion text */
93 if (o.opinion) {
94 var p = document.createElement('p');
95 p.className = 'bkbg-opb-text';
96 p.style.cssText = 'margin:0 0 12px;color:' + o.textColor + ';';
97 p.innerHTML = o.opinion;
98 wrap.appendChild(p);
99 }
100
101 /* Author row */
102 if (o.authorName || o.authorTitle) {
103 var row = document.createElement('div');
104 row.className = 'bkbg-opb-author-row';
105 row.style.cssText = 'display:flex;align-items:center;gap:10px;margin-top:12px;';
106
107 if (o.showAvatar) {
108 var av = document.createElement('div');
109 av.className = 'bkbg-opb-avatar';
110 av.style.cssText = 'width:44px;height:44px;border-radius:50%;overflow:hidden;display:flex;align-items:center;justify-content:center;flex-shrink:0;background:' + o.avatarBg + ';border:2px solid ' + o.accentColor + ';';
111
112 if (o.avatarUrl) {
113 var img = document.createElement('img');
114 img.src = o.avatarUrl;
115 img.alt = o.avatarAlt || o.authorName;
116 img.style.cssText = 'width:100%;height:100%;object-fit:cover;display:block;';
117 av.appendChild(img);
118 } else {
119 var initials = (o.authorName || 'A').split(' ').map(function (w) { return w[0]; }).slice(0, 2).join('').toUpperCase();
120 var ini = document.createElement('span');
121 ini.className = 'bkbg-opb-avatar-initials';
122 ini.style.cssText = 'font-weight:700;font-size:16px;color:' + o.avatarColor + ';';
123 ini.textContent = initials;
124 av.appendChild(ini);
125 }
126 row.appendChild(av);
127 }
128
129 var info = document.createElement('div');
130 if (o.authorName) {
131 var an = document.createElement('p');
132 an.className = 'bkbg-opb-author-name';
133 an.style.cssText = 'margin:0;color:' + o.authorColor + ';';
134 an.textContent = o.authorName;
135 info.appendChild(an);
136 }
137 if (o.authorTitle) {
138 var at = document.createElement('p');
139 at.className = 'bkbg-opb-author-title';
140 at.style.cssText = 'margin:0;color:' + o.titleColor + ';';
141 at.textContent = o.authorTitle;
142 info.appendChild(at);
143 }
144 row.appendChild(info);
145 wrap.appendChild(row);
146 }
147
148 outer.appendChild(wrap);
149 el.parentNode.insertBefore(outer, el);
150 });
151 }
152
153 if (document.readyState !== 'loading') { init(); }
154 else { document.addEventListener('DOMContentLoaded', init); }
155 })();
156