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

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/age-gate/index.js

201 lines 13.0 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 registerBlockType = wp.blocks.registerBlockType;
4 var useBlockProps = wp.blockEditor.useBlockProps;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
7 var RichText = wp.blockEditor.RichText;
8 var MediaUpload = wp.blockEditor.MediaUpload;
9 var PanelBody = wp.components.PanelBody;
10 var RangeControl = wp.components.RangeControl;
11 var ToggleControl = wp.components.ToggleControl;
12 var SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14 var Button = wp.components.Button;
15 var Fragment = wp.element.Fragment;
16
17 // Lazy lookup so the typography control is resolved at render time
18 function getTypographyControl() {
19 return (typeof window.bkbgTypographyControl !== 'undefined') ? window.bkbgTypographyControl : null;
20 }
21 function getTypoCssVars() {
22 return (typeof window.bkbgTypoCssVars !== 'undefined') ? window.bkbgTypoCssVars : function() { return {}; };
23 }
24
25 registerBlockType('blockenberg/age-gate', {
26 edit: function (props) {
27 var a = props.attributes;
28 var set = props.setAttributes;
29 var blockProps = useBlockProps({ className: 'bkbg-ag-editor-wrap bkbg-ag-wrap', style: (function () {
30 var s = {};
31 var _tv = getTypoCssVars();
32 Object.assign(s, _tv(a.titleTypo || {}, '--bkbg-ag-title-'));
33 Object.assign(s, _tv(a.messageTypo || {}, '--bkbg-ag-message-'));
34 s['--bkbg-ag-title-sz'] = (a.titleSize || 26) + 'px';
35 s['--bkbg-ag-message-sz'] = (a.messageSize || 15) + 'px';
36 return s;
37 })() });
38
39 // Editor preview
40 var previewCard = el('div', { className: 'bkbg-ag-preview',
41 style: { background: a.overlayBg || 'rgba(0,0,0,0.75)', borderRadius: 10,
42 padding: '40px 20px', textAlign: 'center', position: 'relative' }
43 },
44 el('div', { className: 'bkbg-ag-card',
45 style: {
46 background: a.cardBg || '#ffffff',
47 borderRadius: (a.cardRadius || 16) + 'px',
48 padding: (a.cardPadding || 48) + 'px',
49 maxWidth: (a.cardMaxWidth || 480) + 'px',
50 margin: '0 auto',
51 boxShadow: '0 20px 60px rgba(0,0,0,0.25)'
52 }
53 },
54 a.logoUrl && el('div', { style: { marginBottom: 16 } },
55 el('img', { src: a.logoUrl, style: { maxHeight: (a.logoSize || 80) + 'px', margin: '0 auto', display: 'block' } })
56 ),
57 el(RichText, {
58 tagName: 'h3', value: a.title, placeholder: 'Age Verification Required',
59 className: 'bkbg-ag-title',
60 style: { margin: '0 0 16px',
61 color: a.titleColor || '#1e1b4b' },
62 onChange: function (v) { set({ title: v }); }
63 }),
64 el(RichText, {
65 tagName: 'p', value: a.message, placeholder: 'Enter your age verification message...',
66 className: 'bkbg-ag-message',
67 style: { margin: '0 0 28px',
68 color: a.messageColor || '#64748b' },
69 onChange: function (v) { set({ message: v }); }
70 }),
71 // Verification mode preview
72 a.verificationMode === 'dob'
73 ? el('div', { style: { marginBottom: 20 } },
74 el('label', { style: { fontSize: 13, color: a.messageColor || '#64748b', display: 'block', marginBottom: 6 } }, 'Date of Birth'),
75 el('input', { type: 'date', disabled: true,
76 style: { border: '1.5px solid #e5e7eb', borderRadius: 8, padding: '8px 14px',
77 fontSize: 15, width: '100%', color: a.titleColor || '#1e1b4b' } })
78 )
79 : null,
80 el('div', { className: 'bkbg-ag-btns', style: { display: 'flex', gap: 12, flexDirection: 'column' } },
81 el('div', { style: { background: a.confirmBg || '#6366f1', color: a.confirmColor || '#ffffff',
82 borderRadius: 10, padding: '12px 24px', fontWeight: 700, fontSize: 15, textAlign: 'center' }
83 }, a.confirmText || 'Yes, I am old enough'),
84 el('div', { style: { background: a.denyBg || '#f1f5f9', color: a.denyColor || '#64748b',
85 borderRadius: 10, padding: '10px 24px', fontSize: 14, textAlign: 'center' }
86 }, a.denyText || 'No, take me back')
87 ),
88 a.disclaimer && el('p', { style: { marginTop: 20, fontSize: 11, color: a.messageColor || '#64748b',
89 opacity: 0.65, lineHeight: 1.5 } }, a.disclaimer),
90 el('p', { style: { marginTop: 12, fontSize: 11, opacity: 0.4, color: a.titleColor || '#1e1b4b' } },
91 'ℹ️ This overlay will appear on the frontend. Remembered for ' + (a.rememberDays || 30) + ' days.')
92 )
93 );
94
95 return el('div', blockProps,
96 el(InspectorControls, {},
97 el(PanelBody, { title: 'Content', initialOpen: true },
98 el(TextControl, { label: 'Confirm button text', value: a.confirmText || '',
99 onChange: function (v) { set({ confirmText: v }); }, __nextHasNoMarginBottom: true }),
100 el(TextControl, { label: 'Deny button text', value: a.denyText || '',
101 onChange: function (v) { set({ denyText: v }); }, __nextHasNoMarginBottom: true }),
102 el(TextControl, { label: 'Deny redirect URL (optional)', value: a.denyRedirectUrl || '',
103 onChange: function (v) { set({ denyRedirectUrl: v }); }, __nextHasNoMarginBottom: true }),
104 el(TextControl, { label: 'Disclaimer text', value: a.disclaimer || '',
105 onChange: function (v) { set({ disclaimer: v }); }, __nextHasNoMarginBottom: true })
106 ),
107 el(PanelBody, { title: 'Gate Settings', initialOpen: false },
108 el(SelectControl, { label: 'Verification mode', value: a.verificationMode || 'yesno',
109 options: [
110 { label: 'Yes / No buttons', value: 'yesno' },
111 { label: 'Date of birth input', value: 'dob' }
112 ],
113 onChange: function (v) { set({ verificationMode: v }); }, __nextHasNoMarginBottom: true }),
114 el(RangeControl, { label: 'Minimum age', value: a.minimumAge || 18,
115 onChange: function (v) { set({ minimumAge: v }); }, min: 13, max: 21, __nextHasNoMarginBottom: true }),
116 el(RangeControl, { label: 'Remember choice for (days)', value: a.rememberDays || 30,
117 onChange: function (v) { set({ rememberDays: v }); }, min: 0, max: 365, __nextHasNoMarginBottom: true }),
118 el(TextControl, { label: 'Logo URL (optional)', value: a.logoUrl || '',
119 onChange: function (v) { set({ logoUrl: v }); }, __nextHasNoMarginBottom: true }),
120 el(RangeControl, { label: 'Logo max height (px)', value: a.logoSize || 80,
121 onChange: function (v) { set({ logoSize: v }); }, min: 30, max: 200, __nextHasNoMarginBottom: true })
122 ),
123 el(PanelBody, { title: 'Card Style', initialOpen: false },
124 el(RangeControl, { label: 'Card max-width (px)', value: a.cardMaxWidth || 480,
125 onChange: function (v) { set({ cardMaxWidth: v }); }, min: 300, max: 800, __nextHasNoMarginBottom: true }),
126 el(RangeControl, { label: 'Card padding', value: a.cardPadding || 48,
127 onChange: function (v) { set({ cardPadding: v }); }, min: 16, max: 80, __nextHasNoMarginBottom: true }),
128 el(RangeControl, { label: 'Card border radius', value: a.cardRadius || 16,
129 onChange: function (v) { set({ cardRadius: v }); }, min: 0, max: 40, __nextHasNoMarginBottom: true }),
130 ),
131
132 el( PanelBody, { title: 'Typography', initialOpen: false },
133 (function () {
134 var TC = getTypographyControl();
135 if (!TC) return el('p', null, 'Typography control not loaded.');
136 return el(Fragment, null,
137 el(TC, { label: 'Title Typography', value: a.titleTypo || {}, onChange: function (v) { set({ titleTypo: v }); } }),
138 el(TC, { label: 'Message Typography', value: a.messageTypo || {}, onChange: function (v) { set({ messageTypo: v }); } })
139 );
140 })()
141 ),
142 el(PanelColorSettings, {
143 title: 'Colors', initialOpen: false,
144 colorSettings: [
145 { label: 'Overlay background', value: a.overlayBg, onChange: function (v) { set({ overlayBg: v || 'rgba(0,0,0,0.75)' }); } },
146 { label: 'Card background', value: a.cardBg, onChange: function (v) { set({ cardBg: v || '#ffffff' }); } },
147 { label: 'Title color', value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#1e1b4b' }); } },
148 { label: 'Message color', value: a.messageColor, onChange: function (v) { set({ messageColor: v || '#64748b' }); } },
149 { label: 'Confirm button bg', value: a.confirmBg, onChange: function (v) { set({ confirmBg: v || '#6366f1' }); } },
150 { label: 'Confirm text color', value: a.confirmColor, onChange: function (v) { set({ confirmColor: v || '#ffffff' }); } },
151 { label: 'Deny button bg', value: a.denyBg, onChange: function (v) { set({ denyBg: v || '#f1f5f9' }); } },
152 { label: 'Deny text color', value: a.denyColor, onChange: function (v) { set({ denyColor: v || '#64748b' }); } }
153 ],
154 enableAlpha: true,
155 disableCustomGradients: true
156 })
157 ),
158 previewCard
159 );
160 },
161
162 save: function (props) {
163 var a = props.attributes;
164 var blockProps = useBlockProps.save();
165 var opts = {
166 minimumAge: a.minimumAge || 18,
167 verificationMode: a.verificationMode || 'yesno',
168 logoUrl: a.logoUrl || '',
169 confirmText: a.confirmText || 'Yes, I am old enough',
170 denyText: a.denyText || 'No, take me back',
171 denyRedirectUrl: a.denyRedirectUrl || '',
172 rememberDays: a.rememberDays >= 0 ? a.rememberDays : 30,
173 disclaimer: a.disclaimer || '',
174 cardRadius: a.cardRadius || 16,
175 cardPadding: a.cardPadding || 48,
176 cardMaxWidth: a.cardMaxWidth || 480,
177 logoSize: a.logoSize || 80,
178 titleSize: a.titleSize || 26,
179 messageSize: a.messageSize || 15,
180 overlayBg: a.overlayBg || 'rgba(0,0,0,0.75)',
181 cardBg: a.cardBg || '#ffffff',
182 titleColor: a.titleColor || '#1e1b4b',
183 messageColor: a.messageColor || '#64748b',
184 confirmBg: a.confirmBg || '#6366f1',
185 confirmColor: a.confirmColor || '#ffffff',
186 denyBg: a.denyBg || '#f1f5f9',
187 denyColor: a.denyColor || '#64748b',
188 titleTypo: a.titleTypo || {},
189 messageTypo: a.messageTypo || {}
190 };
191
192 return el('div', blockProps,
193 el('div', { className: 'bkbg-ag-app', 'data-opts': JSON.stringify(opts) },
194 el(RichText.Content, { tagName: 'div', className: 'bkbg-ag-title-src', value: a.title }),
195 el(RichText.Content, { tagName: 'div', className: 'bkbg-ag-message-src', value: a.message })
196 )
197 );
198 }
199 });
200 }() );
201