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 / link-roundup / frontend.js

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

211 lines 8.4 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 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 letterSpacing: 'letter-spacing', wordSpacing: 'word-spacing'
8 };
9 function typoCssVarsForEl(el, obj, prefix) {
10 if (!obj || typeof obj !== 'object') return;
11 var unitProps = { 'font-size-d':1,'font-size-t':1,'font-size-m':1,'letter-spacing':1,'word-spacing':1 };
12 Object.keys(_typoKeys).forEach(function (k) {
13 if (obj[k] == null || obj[k] === '') return;
14 var css = _typoKeys[k];
15 var v = obj[k];
16 if (unitProps[css] && typeof v === 'number') v = v + 'px';
17 el.style.setProperty(prefix + css, '' + v);
18 });
19 }
20
21 function esc(str) {
22 return String(str || '').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
23 }
24
25 function buildCard(lnk, o, styleKey) {
26 var card = document.createElement('div');
27 card.className = 'bkbg-lru-card bkbg-lru-' + styleKey + '-card';
28 card.style.cssText = 'background:' + o.cardBg + ';border:1px solid ' + o.cardBorder + ';border-radius:' + o.cardRadius + 'px;';
29 if (styleKey === 'magazine') {
30 card.style.borderLeft = '4px solid ' + o.accentColor;
31 }
32
33 if (o.showEmoji && (lnk.emoji || lnk.emojiType === 'dashicon' || lnk.emojiType === 'image')) {
34 var emojiEl = document.createElement('div');
35 emojiEl.className = 'bkbg-lru-card-emoji';
36 var _IP = window.bkbgIconPicker;
37 var _et = lnk.emojiType || 'custom-char';
38 if (_IP && _et !== 'custom-char') {
39 var _in = _IP.buildFrontendIcon(_et, lnk.emoji, lnk.emojiDashicon, lnk.emojiImageUrl, lnk.emojiDashiconColor);
40 if (_in) emojiEl.appendChild(_in); else emojiEl.textContent = lnk.emoji || '🔗';
41 } else { emojiEl.textContent = lnk.emoji || '🔗'; }
42 card.appendChild(emojiEl);
43 }
44
45 var body = document.createElement('div');
46 body.className = 'bkbg-lru-card-body';
47
48 var titleRow = document.createElement('div');
49 titleRow.className = 'bkbg-lru-link-title-row';
50
51 var link = document.createElement('a');
52 link.className = 'bkbg-lru-link';
53 link.href = lnk.url || '#';
54 link.style.color = o.linkColor;
55 link.innerHTML = lnk.title || '';
56 if (o.openInNewTab) { link.target = '_blank'; link.rel = 'noopener noreferrer'; }
57 titleRow.appendChild(link);
58
59 if (o.showCategory && lnk.category) {
60 var catTag = document.createElement('span');
61 catTag.className = 'bkbg-lru-cat-tag';
62 catTag.style.cssText = 'background:' + o.catBg + ';color:' + o.catColor;
63 catTag.textContent = lnk.category;
64 titleRow.appendChild(catTag);
65 }
66 body.appendChild(titleRow);
67
68 if (o.showSource && lnk.source) {
69 var src = document.createElement('div');
70 src.className = 'bkbg-lru-source';
71 src.style.color = o.sourceColor;
72 src.textContent = '' + lnk.source;
73 body.appendChild(src);
74 }
75
76 if (o.showExcerpt && lnk.excerpt) {
77 var exc = document.createElement('p');
78 exc.className = 'bkbg-lru-excerpt';
79 exc.style.color = o.excerptColor;
80 exc.textContent = lnk.excerpt;
81 body.appendChild(exc);
82 }
83
84 card.appendChild(body);
85 return card;
86 }
87
88 function init() {
89 document.querySelectorAll('.bkbg-lru-app').forEach(function (el) {
90 if (el.dataset.rendered) return;
91 el.dataset.rendered = '1';
92
93 var opts;
94 try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; }
95
96 var o = Object.assign({
97 title: "This Week's Reads",
98 subtitle: '',
99 showSubtitle: true,
100 publishDate: '',
101 dateLabel: 'Week of',
102 showDate: true,
103 links: [],
104 style: 'cards',
105 groupByCategory: false,
106 showEmoji: true,
107 showSource: true,
108 showExcerpt: true,
109 showCategory: true,
110 openInNewTab: true,
111 bgColor: '#f8fafc',
112 borderColor: '#e2e8f0',
113 headingColor: '#0f172a',
114 subtitleColor: '#64748b',
115 dateColor: '#94a3b8',
116 cardBg: '#ffffff',
117 cardBorder: '#e2e8f0',
118 linkColor: '#2563eb',
119 sourceColor: '#94a3b8',
120 excerptColor: '#475569',
121 catBg: '#e0f2fe',
122 catColor: '#0369a1',
123 accentColor: '#2563eb',
124 borderRadius: 12,
125 cardRadius: 8,
126 paddingTop: 0,
127 paddingBottom: 0
128 }, opts);
129
130 var wrap = document.createElement('div');
131 wrap.className = 'bkbg-lru-wrap';
132 wrap.style.cssText = [
133 'background:' + o.bgColor,
134 'border-radius:' + o.borderRadius + 'px',
135 'padding-top:' + o.paddingTop + 'px',
136 'padding-bottom:' + o.paddingBottom + 'px'
137 ].join(';');
138
139 typoCssVarsForEl(wrap, o.titleTypo, '--bkbg-lru-tt-');
140 typoCssVarsForEl(wrap, o.subtitleTypo, '--bkbg-lru-st-');
141 typoCssVarsForEl(wrap, o.itemTypo, '--bkbg-lru-it-');
142
143 /* header */
144 if (o.showDate && o.publishDate) {
145 var dateEl = document.createElement('div');
146 dateEl.className = 'bkbg-lru-date-label';
147 dateEl.style.color = o.dateColor;
148 dateEl.textContent = o.dateLabel + ' ' + o.publishDate;
149 wrap.appendChild(dateEl);
150 }
151
152 if (o.title) {
153 var h2 = document.createElement('h2');
154 h2.className = 'bkbg-lru-title';
155 h2.style.color = o.headingColor;
156 h2.innerHTML = o.title;
157 wrap.appendChild(h2);
158 }
159
160 if (o.showSubtitle && o.subtitle) {
161 var sub = document.createElement('p');
162 sub.className = 'bkbg-lru-subtitle';
163 sub.style.color = o.subtitleColor;
164 sub.innerHTML = o.subtitle;
165 wrap.appendChild(sub);
166 }
167
168 var styleKey = o.style === 'magazine' ? 'magazine' : o.style === 'list' ? 'list' : 'card';
169 var gridClass = 'bkbg-lru-grid bkbg-lru-' + o.style + '-style';
170
171 if (o.groupByCategory && (o.links || []).length) {
172 /* group links by category */
173 var cats = {};
174 var catOrder = [];
175 (o.links || []).forEach(function (lnk) {
176 var cat = lnk.category || 'General';
177 if (!cats[cat]) { cats[cat] = []; catOrder.push(cat); }
178 cats[cat].push(lnk);
179 });
180
181 catOrder.forEach(function (cat) {
182 var catTitle = document.createElement('div');
183 catTitle.className = 'bkbg-lru-cat-group-title';
184 catTitle.style.color = o.linkColor;
185 catTitle.textContent = cat;
186 wrap.appendChild(catTitle);
187
188 var grid = document.createElement('div');
189 grid.className = gridClass;
190 cats[cat].forEach(function (lnk) {
191 grid.appendChild(buildCard(lnk, o, styleKey));
192 });
193 wrap.appendChild(grid);
194 });
195 } else {
196 var grid = document.createElement('div');
197 grid.className = gridClass;
198 (o.links || []).forEach(function (lnk) {
199 grid.appendChild(buildCard(lnk, o, styleKey));
200 });
201 wrap.appendChild(grid);
202 }
203
204 el.parentNode.insertBefore(wrap, el);
205 });
206 }
207
208 if (document.readyState !== 'loading') { init(); }
209 else { document.addEventListener('DOMContentLoaded', init); }
210 })();
211