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 / troubleshooting-guide / frontend.js

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

249 lines 12.4 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 mkText(tag, cls, text, styles) {
11 var d = mk(tag, cls, styles);
12 d.textContent = text;
13 return d;
14 }
15
16 function getSevStyle(s, o) {
17 if (s === 'critical') return { background: o.criticalBg, color: o.criticalColor };
18 if (s === 'high') return { background: o.highBg, color: o.highColor };
19 if (s === 'medium') return { background: o.mediumBg, color: o.mediumColor };
20 return { background: o.lowBg, color: o.lowColor };
21 }
22
23 function getSevLabel(s) {
24 if (s === 'critical') return '🔴 Critical';
25 if (s === 'high') return '🟠 High';
26 if (s === 'medium') return '🟡 Medium';
27 return '🟢 Low';
28 }
29
30 function init() {
31 document.querySelectorAll('.bkbg-troubleshooting-guide-app').forEach(function (appEl) {
32 if (appEl.dataset.rendered) return;
33 appEl.dataset.rendered = '1';
34
35 var opts; try { opts = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { opts = {}; }
36
37 var o = {
38 blockTitle: opts.blockTitle || 'Troubleshooting Guide',
39 showTitle: opts.showTitle !== false,
40 blockSubtitle: opts.blockSubtitle || '',
41 showSubtitle: opts.showSubtitle !== false,
42 issues: opts.issues || [],
43 layout: opts.layout || 'cards',
44 style: opts.style || 'bordered',
45 showCause: opts.showCause !== false,
46 showSeverity: opts.showSeverity !== false,
47 showNumbers: opts.showNumbers !== false,
48 enableSearch: opts.enableSearch !== false,
49 searchPlaceholder: opts.searchPlaceholder || 'Search issues…',
50 collapsible: opts.collapsible || false,
51 borderRadius: opts.borderRadius !== undefined ? opts.borderRadius : 10,
52 gap: opts.gap !== undefined ? opts.gap : 14,
53 fontSize: opts.fontSize !== undefined ? opts.fontSize : 14,
54 problemFontSize: opts.problemFontSize !== undefined ? opts.problemFontSize : 16,
55 titleFontSize: opts.titleFontSize !== undefined ? opts.titleFontSize : 26,
56 bgColor: opts.bgColor || '',
57 cardBg: opts.cardBg || '#ffffff',
58 borderColor: opts.borderColor || '#e2e8f0',
59 titleColor: opts.titleColor || '#0f172a',
60 subtitleColor: opts.subtitleColor || '#64748b',
61 problemColor: opts.problemColor || '#1e293b',
62 causeColor: opts.causeColor || '#475569',
63 solutionColor: opts.solutionColor || '#374151',
64 solutionBg: opts.solutionBg || '#f0fdf4',
65 solutionBorderColor:opts.solutionBorderColor || '#86efac',
66 labelColor: opts.labelColor || '#64748b',
67 criticalBg: opts.criticalBg || '#fee2e2',
68 criticalColor: opts.criticalColor || '#991b1b',
69 highBg: opts.highBg || '#ffedd5',
70 highColor: opts.highColor || '#9a3412',
71 mediumBg: opts.mediumBg || '#fef9c3',
72 mediumColor: opts.mediumColor || '#854d0e',
73 lowBg: opts.lowBg || '#f0fdf4',
74 lowColor: opts.lowColor || '#166534'
75 };
76
77 var isCompact = o.layout === 'compact';
78 var isLeftAccent = o.style === 'left-accent';
79 var isFlat = o.style === 'flat';
80
81 /* ── Outer block ─────────────────────────────────── */
82 var block = mk('div', 'bkbg-tg-block');
83 if (o.bgColor) block.style.background = o.bgColor;
84
85 /* ── Header ──────────────────────────────────────── */
86 if ((o.showTitle && o.blockTitle) || (o.showSubtitle && o.blockSubtitle)) {
87 var header = mk('div', 'bkbg-tg-header', { marginBottom: '20px' });
88 if (o.showTitle && o.blockTitle) {
89 header.appendChild(mkText('h3', 'bkbg-tg-title', o.blockTitle, {
90 color: o.titleColor, margin: '0 0 8px'
91 }));
92 }
93 if (o.showSubtitle && o.blockSubtitle) {
94 header.appendChild(mkText('p', 'bkbg-tg-subtitle', o.blockSubtitle, {
95 fontSize: '15px', color: o.subtitleColor, margin: '0'
96 }));
97 }
98 block.appendChild(header);
99 }
100
101 /* ── Search ──────────────────────────────────────── */
102 var searchInput = null;
103 if (o.enableSearch) {
104 var searchWrap = mk('div', 'bkbg-tg-search-wrap', { marginBottom: o.gap + 'px' });
105 searchInput = mk('input', 'bkbg-tg-search', {
106 width: '100%', padding: '10px 14px 10px 38px', boxSizing: 'border-box',
107 border: '1px solid ' + o.borderColor, borderRadius: o.borderRadius + 'px',
108 fontSize: '14px', fontFamily: 'inherit'
109 });
110 searchInput.type = 'text';
111 searchInput.placeholder = o.searchPlaceholder;
112 searchWrap.appendChild(searchInput);
113 block.appendChild(searchWrap);
114 }
115
116 /* ── Issues ──────────────────────────────────────── */
117 var list = mk('div', 'bkbg-tg-list' + (isCompact ? ' is-compact' : ''), {
118 display: 'flex', flexDirection: 'column', gap: o.gap + 'px'
119 });
120 list.style.setProperty('--bkbg-tg-border', o.borderColor);
121
122 var issueEls = o.issues.map(function (iss, idx) {
123 var sevStyle = getSevStyle(iss.severity || 'medium', o);
124
125 var card = mk('div', 'bkbg-tg-issue' + (isFlat ? ' is-flat' : '') + (o.collapsible ? ' is-collapsible' : ''));
126 card.style.background = o.cardBg;
127 if (!isFlat) {
128 card.style.border = '1px solid ' + o.borderColor;
129 card.style.borderRadius = o.borderRadius + 'px';
130 }
131 if (isLeftAccent) { card.style.borderLeft = '4px solid ' + sevStyle.color; }
132
133 /* Track search text on element for filtering */
134 card.dataset.searchText = ((iss.problem || '') + ' ' + (iss.cause || '') + ' ' + (iss.solution || '')).toLowerCase();
135
136 /* Problem row */
137 var problemRow = mk('div', 'bkbg-tg-problem-row');
138 problemRow.style.borderBottom = '1px solid ' + o.borderColor;
139
140 if (o.showNumbers) {
141 problemRow.appendChild(mkText('span', 'bkbg-tg-number-badge', String(idx + 1), {
142 background: o.borderColor, color: o.problemColor
143 }));
144 }
145
146 problemRow.appendChild(mkText('span', 'bkbg-tg-problem-text', iss.problem || '', {
147 color: o.problemColor
148 }));
149
150 if (o.showSeverity) {
151 problemRow.appendChild(mkText('span', 'bkbg-tg-severity', getSevLabel(iss.severity || 'medium'), sevStyle));
152 }
153
154 if (o.collapsible) {
155 var toggleBtn = mk('button', 'bkbg-tg-toggle');
156 toggleBtn.textContent = 'Details';
157 var arrow = mkText('span', 'bkbg-tg-arrow', '');
158 toggleBtn.appendChild(arrow);
159 problemRow.appendChild(toggleBtn);
160 }
161
162 card.appendChild(problemRow);
163
164 /* Body (cause + solution) */
165 var body = mk('div', 'bkbg-tg-body');
166
167 if (o.showCause && iss.cause) {
168 var causeCol = mk('div', 'bkbg-tg-cause-col', {
169 padding: '10px 18px',
170 borderBottom: '1px solid ' + o.borderColor
171 });
172 causeCol.appendChild(mkText('span', 'bkbg-tg-col-label', 'Cause', { color: o.labelColor }));
173 causeCol.appendChild(mkText('span', 'bkbg-tg-cause-text', iss.cause, {
174 color: o.causeColor, display: 'block'
175 }));
176 body.appendChild(causeCol);
177 }
178
179 if (iss.solution) {
180 var solCol = mk('div', 'bkbg-tg-solution-col', {
181 padding: '10px 18px',
182 background: o.solutionBg,
183 borderTop: '1px solid ' + o.solutionBorderColor
184 });
185 solCol.appendChild(mkText('span', 'bkbg-tg-col-label', '✔ Solution', { color: '#166534' }));
186 solCol.appendChild(mkText('span', 'bkbg-tg-solution-text', iss.solution, {
187 color: o.solutionColor, display: 'block'
188 }));
189 body.appendChild(solCol);
190 }
191
192 card.appendChild(body);
193
194 /* Collapsible toggle */
195 if (o.collapsible) {
196 body.style.maxHeight = '0';
197 body.style.overflow = 'hidden';
198 body.style.transition = 'max-height .3s ease';
199
200 var toggleBtnRef = problemRow.querySelector('.bkbg-tg-toggle');
201 toggleBtnRef.addEventListener('click', function () {
202 var isOpen = card.classList.contains('is-open');
203 if (isOpen) {
204 body.style.maxHeight = '0';
205 card.classList.remove('is-open');
206 } else {
207 body.style.maxHeight = body.scrollHeight + 'px';
208 card.classList.add('is-open');
209 }
210 });
211 }
212
213 return card;
214 });
215
216 issueEls.forEach(function (el) { list.appendChild(el); });
217
218 /* No-results message */
219 var noResults = mkText('div', 'bkbg-tg-no-results', 'No matching issues found.', {
220 textAlign: 'center', padding: '20px', color: '#94a3b8', fontSize: '14px', display: 'none'
221 });
222 list.appendChild(noResults);
223
224 block.appendChild(list);
225
226 /* ── Search filtering ────────────────────────────── */
227 if (searchInput) {
228 searchInput.addEventListener('input', function () {
229 var q = searchInput.value.toLowerCase().trim();
230 var visible = 0;
231 issueEls.forEach(function (card) {
232 var match = !q || card.dataset.searchText.indexOf(q) !== -1;
233 card.style.display = match ? '' : 'none';
234 if (match) visible++;
235 });
236 noResults.style.display = visible === 0 ? 'block' : 'none';
237 });
238 }
239
240 /* ── Insert ──────────────────────────────────────── */
241 appEl.parentNode.insertBefore(block, appEl);
242 appEl.style.display = 'none';
243 });
244 }
245
246 if (document.readyState !== 'loading') { init(); }
247 else { document.addEventListener('DOMContentLoaded', init); }
248 })();
249