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 / split-form / frontend.js

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

273 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 var RATIO_MAP = { '50-50': [50, 50], '55-45': [55, 45], '45-55': [45, 55], '60-40': [60, 40], '40-60': [40, 60] };
3
4 /* ── Typography CSS-var helper ──────────────────── */
5 var _typoKeys = [
6 ['family','font-family'],['weight','font-weight'],['style','font-style'],
7 ['decoration','text-decoration'],['transform','text-transform']
8 ];
9 var _sizeKeys = [['sizeDesktop','font-size-d'],['sizeTablet','font-size-t'],['sizeMobile','font-size-m']];
10 var _lhKeys = [['lineHeightDesktop','line-height-d'],['lineHeightTablet','line-height-t'],['lineHeightMobile','line-height-m']];
11 var _lsKeys = [['letterSpacingDesktop','letter-spacing-d'],['letterSpacingTablet','letter-spacing-t'],['letterSpacingMobile','letter-spacing-m']];
12 var _wsKeys = [['wordSpacingDesktop','word-spacing-d'],['wordSpacingTablet','word-spacing-t'],['wordSpacingMobile','word-spacing-m']];
13 function typoCssVarsForEl(el, obj, prefix) {
14 if (!obj || typeof obj !== 'object') return;
15 _typoKeys.forEach(function(p) { if (obj[p[0]]) el.style.setProperty(prefix + p[1], obj[p[0]]); });
16 var unit = obj.sizeUnit || 'px';
17 _sizeKeys.forEach(function(p) { if (obj[p[0]]) el.style.setProperty(prefix + p[1], obj[p[0]] + unit); });
18 _lhKeys.forEach(function(p) { if (obj[p[0]]) el.style.setProperty(prefix + p[1], String(obj[p[0]])); });
19 _lsKeys.forEach(function(p) { if (obj[p[0]]) el.style.setProperty(prefix + p[1], obj[p[0]] + 'px'); });
20 _wsKeys.forEach(function(p) { if (obj[p[0]]) el.style.setProperty(prefix + p[1], obj[p[0]] + 'px'); });
21 }
22
23 function init() {
24 document.querySelectorAll('.bkbg-sf-app').forEach(function (appEl) {
25 if (appEl.dataset.rendered) return;
26 appEl.dataset.rendered = '1';
27
28 var opts;
29 try { opts = JSON.parse(appEl.dataset.opts || '{}'); } catch (e) { opts = {}; }
30
31 var o = Object.assign({
32 contentSide: 'left', splitRatio: '50-50',
33 icon: '✉️', showIcon: true,
34 eyebrow: '', showEyebrow: true,
35 heading: 'Get weekly insights straight to your inbox',
36 subtext: '', bullets: [], showBullets: true, bulletIcon: '',
37 useImage: false, imageUrl: '', imageAlt: '', imageOverlay: true,
38 formTitle: 'Subscribe for free', showFormTitle: true, formSubtext: '',
39 showName: true, namePlaceholder: 'Your name',
40 emailPlaceholder: 'Your email address',
41 showPhone: false, phonePlaceholder: 'Phone (optional)',
42 submitLabel: 'Subscribe now →', formAction: '#', formMethod: 'post',
43 privacyNote: 'We respect your privacy. Unsubscribe anytime.',
44 showPrivacy: true, successMsg: '🎉 You\'re in! Check your inbox.',
45 inputRadius: 8, btnRadius: 8, borderRadius: 0,
46 paddingTop: 60, paddingBottom: 60,
47 bgColor: '#1e1b4b', contentBg: '', formBg: '#ffffff',
48 eyebrowColor: '#a5b4fc', headingColor: '#ffffff', subtextColor: '#c7d2fe',
49 bulletColor: '#c7d2fe', bulletIconColor: '#818cf8',
50 formHeadingColor: '#111827', formSubtextColor: '#6b7280',
51 inputBorder: '#d1d5db', inputFocusBorder: '#6366f1',
52 inputBg: '#f9fafb', inputColor: '#111827',
53 btnBg: '#6366f1', btnColor: '#ffffff', privacyColor: '#9ca3af'
54 }, opts);
55
56 var ratio = RATIO_MAP[o.splitRatio] || [50, 50];
57 var contentFlex = o.contentSide === 'left' ? ratio[0] : ratio[1];
58 var formFlex = o.contentSide === 'left' ? ratio[1] : ratio[0];
59
60 /* Outer section */
61 var section = document.createElement('section');
62 section.className = 'bkbg-sf-section';
63 section.style.cssText = [
64 'background:' + o.bgColor,
65 'padding-top:' + o.paddingTop + 'px',
66 'padding-bottom:' + o.paddingBottom + 'px',
67 'border-radius:' + o.borderRadius + 'px'
68 ].join(';');
69
70 /* Legacy CSS vars */
71 if (o.eyebrowFontSize) section.style.setProperty('--bksf-eb-sz', o.eyebrowFontSize + 'px');
72 if (o.eyebrowFontWeight) section.style.setProperty('--bksf-eb-w', String(o.eyebrowFontWeight));
73 if (o.headingFontSize) section.style.setProperty('--bksf-hd-sz', o.headingFontSize + 'px');
74 if (o.headingFontWeight) section.style.setProperty('--bksf-hd-w', String(o.headingFontWeight));
75 if (o.subtextFontSize) section.style.setProperty('--bksf-st-sz', o.subtextFontSize + 'px');
76 if (o.formTitleFontSize) section.style.setProperty('--bksf-ft-sz', o.formTitleFontSize + 'px');
77 if (o.formTitleFontWeight) section.style.setProperty('--bksf-ft-w', String(o.formTitleFontWeight));
78 /* Typo CSS vars */
79 typoCssVarsForEl(section, o.eyebrowTypo, '--bksf-eb-');
80 typoCssVarsForEl(section, o.headingTypo, '--bksf-hd-');
81 typoCssVarsForEl(section, o.subtextTypo, '--bksf-st-');
82 typoCssVarsForEl(section, o.formTitleTypo, '--bksf-ft-');
83 typoCssVarsForEl(section, o.bulletTypo, '--bksf-bl-');
84
85 var panels = document.createElement('div');
86 panels.className = 'bkbg-sf-panels';
87
88 /* ── Content panel ─────────────────────────────── */
89 var contentPanel = document.createElement('div');
90 contentPanel.className = 'bkbg-sf-content';
91 contentPanel.style.cssText = 'flex:' + contentFlex + ';' + (o.contentBg ? 'background:' + o.contentBg : '');
92
93 if (o.useImage && o.imageUrl) {
94 contentPanel.style.backgroundImage = 'url(' + o.imageUrl + ')';
95 contentPanel.style.backgroundSize = 'cover';
96 contentPanel.style.backgroundPosition = 'center';
97 if (o.imageOverlay) {
98 var ov = document.createElement('div');
99 ov.className = 'bkbg-sf-overlay';
100 ov.style.background = 'rgba(0,0,0,.45)';
101 contentPanel.appendChild(ov);
102 }
103 }
104
105 var contentInner = document.createElement('div');
106 contentInner.className = 'bkbg-sf-content-inner';
107
108 if (o.showIcon && o.icon) {
109 var iconEl = document.createElement('div');
110 iconEl.className = 'bkbg-sf-icon';
111 var _IP = window.bkbgIconPicker;
112 var _iType = o.iconType || 'custom-char';
113 if (_IP && _iType !== 'custom-char') {
114 var _in = _IP.buildFrontendIcon(_iType, o.icon, o.iconDashicon, o.iconImageUrl, o.iconDashiconColor);
115 if (_in) iconEl.appendChild(_in);
116 else iconEl.textContent = o.icon;
117 } else {
118 iconEl.textContent = o.icon;
119 }
120 contentInner.appendChild(iconEl);
121 }
122 if (o.showEyebrow && o.eyebrow) {
123 var ey = document.createElement('p');
124 ey.className = 'bkbg-sf-eyebrow';
125 ey.innerHTML = o.eyebrow;
126 ey.style.color = o.eyebrowColor;
127 contentInner.appendChild(ey);
128 }
129
130 var h = document.createElement('h2');
131 h.className = 'bkbg-sf-heading';
132 h.innerHTML = o.heading;
133 h.style.color = o.headingColor;
134 contentInner.appendChild(h);
135
136 if (o.subtext) {
137 var sub = document.createElement('p');
138 sub.className = 'bkbg-sf-text';
139 sub.innerHTML = o.subtext;
140 sub.style.color = o.subtextColor;
141 contentInner.appendChild(sub);
142 }
143
144 if (o.showBullets && o.bullets && o.bullets.length) {
145 var ul = document.createElement('ul');
146 ul.className = 'bkbg-sf-bullets';
147 o.bullets.forEach(function (b) {
148 var li = document.createElement('li');
149 li.className = 'bkbg-sf-bullet';
150 li.style.color = o.bulletColor;
151 var ico = document.createElement('span');
152 ico.className = 'bkbg-sf-bullet-icon';
153 var _bIP = window.bkbgIconPicker;
154 var _bType = o.bulletIconType || 'custom-char';
155 if (_bIP && _bType !== 'custom-char') {
156 var _bn = _bIP.buildFrontendIcon(_bType, o.bulletIcon, o.bulletIconDashicon, o.bulletIconImageUrl, o.bulletIconDashiconColor);
157 if (_bn) ico.appendChild(_bn);
158 else ico.textContent = o.bulletIcon;
159 } else {
160 ico.textContent = o.bulletIcon;
161 }
162 ico.style.color = o.bulletIconColor;
163 li.appendChild(ico);
164 var txt = document.createElement('span');
165 txt.textContent = b.text;
166 li.appendChild(txt);
167 ul.appendChild(li);
168 });
169 contentInner.appendChild(ul);
170 }
171
172 contentPanel.appendChild(contentInner);
173
174 /* ── Form panel ────────────────────────────────── */
175 var formPanel = document.createElement('div');
176 formPanel.className = 'bkbg-sf-form-panel';
177 formPanel.style.cssText = 'flex:' + formFlex + ';background:' + o.formBg;
178
179 if (o.showFormTitle && o.formTitle) {
180 var ft = document.createElement('h3');
181 ft.className = 'bkbg-sf-form-title';
182 ft.textContent = o.formTitle;
183 ft.style.color = o.formHeadingColor;
184 formPanel.appendChild(ft);
185 }
186 if (o.formSubtext) {
187 var fs = document.createElement('p');
188 fs.className = 'bkbg-sf-form-subtext';
189 fs.textContent = o.formSubtext;
190 fs.style.color = o.formHeadingColor;
191 formPanel.appendChild(fs);
192 }
193
194 /* Success message (hidden) */
195 var successEl = document.createElement('div');
196 successEl.className = 'bkbg-sf-success';
197 successEl.style.color = o.formHeadingColor;
198 successEl.textContent = o.successMsg;
199 formPanel.appendChild(successEl);
200
201 /* Form */
202 var form = document.createElement('form');
203 form.className = 'bkbg-sf-form';
204 form.action = o.formAction || '#';
205 form.method = o.formMethod || 'post';
206
207 var inputCss = 'border-radius:' + o.inputRadius + 'px;background:' + o.inputBg + ';border-color:' + o.inputBorder + ';color:' + o.inputColor;
208
209 if (o.showName) {
210 form.appendChild(makeInput('text', o.namePlaceholder, 'name', inputCss, o.inputFocusBorder, o.inputBorder));
211 }
212
213 form.appendChild(makeInput('email', o.emailPlaceholder, 'email', inputCss, o.inputFocusBorder, o.inputBorder));
214
215 if (o.showPhone) {
216 form.appendChild(makeInput('tel', o.phonePlaceholder, 'phone', inputCss, o.inputFocusBorder, o.inputBorder));
217 }
218
219 var btn = document.createElement('button');
220 btn.type = 'submit';
221 btn.className = 'bkbg-sf-submit';
222 btn.textContent = o.submitLabel;
223 btn.style.cssText = 'background:' + o.btnBg + ';color:' + o.btnColor + ';border-radius:' + o.btnRadius + 'px';
224 form.appendChild(btn);
225
226 if (o.showPrivacy && o.privacyNote) {
227 var priv = document.createElement('p');
228 priv.className = 'bkbg-sf-privacy';
229 priv.textContent = o.privacyNote;
230 priv.style.color = o.privacyColor;
231 form.appendChild(priv);
232 }
233
234 /* Submit handler (prevent default, show success) */
235 form.addEventListener('submit', function (e) {
236 if (!o.formAction || o.formAction === '#') {
237 e.preventDefault();
238 form.style.display = 'none';
239 successEl.classList.add('is-visible');
240 }
241 });
242
243 formPanel.appendChild(form);
244
245 /* ── Assemble ──────────────────────────────────── */
246 if (o.contentSide === 'left') {
247 panels.appendChild(contentPanel);
248 panels.appendChild(formPanel);
249 } else {
250 panels.appendChild(formPanel);
251 panels.appendChild(contentPanel);
252 }
253
254 section.appendChild(panels);
255 appEl.parentNode.insertBefore(section, appEl);
256 });
257 }
258
259 function makeInput(type, placeholder, name, css, focusBorder, defaultBorder) {
260 var inp = document.createElement('input');
261 inp.type = type;
262 inp.placeholder = placeholder;
263 inp.name = name;
264 inp.style.cssText = css;
265 inp.addEventListener('focus', function () { inp.style.borderColor = focusBorder; inp.style.borderWidth = '2px'; });
266 inp.addEventListener('blur', function () { inp.style.borderColor = defaultBorder; inp.style.borderWidth = '1px'; });
267 return inp;
268 }
269
270 if (document.readyState !== 'loading') { init(); }
271 else { document.addEventListener('DOMContentLoaded', init); }
272 })();
273