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 / offer-card / frontend.js

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

213 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 wp.domReady(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 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(el, obj, prefix) {
11 if (!obj || typeof obj !== 'object') return;
12 Object.keys(_typoKeys).forEach(function (k) {
13 var v = obj[k];
14 if (v === undefined || v === '' || v === null) return;
15 if (k === 'sizeDesktop' || k === 'sizeTablet' || k === 'sizeMobile') v = v + (obj.sizeUnit || 'px');
16 else if (k === 'lineHeightDesktop' || k === 'lineHeightTablet' || k === 'lineHeightMobile') v = v + (obj.lineHeightUnit || '');
17 else if (k === 'letterSpacingDesktop' || k === 'letterSpacingTablet' || k === 'letterSpacingMobile') v = v + (obj.letterSpacingUnit || 'px');
18 else if (k === 'wordSpacingDesktop' || k === 'wordSpacingTablet' || k === 'wordSpacingMobile') v = v + (obj.wordSpacingUnit || 'px');
19 el.style.setProperty(prefix + _typoKeys[k], String(v));
20 });
21 }
22
23 document.querySelectorAll('.bkbg-ofr-app').forEach(function (el) {
24 var attr = JSON.parse(el.dataset.opts || '{}');
25 var wrap = document.createElement('div');
26 wrap.className = 'bkbg-ofr-wrap';
27 wrap.style.background = attr.bgColor || '#ffffff';
28 wrap.style.paddingTop = (attr.paddingTop || 64) + 'px';
29 wrap.style.paddingBottom = (attr.paddingBottom || 64) + 'px';
30 typoCssVarsForEl(wrap, attr.headingTypo, '--bkbg-ofr-hd-');
31 typoCssVarsForEl(wrap, attr.descTypo, '--bkbg-ofr-ds-');
32 typoCssVarsForEl(wrap, attr.ctaTypo, '--bkbg-ofr-ct-');
33
34 var card = document.createElement('div');
35 var layoutClass = attr.layout === 'banner' ? ' bkbg-ofr-card--banner' : attr.layout === 'minimal' ? ' bkbg-ofr-card--minimal' : '';
36 card.className = 'bkbg-ofr-card' + layoutClass;
37 card.style.setProperty('--ofr-card-bg', attr.cardBg || '#ffffff');
38 card.style.setProperty('--ofr-border', attr.borderColor || '#e5e7eb');
39 card.style.setProperty('--ofr-radius', (attr.borderRadius || 16) + 'px');
40 card.style.maxWidth = (attr.maxWidth || 540) + 'px';
41
42 var isBanner = attr.layout === 'banner';
43
44 /* ---- MAIN section ---- */
45 var main = document.createElement('div');
46 main.className = 'bkbg-ofr-main';
47
48 if (attr.showBadge && attr.badge) {
49 var badge = document.createElement('div');
50 badge.style.marginBottom = '16px';
51 var badgePill = document.createElement('span');
52 badgePill.className = 'bkbg-ofr-badge bkbg-ofr-badge--' + (attr.badgeStyle || 'hot');
53 badgePill.style.background = attr.badgeBg || '#fef2f2';
54 badgePill.style.color = attr.badgeColor || '#b91c1c';
55 badgePill.innerHTML = attr.badge;
56 badge.appendChild(badgePill);
57 main.appendChild(badge);
58 }
59
60 var heading = document.createElement('h3');
61 heading.className = 'bkbg-ofr-heading';
62 heading.style.color = attr.headingColor || '#111827';
63 heading.innerHTML = attr.heading || '';
64 main.appendChild(heading);
65
66 if (attr.description) {
67 var desc = document.createElement('p');
68 desc.className = 'bkbg-ofr-desc';
69 desc.style.color = attr.descColor || '#6b7280';
70 desc.innerHTML = attr.description;
71 main.appendChild(desc);
72 }
73
74 if (attr.showPrice) {
75 var priceRow = document.createElement('div');
76 priceRow.className = 'bkbg-ofr-price-row';
77
78 var salePrice = document.createElement('span');
79 salePrice.className = 'bkbg-ofr-sale-price';
80 salePrice.style.color = attr.priceColor || '#111827';
81 salePrice.textContent = (attr.currency || '$') + (attr.salePrice || '0');
82 priceRow.appendChild(salePrice);
83
84 if (attr.originalPrice) {
85 var orig = document.createElement('span');
86 orig.className = 'bkbg-ofr-original-price';
87 orig.style.color = attr.strikethroughColor || '#9ca3af';
88 orig.textContent = (attr.currency || '$') + attr.originalPrice;
89 priceRow.appendChild(orig);
90 }
91
92 main.appendChild(priceRow);
93 }
94
95 /* If banner, append main now, action comes separately */
96 if (isBanner) {
97 card.appendChild(main);
98 }
99
100 /* ---- ACTION section ---- */
101 var action = document.createElement('div');
102 action.className = 'bkbg-ofr-action';
103
104 /* Countdown */
105 if (attr.showCountdown && attr.countdownEnd) {
106 var endDate = new Date(attr.countdownEnd).getTime();
107 var cdWrap = document.createElement('div');
108 cdWrap.className = 'bkbg-ofr-countdown';
109
110 var units = [
111 { key: 'd', label: 'Days', ms: 86400000 },
112 { key: 'h', label: 'Hrs', ms: 3600000 },
113 { key: 'm', label: 'Min', ms: 60000 },
114 { key: 's', label: 'Sec', ms: 1000 }
115 ];
116
117 var numSpans = {};
118 units.forEach(function (unit) {
119 var box = document.createElement('div');
120 box.className = 'bkbg-ofr-countdown-unit';
121 var num = document.createElement('span');
122 num.className = 'bkbg-ofr-countdown-num';
123 num.textContent = '00';
124 numSpans[unit.key] = num;
125 var lbl = document.createElement('span');
126 lbl.className = 'bkbg-ofr-countdown-lbl';
127 lbl.textContent = unit.label;
128 box.appendChild(num);
129 box.appendChild(lbl);
130 cdWrap.appendChild(box);
131 });
132
133 function updateTimer() {
134 var diff = endDate - Date.now();
135 if (diff <= 0) {
136 units.forEach(function (u) { numSpans[u.key].textContent = '00'; });
137 return;
138 }
139 var d = Math.floor(diff / 86400000);
140 var h = Math.floor((diff % 86400000) / 3600000);
141 var m = Math.floor((diff % 3600000) / 60000);
142 var s = Math.floor((diff % 60000) / 1000);
143 numSpans.d.textContent = String(d).padStart(2, '0');
144 numSpans.h.textContent = String(h).padStart(2, '0');
145 numSpans.m.textContent = String(m).padStart(2, '0');
146 numSpans.s.textContent = String(s).padStart(2, '0');
147 }
148
149 updateTimer();
150 setInterval(updateTimer, 1000);
151 action.appendChild(cdWrap);
152 }
153
154 /* Includes */
155 if (attr.showIncludes && attr.includes && attr.includes.length) {
156 var ul = document.createElement('ul');
157 ul.className = 'bkbg-ofr-includes';
158 attr.includes.forEach(function (item) {
159 if (!item.text) return;
160 var li = document.createElement('li');
161 li.className = 'bkbg-ofr-include-item';
162 li.style.color = attr.includeColor || '#374151';
163
164 var chk = document.createElement('span');
165 chk.className = 'bkbg-ofr-check';
166 chk.style.color = attr.checkColor || '#16a34a';
167 chk.textContent = '';
168
169 var txt = document.createElement('span');
170 txt.textContent = item.text;
171
172 li.appendChild(chk);
173 li.appendChild(txt);
174 ul.appendChild(li);
175 });
176 action.appendChild(ul);
177 }
178
179 /* CTA */
180 var cta = document.createElement('a');
181 cta.className = 'bkbg-ofr-cta';
182 cta.href = attr.ctaUrl || '#';
183 cta.style.background = attr.ctaBg || '#7c3aed';
184 cta.style.color = attr.ctaColor || '#ffffff';
185 if (attr.ctaOpenNewTab) {
186 cta.target = '_blank';
187 cta.rel = 'noopener noreferrer';
188 }
189 cta.textContent = attr.ctaLabel || 'Get access';
190 action.appendChild(cta);
191
192 /* Disclaimer */
193 if (attr.showDisclaimer && attr.disclaimer) {
194 var disc = document.createElement('p');
195 disc.className = 'bkbg-ofr-disclaimer';
196 disc.style.color = attr.disclaimerColor || '#9ca3af';
197 disc.innerHTML = attr.disclaimer;
198 action.appendChild(disc);
199 }
200
201 if (isBanner) {
202 card.appendChild(action);
203 } else {
204 /* stacked: main content then action */
205 card.appendChild(main);
206 card.appendChild(action);
207 }
208
209 wrap.appendChild(card);
210 el.replaceWith(wrap);
211 });
212 });
213