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 / research-brief / frontend.js

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

178 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 function mk(tag, cls, styles) {
5 var d = document.createElement(tag);
6 if (cls) d.className = cls;
7 if (styles) Object.keys(styles).forEach(function (k) { d.style[k] = styles[k]; });
8 return d;
9 }
10 function tx(tag, cls, text, styles) {
11 var d = mk(tag, cls, styles);
12 d.textContent = text;
13 return d;
14 }
15 function ap(parent) {
16 Array.prototype.slice.call(arguments, 1).forEach(function (c) { if (c) parent.appendChild(c); });
17 return parent;
18 }
19
20 var studyTypeLabels = {
21 'survey': '📊 Survey',
22 'experiment': '🔬 Experiment',
23 'meta-analysis':'📚 Meta-Analysis',
24 'case-study': '🗂️ Case Study',
25 'review': '🔍 Review'
26 };
27
28 function sectionHead(label, a) {
29 return tx('div', 'bkbg-rb-section-head', label, { color: a.accentColor || '#0284c7', borderBottomColor: a.accentColor || '#0284c7' });
30 }
31
32 function sigInfo(sig, a) {
33 if (sig === 'high') return { label: '🟢 High', bg: a.highBg || '#dcfce7', color: a.highColor || '#14532d' };
34 if (sig === 'medium') return { label: '🟡 Medium', bg: a.medBg || '#fef9c3', color: a.medColor || '#713f12' };
35 return { label: '⚪ Low', bg: a.lowBg || '#f1f5f9', color: a.lowColor || '#374151' };
36 }
37
38 var _typoKeys = {
39 family:'font-family', weight:'font-weight', style:'font-style',
40 decoration:'text-decoration', transform:'text-transform',
41 sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m',
42 lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m',
43 letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m',
44 wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m'
45 };
46 function typoCssVarsForEl(typo, prefix, el) {
47 if (!typo || typeof typo !== 'object') return;
48 Object.keys(_typoKeys).forEach(function(k) {
49 if (typo[k] !== undefined && typo[k] !== '') {
50 var v = typo[k];
51 if (['sizeDesktop','sizeTablet','sizeMobile'].indexOf(k) !== -1) v = v + (typo.sizeUnit || 'px');
52 else if (['lineHeightDesktop','lineHeightTablet','lineHeightMobile'].indexOf(k) !== -1) v = v + (typo.lineHeightUnit || '');
53 else if (['letterSpacingDesktop','letterSpacingTablet','letterSpacingMobile'].indexOf(k) !== -1) v = v + (typo.letterSpacingUnit || 'px');
54 else if (['wordSpacingDesktop','wordSpacingTablet','wordSpacingMobile'].indexOf(k) !== -1) v = v + (typo.wordSpacingUnit || 'px');
55 el.style.setProperty(prefix + _typoKeys[k], String(v));
56 }
57 });
58 }
59
60 function init() {
61 document.querySelectorAll('.bkbg-research-brief-app').forEach(function (appEl) {
62 if (appEl.dataset.rendered) return;
63 appEl.dataset.rendered = '1';
64
65 var a;
66 try { a = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { return; }
67
68 var wrap = mk('div', 'bkbg-rb-wrap', {
69 border: '1px solid ' + (a.borderColor || '#e5e7eb'),
70 borderRadius: (a.borderRadius || 12) + 'px',
71 overflow: 'hidden',
72 background: a.bgColor || '#fff'
73 });
74 typoCssVarsForEl(a.titleTypo, '--bkrb-tt-', wrap);
75 typoCssVarsForEl(a.bodyTypo, '--bkrb-bt-', wrap);
76
77 // ── Header ───────────────────────────────────────────────────
78 var header = mk('div', 'bkbg-rb-header', { background: a.headerBg || '#0f172a' });
79
80 var metaRow = mk('div', 'bkbg-rb-header-meta');
81 ap(metaRow, tx('span', 'bkbg-rb-type-badge', studyTypeLabels[a.studyType] || a.studyType || 'Study', { background: a.typeBadgeBg || '#e0f2fe', color: a.typeBadgeColor || '#0c4a6e' }));
82 if (a.publicationYear) ap(metaRow, tx('span', 'bkbg-rb-year', a.publicationYear, { color: a.metaColor || '#94a3b8' }));
83 ap(header, metaRow);
84
85 var titleEl = mk('h2', 'bkbg-rb-title', { color: a.headerColor || '#f8fafc' });
86 titleEl.textContent = a.studyTitle || '';
87 ap(header, titleEl);
88
89 var authorRow = mk('div', 'bkbg-rb-author-row');
90 if (a.authors) ap(authorRow, tx('span', 'bkbg-rb-meta-item', '✍️ ' + a.authors, { color: a.metaColor || '#94a3b8' }));
91 if (a.publication) ap(authorRow, tx('span', 'bkbg-rb-meta-item', '📰 ' + a.publication, { color: a.metaColor || '#94a3b8' }));
92 ap(header, authorRow);
93 ap(wrap, header);
94
95 // ── Sample strip ─────────────────────────────────────────────
96 if (a.sampleSize) {
97 var strip = mk('div', 'bkbg-rb-sample-strip', { borderBottomColor: a.borderColor || '#e5e7eb' });
98 var strong = tx('strong', '', 'Sample: ');
99 strip.appendChild(strong);
100 strip.appendChild(document.createTextNode(a.sampleSize));
101 ap(wrap, strip);
102 }
103
104 // ── Body ─────────────────────────────────────────────────────
105 var body = mk('div', 'bkbg-rb-body');
106
107 // Methodology
108 if (a.showMethodology && a.methodology) {
109 var methSection = mk('div');
110 ap(methSection, sectionHead('Methodology', a));
111 var methP = mk('p', 'bkbg-rb-method', { background: a.methodBg || '#f0f9ff', color: a.methodColor || '#374151', margin: 0 });
112 methP.textContent = a.methodology;
113 ap(methSection, methP);
114 ap(body, methSection);
115 }
116
117 // Findings
118 if (a.showFindings && a.findings && a.findings.length) {
119 var findSection = mk('div');
120 ap(findSection, sectionHead(a.findingsLabel || 'Key Findings', a));
121 a.findings.forEach(function (f) {
122 var row = mk('div', 'bkbg-rb-finding', { borderLeftColor: a.accentColor || '#0284c7' });
123 var si = sigInfo(f.significance, a);
124 ap(row, tx('span', 'bkbg-rb-sig-badge', si.label, { background: si.bg, color: si.color }));
125 var p = mk('p', 'bkbg-rb-finding-text', { color: '#374151' });
126 p.textContent = f.finding;
127 ap(row, p);
128 ap(findSection, row);
129 });
130 ap(body, findSection);
131 }
132
133 // Limitations
134 if (a.showLimitations && a.limitations && a.limitations.length) {
135 var limSection = mk('div');
136 ap(limSection, sectionHead(a.limitationsLabel || 'Limitations', a));
137 var ul = mk('ul', 'bkbg-rb-limit-list', { color: a.limitColor || '#7c3aed' });
138 a.limitations.forEach(function (l) { ap(ul, tx('li', '', l)); });
139 ap(limSection, ul);
140 ap(body, limSection);
141 }
142
143 // Takeaways
144 if (a.showTakeaways && a.takeaways && a.takeaways.length) {
145 var tSection = mk('div');
146 ap(tSection, sectionHead(a.takeawaysLabel || 'Practical Takeaways', a));
147 a.takeaways.forEach(function (t) {
148 var row = mk('div', 'bkbg-rb-takeaway', { background: a.takeawayBg || '#f0fdf4', borderLeftColor: a.takeawayBorder || '#16a34a' });
149 ap(row, tx('span', 'bkbg-rb-takeaway-check', '', { color: a.takeawayBorder || '#16a34a' }));
150 ap(row, tx('span', '', t, { color: a.takeawayColor || '#166534' }));
151 ap(tSection, row);
152 });
153 ap(body, tSection);
154 }
155
156 // Source
157 if (a.showSource && a.doi) {
158 var srcDiv = mk('div', 'bkbg-rb-source', { borderTopColor: a.borderColor || '#e5e7eb', color: a.metaColor || '#94a3b8' });
159 srcDiv.appendChild(document.createTextNode('DOI: '));
160 var doiLink = mk('a');
161 doiLink.href = a.sourceUrl || '#';
162 doiLink.target = '_blank';
163 doiLink.rel = 'noopener';
164 doiLink.style.color = a.accentColor || '#0284c7';
165 doiLink.textContent = a.doi;
166 ap(srcDiv, doiLink);
167 ap(body, srcDiv);
168 }
169
170 ap(wrap, body);
171 appEl.appendChild(wrap);
172 });
173 }
174
175 if (document.readyState !== 'loading') { init(); }
176 else { document.addEventListener('DOMContentLoaded', init); }
177 })();
178