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 / popup / index.js

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

316 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 var el = wp.element.createElement;
3 var __ = wp.i18n.__;
4 var useState = wp.element.useState;
5 var registerBlockType = wp.blocks.registerBlockType;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var MediaUpload = wp.blockEditor.MediaUpload;
8 var MediaUploadCheck = wp.blockEditor.MediaUploadCheck;
9 var useBlockProps = wp.blockEditor.useBlockProps;
10 var RichText = wp.blockEditor.RichText;
11 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
12 var PanelBody = wp.components.PanelBody;
13 var ToggleControl = wp.components.ToggleControl;
14 var RangeControl = wp.components.RangeControl;
15 var SelectControl = wp.components.SelectControl;
16 var TextControl = wp.components.TextControl;
17 var Button = wp.components.Button;
18 var Fragment = wp.element.Fragment;
19
20 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
21 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
22
23 registerBlockType('blockenberg/popup', {
24 edit: function (props) {
25 var attr = props.attributes;
26 var set = props.setAttributes;
27 var previewOpen = useState(false);
28 var isOpen = previewOpen[0];
29 var setOpen = previewOpen[1];
30
31 var inspector = el(InspectorControls, {},
32 /* Trigger */
33 el(PanelBody, { title: __('Trigger Button', 'blockenberg'), initialOpen: true },
34 el(TextControl, { label: __('Button Label', 'blockenberg'), value: attr.triggerLabel, onChange: function (v) { set({ triggerLabel: v }); }, __nextHasNoMarginBottom: true }),
35 el(SelectControl, {
36 label: __('Button Style', 'blockenberg'), value: attr.triggerStyle,
37 options: [{ label: 'Filled', value: 'filled' }, { label: 'Outline', value: 'outline' }, { label: 'Ghost', value: 'ghost' }],
38 onChange: function (v) { set({ triggerStyle: v }); }, __nextHasNoMarginBottom: true
39 }),
40 el(SelectControl, {
41 label: __('Button Size', 'blockenberg'), value: attr.triggerSize,
42 options: [{ label: 'Small', value: 'sm' }, { label: 'Medium', value: 'md' }, { label: 'Large', value: 'lg' }],
43 onChange: function (v) { set({ triggerSize: v }); }, __nextHasNoMarginBottom: true
44 }),
45 el(SelectControl, {
46 label: __('Button Alignment', 'blockenberg'), value: attr.triggerAlign,
47 options: [{ label: 'Left', value: 'left' }, { label: 'Center', value: 'center' }, { label: 'Right', value: 'right' }],
48 onChange: function (v) { set({ triggerAlign: v }); }, __nextHasNoMarginBottom: true
49 })
50 ),
51 /* Trigger type */
52 el(PanelBody, { title: __('Trigger Type', 'blockenberg'), initialOpen: false },
53 el(SelectControl, {
54 label: __('When to Show', 'blockenberg'), value: attr.triggerType,
55 options: [
56 { label: 'Button Click', value: 'click' },
57 { label: 'Scroll Depth', value: 'scroll' },
58 { label: 'Time Delay', value: 'delay' },
59 { label: 'Exit Intent', value: 'exit' }
60 ],
61 onChange: function (v) { set({ triggerType: v }); }, __nextHasNoMarginBottom: true
62 }),
63 attr.triggerType === 'scroll' && el(RangeControl, {
64 label: __('Scroll Depth (%)', 'blockenberg'), value: attr.scrollDepth, min: 10, max: 100,
65 onChange: function (v) { set({ scrollDepth: v }); }, __nextHasNoMarginBottom: true
66 }),
67 attr.triggerType === 'delay' && el(RangeControl, {
68 label: __('Delay (seconds)', 'blockenberg'), value: attr.timeDelay, min: 1, max: 30,
69 onChange: function (v) { set({ timeDelay: v }); }, __nextHasNoMarginBottom: true
70 }),
71 el(SelectControl, {
72 label: __('Show Frequency', 'blockenberg'), value: attr.showOnce,
73 options: [
74 { label: 'Always', value: 'always' },
75 { label: 'Once per Session', value: 'session' },
76 { label: 'Once Ever', value: 'once' }
77 ],
78 onChange: function (v) { set({ showOnce: v }); }, __nextHasNoMarginBottom: true
79 })
80 ),
81 /* Popup layout */
82 el(PanelBody, { title: __('Popup Layout', 'blockenberg'), initialOpen: false },
83 el(SelectControl, {
84 label: __('Position', 'blockenberg'), value: attr.popupPosition,
85 options: [
86 { label: 'Center', value: 'center' },
87 { label: 'Drawer — Right', value: 'drawer-right' },
88 { label: 'Drawer — Bottom', value: 'drawer-bottom' }
89 ],
90 onChange: function (v) { set({ popupPosition: v }); }, __nextHasNoMarginBottom: true
91 }),
92 el(SelectControl, {
93 label: __('Size', 'blockenberg'), value: attr.popupSize,
94 options: [{ label: 'Small', value: 'sm' }, { label: 'Medium', value: 'md' }, { label: 'Large', value: 'lg' }, { label: 'Custom', value: 'custom' }],
95 onChange: function (v) { set({ popupSize: v }); }, __nextHasNoMarginBottom: true
96 }),
97 attr.popupSize === 'custom' && el(RangeControl, {
98 label: __('Custom Width (px)', 'blockenberg'), value: attr.popupWidth, min: 300, max: 1000,
99 onChange: function (v) { set({ popupWidth: v }); }, __nextHasNoMarginBottom: true
100 }),
101 el(SelectControl, {
102 label: __('Animation', 'blockenberg'), value: attr.popupAnimation,
103 options: [
104 { label: 'Scale', value: 'scale' },
105 { label: 'Fade', value: 'fade' },
106 { label: 'Slide Up', value: 'slide-up' },
107 { label: 'Slide Right', value: 'slide-right' }
108 ],
109 onChange: function (v) { set({ popupAnimation: v }); }, __nextHasNoMarginBottom: true
110 }),
111 el(RangeControl, {
112 label: __('Border Radius (px)', 'blockenberg'), value: attr.borderRadius, min: 0, max: 40,
113 onChange: function (v) { set({ borderRadius: v }); }, __nextHasNoMarginBottom: true
114 }),
115 el(ToggleControl, { label: __('Close on Overlay Click', 'blockenberg'), checked: attr.closeOnOverlay, onChange: function (v) { set({ closeOnOverlay: v }); }, __nextHasNoMarginBottom: true }),
116 el(ToggleControl, { label: __('Show Close Button', 'blockenberg'), checked: attr.showCloseBtn, onChange: function (v) { set({ showCloseBtn: v }); }, __nextHasNoMarginBottom: true }),
117 el(RangeControl, {
118 label: __('Overlay Opacity (%)', 'blockenberg'), value: attr.overlayOpacity, min: 10, max: 95,
119 onChange: function (v) { set({ overlayOpacity: v }); }, __nextHasNoMarginBottom: true
120 })
121 ),
122 /* Image */
123 el(PanelBody, { title: __('Image', 'blockenberg'), initialOpen: false },
124 el(SelectControl, {
125 label: __('Image Position', 'blockenberg'), value: attr.imagePosition,
126 options: [{ label: 'Top', value: 'top' }, { label: 'Left', value: 'left' }, { label: 'Right', value: 'right' }, { label: 'None', value: 'none' }],
127 onChange: function (v) { set({ imagePosition: v }); }, __nextHasNoMarginBottom: true
128 }),
129 attr.imagePosition !== 'none' && el(MediaUploadCheck, {},
130 el(MediaUpload, {
131 onSelect: function (m) { set({ imageUrl: m.url, imageId: m.id, imageAlt: m.alt || '' }); },
132 allowedTypes: ['image'], value: attr.imageId,
133 render: function (ref) {
134 return el(Fragment, {},
135 attr.imageUrl && el('img', { src: attr.imageUrl, alt: attr.imageAlt, style: { width: '100%', borderRadius: '8px', marginBottom: '8px' } }),
136 el(Button, { onClick: ref.open, variant: 'secondary', isSmall: true }, attr.imageUrl ? __('Replace Image', 'blockenberg') : __('Upload Image', 'blockenberg')),
137 attr.imageUrl && el(Button, { onClick: function () { set({ imageUrl: '', imageId: 0, imageAlt: '' }); }, variant: 'link', isDestructive: true, isSmall: true, style: { marginLeft: '8px' } }, __('Remove', 'blockenberg'))
138 );
139 }
140 })
141 )
142 ),
143 /* CTA */
144 el(PanelBody, { title: __('CTA & Dismiss', 'blockenberg'), initialOpen: false },
145 el(ToggleControl, { label: __('Show CTA Button', 'blockenberg'), checked: attr.showCta, onChange: function (v) { set({ showCta: v }); }, __nextHasNoMarginBottom: true }),
146 attr.showCta && el(TextControl, { label: __('CTA Label', 'blockenberg'), value: attr.ctaLabel, onChange: function (v) { set({ ctaLabel: v }); }, __nextHasNoMarginBottom: true }),
147 attr.showCta && el(TextControl, { label: __('CTA URL', 'blockenberg'), value: attr.ctaUrl, onChange: function (v) { set({ ctaUrl: v }); }, __nextHasNoMarginBottom: true }),
148 attr.showCta && el(ToggleControl, { label: __('Open in New Tab', 'blockenberg'), checked: attr.ctaNewTab, onChange: function (v) { set({ ctaNewTab: v }); }, __nextHasNoMarginBottom: true }),
149 attr.showCta && el(SelectControl, {
150 label: __('CTA Style', 'blockenberg'), value: attr.ctaStyle,
151 options: [{ label: 'Filled', value: 'filled' }, { label: 'Outline', value: 'outline' }],
152 onChange: function (v) { set({ ctaStyle: v }); }, __nextHasNoMarginBottom: true
153 }),
154 el(ToggleControl, { label: __('Show Dismiss Link', 'blockenberg'), checked: attr.showDismiss, onChange: function (v) { set({ showDismiss: v }); }, __nextHasNoMarginBottom: true }),
155 attr.showDismiss && el(TextControl, { label: __('Dismiss Label', 'blockenberg'), value: attr.dismissLabel, onChange: function (v) { set({ dismissLabel: v }); }, __nextHasNoMarginBottom: true })
156 ),
157 /* Spacing */
158 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
159 el(RangeControl, { label: __('Padding Top (px)', 'blockenberg'), value: attr.paddingTop, min: 0, max: 240, onChange: function (v) { set({ paddingTop: v }); }, __nextHasNoMarginBottom: true }),
160 el(RangeControl, { label: __('Padding Bottom (px)', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 240, onChange: function (v) { set({ paddingBottom: v }); }, __nextHasNoMarginBottom: true })
161 ),
162 /* Colors */
163 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
164 (function () {
165 var TC = getTypoControl();
166 if (!TC) return el('p', null, 'Loading\u2026');
167 return el(Fragment, null,
168 el(TC, { label: 'Heading Typography', value: attr.headingTypo, onChange: function (v) { set({ headingTypo: v }); } }),
169 el(TC, { label: 'Body Typography', value: attr.bodyTypo, onChange: function (v) { set({ bodyTypo: v }); } })
170 );
171 })()
172 ),
173 el(PanelColorSettings, {
174 title: __('Colors', 'blockenberg'), initialOpen: false,
175 colorSettings: [
176 { value: attr.triggerBg, onChange: function (v) { set({ triggerBg: v || '#6366f1' }); }, label: __('Trigger Button BG', 'blockenberg') },
177 { value: attr.triggerColor, onChange: function (v) { set({ triggerColor: v || '#ffffff' }); }, label: __('Trigger Button Text', 'blockenberg') },
178 { value: attr.overlayColor, onChange: function (v) { set({ overlayColor: v || '#000000' }); }, label: __('Overlay Color', 'blockenberg') },
179 { value: attr.popupBg, onChange: function (v) { set({ popupBg: v || '#ffffff' }); }, label: __('Popup Background', 'blockenberg') },
180 { value: attr.headingColor, onChange: function (v) { set({ headingColor: v || '#111827' }); }, label: __('Heading', 'blockenberg') },
181 { value: attr.textColor, onChange: function (v) { set({ textColor: v || '#4b5563' }); }, label: __('Body Text', 'blockenberg') },
182 { value: attr.btnBg, onChange: function (v) { set({ btnBg: v || '#6366f1' }); }, label: __('CTA Button BG', 'blockenberg') },
183 { value: attr.btnColor, onChange: function (v) { set({ btnColor: v || '#ffffff' }); }, label: __('CTA Button Text', 'blockenberg') },
184 { value: attr.dismissColor, onChange: function (v) { set({ dismissColor: v || '#9ca3af' }); }, label: __('Dismiss Text', 'blockenberg') }
185 ]
186 })
187 );
188
189 /* Trigger button styles */
190 var triggerPadding = attr.triggerSize === 'sm' ? '10px 20px' : attr.triggerSize === 'lg' ? '18px 40px' : '13px 28px';
191 var triggerFontSize = attr.triggerSize === 'sm' ? '14px' : attr.triggerSize === 'lg' ? '18px' : '15px';
192 var triggerStyle = {
193 padding: triggerPadding,
194 fontSize: triggerFontSize,
195 fontWeight: '700',
196 borderRadius: '8px',
197 cursor: 'pointer',
198 border: attr.triggerStyle === 'outline' ? ('2px solid ' + attr.triggerBg) : 'none',
199 background: attr.triggerStyle === 'filled' ? attr.triggerBg : attr.triggerStyle === 'ghost' ? 'transparent' : 'transparent',
200 color: attr.triggerStyle === 'filled' ? attr.triggerColor : attr.triggerBg,
201 display: 'inline-block'
202 };
203
204 /* Popup width */
205 var pwMap = { sm: '400px', md: '560px', lg: '760px', custom: attr.popupWidth + 'px' };
206 var pw = pwMap[attr.popupSize] || '560px';
207
208 /* Popup content inner */
209 var imgEl = attr.imageUrl && attr.imagePosition !== 'none'
210 ? el('img', { src: attr.imageUrl, alt: attr.imageAlt, style: { width: '100%', display: 'block', borderRadius: attr.imagePosition === 'top' ? (attr.borderRadius + 'px ' + attr.borderRadius + 'px 0 0') : '10px', objectFit: 'cover', maxHeight: attr.imagePosition === 'top' ? '200px' : '100%' } })
211 : null;
212
213 var popupContentStyle = {
214 display: 'flex',
215 flexDirection: attr.imagePosition === 'left' || attr.imagePosition === 'right' ? 'row' : 'column',
216 background: attr.popupBg,
217 borderRadius: attr.borderRadius + 'px',
218 overflow: 'hidden',
219 maxWidth: pw,
220 width: '100%',
221 boxShadow: '0 25px 80px rgba(0,0,0,.25)',
222 position: 'relative'
223 };
224
225 var bodyStyle = { padding: '32px' };
226
227 var ctaBtnStyle = {
228 display: 'inline-block',
229 padding: '12px 28px',
230 borderRadius: '8px',
231 fontWeight: '700',
232 fontSize: '15px',
233 cursor: 'pointer',
234 marginTop: '20px',
235 background: attr.ctaStyle === 'filled' ? attr.btnBg : 'transparent',
236 color: attr.ctaStyle === 'filled' ? attr.btnColor : attr.btnBg,
237 border: attr.ctaStyle === 'outline' ? ('2px solid ' + attr.btnBg) : 'none',
238 textDecoration: 'none'
239 };
240
241 var popupBody = el('div', { style: bodyStyle },
242 el(RichText, {
243 tagName: 'h3', className: 'bkbg-pop-heading', value: attr.heading, onChange: function (v) { set({ heading: v }); },
244 placeholder: __('Popup heading…', 'blockenberg'),
245 style: { color: attr.headingColor, margin: '0 0 12px' }
246 }),
247 el(RichText, {
248 tagName: 'p', className: 'bkbg-pop-text', value: attr.subtext, onChange: function (v) { set({ subtext: v }); },
249 placeholder: __('Popup body text…', 'blockenberg'),
250 style: { color: attr.textColor, margin: 0 }
251 }),
252 attr.showCta && el('span', { style: ctaBtnStyle }, attr.ctaLabel),
253 attr.showDismiss && el('p', { style: { color: attr.dismissColor, fontSize: '13px', marginTop: '12px', cursor: 'pointer', textDecoration: 'underline' } }, attr.dismissLabel)
254 );
255
256 var blockProps = useBlockProps((function () {
257 var _tv = getTypoCssVars();
258 var s = { paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px', textAlign: attr.triggerAlign };
259 if (_tv) {
260 Object.assign(s, _tv(attr.headingTypo, '--bkbg-pop-hd-'));
261 Object.assign(s, _tv(attr.bodyTypo, '--bkbg-pop-bd-'));
262 }
263 return { style: s };
264 })());
265
266 return el(Fragment, {},
267 inspector,
268 el('div', blockProps,
269 el('div', { style: { display: 'inline-block' } },
270 el('button', { type: 'button', style: triggerStyle, onClick: function () { setOpen(!isOpen); } }, attr.triggerLabel),
271 attr.triggerType !== 'click' && el('div', { style: { fontSize: '12px', color: '#6b7280', marginTop: '6px' } },
272 '⚡ Trigger: ',
273 attr.triggerType === 'scroll' ? ('after ' + attr.scrollDepth + '% scroll') :
274 attr.triggerType === 'delay' ? ('after ' + attr.timeDelay + 's') : 'exit intent'
275 )
276 ),
277 isOpen && el('div', {
278 style: { position: 'fixed', inset: 0, zIndex: 9999, display: 'flex', alignItems: attr.popupPosition === 'drawer-bottom' ? 'flex-end' : 'center', justifyContent: attr.popupPosition === 'drawer-right' ? 'flex-end' : 'center', background: (attr.overlayColor || '#000') + Math.round(attr.overlayOpacity * 255 / 100).toString(16).padStart(2, '0') },
279 onClick: function () { if (attr.closeOnOverlay) setOpen(false); }
280 },
281 el('div', { className: 'bkbg-pop-box', style: popupContentStyle, onClick: function (e) { e.stopPropagation(); } },
282 attr.showCloseBtn && el('button', {
283 type: 'button', onClick: function () { setOpen(false); },
284 style: { position: 'absolute', top: '12px', right: '16px', background: 'none', border: 'none', fontSize: '22px', color: '#9ca3af', cursor: 'pointer', lineHeight: 1, zIndex: 1 }
285 }, '×'),
286 imgEl && attr.imagePosition === 'top' && imgEl,
287 el('div', { style: { display: 'flex', flex: 1 } },
288 imgEl && attr.imagePosition === 'left' && el('div', { style: { width: '45%', flexShrink: 0 } }, imgEl),
289 popupBody,
290 imgEl && attr.imagePosition === 'right' && el('div', { style: { width: '45%', flexShrink: 0 } }, imgEl)
291 )
292 )
293 )
294 )
295 );
296 },
297
298 save: function (props) {
299 return el('div', useBlockProps.save(),
300 el('div', { className: 'bkbg-pop-app', 'data-opts': JSON.stringify(props.attributes) })
301 );
302 },
303
304 deprecated: [{
305 attributes: {
306 triggerLabel:{type:'string',default:'Open Popup'},triggerStyle:{type:'string',default:'filled'},triggerSize:{type:'string',default:'md'},triggerAlign:{type:'string',default:'center'},triggerType:{type:'string',default:'click'},scrollDepth:{type:'number',default:40},timeDelay:{type:'number',default:3},showOnce:{type:'string',default:'always'},popupPosition:{type:'string',default:'center'},popupSize:{type:'string',default:'md'},popupWidth:{type:'number',default:560},popupAnimation:{type:'string',default:'scale'},borderRadius:{type:'number',default:16},closeOnOverlay:{type:'boolean',default:true},showCloseBtn:{type:'boolean',default:true},imageUrl:{type:'string',default:''},imageId:{type:'number',default:0},imageAlt:{type:'string',default:''},imagePosition:{type:'string',default:'top'},heading:{type:'string',default:'Get 20% Off Today'},subtext:{type:'string',default:'Subscribe to our newsletter and get your exclusive discount code instantly.'},ctaLabel:{type:'string',default:'Claim Your Discount'},ctaUrl:{type:'string',default:'#'},ctaNewTab:{type:'boolean',default:false},showCta:{type:'boolean',default:true},ctaStyle:{type:'string',default:'filled'},dismissLabel:{type:'string',default:'No thanks'},showDismiss:{type:'boolean',default:true},paddingTop:{type:'number',default:0},paddingBottom:{type:'number',default:0},overlayColor:{type:'string',default:'#000000'},overlayOpacity:{type:'number',default:60},popupBg:{type:'string',default:'#ffffff'},headingColor:{type:'string',default:'#111827'},textColor:{type:'string',default:'#4b5563'},btnBg:{type:'string',default:'#6366f1'},btnColor:{type:'string',default:'#ffffff'},triggerBg:{type:'string',default:'#6366f1'},triggerColor:{type:'string',default:'#ffffff'},dismissColor:{type:'string',default:'#9ca3af'},headingFontSize:{type:'number',default:22},headingFontWeight:{type:'string',default:'800'},headingLineHeight:{type:'number',default:1.3},bodyFontSize:{type:'number',default:15},bodyLineHeight:{type:'number',default:1.6}
307 },
308 save: function (props) {
309 return wp.element.createElement('div', wp.blockEditor.useBlockProps.save(),
310 wp.element.createElement('div', { className: 'bkbg-pop-app', 'data-opts': JSON.stringify(props.attributes) })
311 );
312 }
313 }]
314 });
315 }() );
316