PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.11
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.11
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 / icon / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.11, at blocks/icon/frontend.js

161 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 var typoMap = [
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 ['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 function typoCssVarsForEl(typo, prefix, el) {
11 if (!typo || typeof typo !== 'object') return;
12 for (var i = 0; i < typoMap.length; i++) {
13 var v = typo[typoMap[i][0]];
14 if (v !== undefined && v !== '' && v !== null) el.style.setProperty(prefix + typoMap[i][1], String(v));
15 }
16 }
17
18 function init() {
19 document.querySelectorAll('.bkbg-icon-app').forEach(function (appEl) {
20 if (appEl.dataset.rendered) return;
21 appEl.dataset.rendered = '1';
22
23 var opts;
24 try { opts = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { opts = {}; }
25
26 var o = Object.assign({
27 icon: '',
28 shape: 'circle',
29 iconSize: 48,
30 bgSize: 96,
31 showBg: true,
32 borderWidth: 0,
33 shadow: false,
34 animation: 'none',
35 align: 'center',
36 label: '',
37 showLabel: false,
38 subLabel: '',
39 showSubLabel: false,
40 linkUrl: '',
41 linkNewTab: false,
42 containerBg: '',
43 bgColor: '#6366f1',
44 borderColor: '#6366f1',
45 labelColor: '#111827',
46 subLabelColor: '#6b7280',
47 containerPadding: 16,
48 gap: 10,
49 labelSize: 16,
50 subLabelSize: 13,
51 }, opts);
52
53 var alignItems = o.align === 'left' ? 'flex-start' : o.align === 'right' ? 'flex-end' : 'center';
54 var textAlign = o.align;
55
56 var wrap = document.createElement('div');
57 wrap.className = 'bkbg-icon-wrap';
58 wrap.style.display = 'flex';
59 wrap.style.flexDirection = 'column';
60 wrap.style.alignItems = alignItems;
61 wrap.style.gap = o.gap + 'px';
62 wrap.style.padding = o.containerPadding + 'px';
63 if (o.containerBg) wrap.style.background = o.containerBg;
64
65 typoCssVarsForEl(o.labelTypo, '--bkbg-ico-lb-', wrap);
66 typoCssVarsForEl(o.subLabelTypo, '--bkbg-ico-sl-', wrap);
67 wrap.style.setProperty('--bkbg-ico-lb-sz', (o.labelSize || 16) + 'px');
68 wrap.style.setProperty('--bkbg-ico-lb-fw', o.labelFontWeight || '600');
69 wrap.style.setProperty('--bkbg-ico-lb-lh', String(o.labelLineHeight || 1.3));
70 wrap.style.setProperty('--bkbg-ico-sl-sz', (o.subLabelSize || 13) + 'px');
71 wrap.style.setProperty('--bkbg-ico-sl-fw', o.subLabelFontWeight || '400');
72 wrap.style.setProperty('--bkbg-ico-sl-lh', String(o.subLabelLineHeight || 1.4));
73
74 // Shape styles
75 var borderRadius = o.shape === 'circle' ? '50%'
76 : o.shape === 'square' ? '4px'
77 : o.shape === 'rounded' ? '16px'
78 : o.shape === 'pill' ? '999px'
79 : '0';
80
81 var shapeEl = document.createElement('div');
82 shapeEl.className = 'bkbg-icon-shape bkbg-icon-anim-' + o.animation;
83 shapeEl.style.display = 'inline-flex';
84 shapeEl.style.alignItems = 'center';
85 shapeEl.style.justifyContent = 'center';
86 shapeEl.style.fontSize = o.iconSize + 'px';
87 shapeEl.style.lineHeight = '1';
88
89 if (o.shape !== 'none' && o.showBg) {
90 shapeEl.style.width = o.bgSize + 'px';
91 shapeEl.style.height = o.bgSize + 'px';
92 shapeEl.style.borderRadius = borderRadius;
93 shapeEl.style.background = o.bgColor;
94 if (o.borderWidth > 0) {
95 shapeEl.style.border = o.borderWidth + 'px solid ' + o.borderColor;
96 }
97 if (o.shadow) {
98 shapeEl.style.boxShadow = '0 8px 24px rgba(0,0,0,0.18)';
99 }
100 } else if (o.shape !== 'none') {
101 shapeEl.style.borderRadius = borderRadius;
102 shapeEl.style.padding = '8px';
103 if (o.borderWidth > 0) {
104 shapeEl.style.border = o.borderWidth + 'px solid ' + o.borderColor;
105 }
106 }
107
108 var iconSpan = document.createElement('span');
109 iconSpan.textContent = o.icon;
110 iconSpan.style.display = 'block';
111 iconSpan.style.lineHeight = '1';
112 shapeEl.appendChild(iconSpan);
113
114 var iconContainer = shapeEl;
115
116 // Wrap in link if needed
117 if (o.linkUrl) {
118 var linkEl = document.createElement('a');
119 linkEl.href = o.linkUrl;
120 linkEl.className = 'bkbg-icon-link';
121 if (o.linkNewTab) {
122 linkEl.target = '_blank';
123 linkEl.rel = 'noopener noreferrer';
124 }
125 linkEl.appendChild(shapeEl);
126 iconContainer = linkEl;
127 }
128 wrap.appendChild(iconContainer);
129
130 // Label
131 if (o.showLabel && o.label) {
132 var labelEl = document.createElement('div');
133 labelEl.className = 'bkbg-icon-label';
134 labelEl.textContent = o.label;
135 labelEl.style.color = o.labelColor;
136 labelEl.style.textAlign = textAlign;
137 wrap.appendChild(labelEl);
138 }
139
140 // Sub-label
141 if (o.showSubLabel && o.subLabel) {
142 var subEl = document.createElement('div');
143 subEl.className = 'bkbg-icon-sublabel';
144 subEl.textContent = o.subLabel;
145 subEl.style.color = o.subLabelColor;
146 subEl.style.textAlign = textAlign;
147 wrap.appendChild(subEl);
148 }
149
150 appEl.parentNode.insertBefore(wrap, appEl);
151 appEl.style.display = 'none';
152 });
153 }
154
155 if (document.readyState !== 'loading') {
156 init();
157 } else {
158 document.addEventListener('DOMContentLoaded', init);
159 }
160 })();
161