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

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

311 lines 18.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 var el = window.wp.element.createElement;
3 var Fragment = window.wp.element.Fragment;
4 var __ = function (s) { return s; };
5 var registerBlockType = window.wp.blocks.registerBlockType;
6 var InspectorControls = window.wp.blockEditor.InspectorControls;
7 var PanelBody = window.wp.components.PanelBody;
8 var ToggleControl = window.wp.components.ToggleControl;
9 var SelectControl = window.wp.components.SelectControl;
10 var RangeControl = window.wp.components.RangeControl;
11 var TextControl = window.wp.components.TextControl;
12 var PanelColorSettings = window.wp.blockEditor.PanelColorSettings;
13
14 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
15 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
16
17 registerBlockType('blockenberg/post-carousel', {
18 title: __('Post Carousel'),
19 description: __('A responsive carousel of posts with autoplay, arrows, and dots.'),
20 category: 'bkbg-blog',
21 icon: el('svg', { viewBox: '0 0 24 24', fill: 'currentColor', width: 24, height: 24 },
22 el('path', { d: 'M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V6h16v12zM8 11l2.5 3.16 3.5-4.47L18 16H6z' }),
23 el('path', { d: 'M1 12l3-3v6l-3-3zm19-3l3 3-3 3V9z' })
24 ),
25
26 edit: function (props) {
27 var a = props.attributes;
28 var setA = props.setAttributes;
29
30 var inspector = el(InspectorControls, null,
31 el(PanelBody, { title: __('Query'), initialOpen: true },
32 el(SelectControl, {
33 label: __('Post Type'), value: a.postType,
34 options: [
35 { label: 'Posts', value: 'post' },
36 { label: 'Pages', value: 'page' },
37 ],
38 onChange: function (v) { setA({ postType: v }); },
39 }),
40 el(SelectControl, {
41 label: __('Order By'), value: a.orderby,
42 options: [
43 { label: 'Date', value: 'date' },
44 { label: 'Title', value: 'title' },
45 { label: 'Modified', value: 'modified' },
46 { label: 'Random', value: 'rand' },
47 { label: 'Menu Order', value: 'menu_order' },
48 ],
49 onChange: function (v) { setA({ orderby: v }); },
50 }),
51 el(SelectControl, {
52 label: __('Order'), value: a.order,
53 options: [
54 { label: 'Newest first', value: 'desc' },
55 { label: 'Oldest first', value: 'asc' },
56 ],
57 onChange: function (v) { setA({ order: v }); },
58 }),
59 el(RangeControl, {
60 label: __('Number of Posts'), value: a.perPage, min: 2, max: 20,
61 onChange: function (v) { setA({ perPage: v }); },
62 }),
63 el(RangeControl, {
64 label: __('Excerpt Length (words)'), value: a.excerptLen, min: 5, max: 60,
65 onChange: function (v) { setA({ excerptLen: v }); },
66 })
67 ),
68 el(PanelBody, { title: __('Carousel'), initialOpen: true },
69 el(RangeControl, {
70 label: __('Slides (Desktop)'), value: a.slidesPerView, min: 1, max: 5,
71 onChange: function (v) { setA({ slidesPerView: v }); },
72 }),
73 el(RangeControl, {
74 label: __('Slides (Tablet)'), value: a.slidesPerViewTablet, min: 1, max: 4,
75 onChange: function (v) { setA({ slidesPerViewTablet: v }); },
76 }),
77 el(RangeControl, {
78 label: __('Slides (Mobile)'), value: a.slidesPerViewMobile, min: 1, max: 2,
79 onChange: function (v) { setA({ slidesPerViewMobile: v }); },
80 }),
81 el(RangeControl, {
82 label: __('Gap (px)'), value: a.gap, min: 0, max: 60,
83 onChange: function (v) { setA({ gap: v }); },
84 }),
85 el(ToggleControl, {
86 label: __('Autoplay'), checked: a.autoplay,
87 onChange: function (v) { setA({ autoplay: v }); },
88 __nextHasNoMarginBottom: true,
89 }),
90 a.autoplay && el(RangeControl, {
91 label: __('Autoplay Speed (ms)'), value: a.autoplaySpeed, min: 1000, max: 10000, step: 500,
92 onChange: function (v) { setA({ autoplaySpeed: v }); },
93 }),
94 a.autoplay && el(ToggleControl, {
95 label: __('Pause on Hover'), checked: a.pauseOnHover,
96 onChange: function (v) { setA({ pauseOnHover: v }); },
97 __nextHasNoMarginBottom: true,
98 }),
99 el(ToggleControl, {
100 label: __('Loop'), checked: a.loop,
101 onChange: function (v) { setA({ loop: v }); },
102 __nextHasNoMarginBottom: true,
103 }),
104 el(ToggleControl, {
105 label: __('Show Arrows'), checked: a.showArrows,
106 onChange: function (v) { setA({ showArrows: v }); },
107 __nextHasNoMarginBottom: true,
108 }),
109 a.showArrows && el(SelectControl, {
110 label: __('Arrow Style'), value: a.arrowStyle,
111 options: [
112 { label: 'Circle', value: 'circle' },
113 { label: 'Square', value: 'square' },
114 { label: 'Minimal', value: 'minimal' },
115 ],
116 onChange: function (v) { setA({ arrowStyle: v }); },
117 }),
118 el(ToggleControl, {
119 label: __('Show Dots'), checked: a.showDots,
120 onChange: function (v) { setA({ showDots: v }); },
121 __nextHasNoMarginBottom: true,
122 })
123 ),
124 el(PanelBody, { title: __('Card'), initialOpen: false },
125 el(SelectControl, {
126 label: __('Card Style'), value: a.cardStyle,
127 options: [
128 { label: 'Shadow', value: 'shadow' },
129 { label: 'Outlined', value: 'outlined' },
130 { label: 'Flat', value: 'flat' },
131 ],
132 onChange: function (v) { setA({ cardStyle: v }); },
133 }),
134 el(RangeControl, {
135 label: __('Card Radius'), value: a.cardRadius, min: 0, max: 30,
136 onChange: function (v) { setA({ cardRadius: v }); },
137 }),
138 el(SelectControl, {
139 label: __('Image Ratio'), value: a.imageRatio,
140 options: [
141 { label: '16:9', value: '56.25' },
142 { label: '4:3', value: '75' },
143 { label: '1:1', value: '100' },
144 ],
145 onChange: function (v) { setA({ imageRatio: v }); },
146 }),
147 el(ToggleControl, {
148 label: __('Show Image'), checked: a.showImage,
149 onChange: function (v) { setA({ showImage: v }); },
150 __nextHasNoMarginBottom: true,
151 }),
152 el(ToggleControl, {
153 label: __('Show Meta'), checked: a.showMeta,
154 onChange: function (v) { setA({ showMeta: v }); },
155 __nextHasNoMarginBottom: true,
156 }),
157 el(ToggleControl, {
158 label: __('Show Excerpt'), checked: a.showExcerpt,
159 onChange: function (v) { setA({ showExcerpt: v }); },
160 __nextHasNoMarginBottom: true,
161 }),
162 el(ToggleControl, {
163 label: __('Show Read More'), checked: a.showReadMore,
164 onChange: function (v) { setA({ showReadMore: v }); },
165 __nextHasNoMarginBottom: true,
166 }),
167 a.showReadMore && el(TextControl, {
168 label: __('Read More Label'),
169 value: a.readMoreLabel,
170 onChange: function (v) { setA({ readMoreLabel: v }); },
171 })
172 ),
173 el(PanelBody, { title: __('Typography'), initialOpen: false },
174 (function () {
175 var TC = getTypoControl();
176 if (!TC) return el('p', null, 'Loading…');
177 return el(Fragment, null,
178 el(TC, { label: 'Title Typography', value: a.titleTypo, onChange: function (v) { setA({ titleTypo: v }); } }),
179 el(TC, { label: 'Excerpt Typography', value: a.excerptTypo, onChange: function (v) { setA({ excerptTypo: v }); } }),
180 el(TC, { label: 'Meta Typography', value: a.metaTypo, onChange: function (v) { setA({ metaTypo: v }); } })
181 );
182 })()
183 ),
184 el(PanelBody, { title: __('Colors'), initialOpen: false },
185 el(PanelColorSettings, {
186 title: __('Card Colors'), initialOpen: false,
187 colorSettings: [
188 { label: __('Card BG'), value: a.cardBg, onChange: function (v) { setA({ cardBg: v || '#ffffff' }); } },
189 { label: __('Title'), value: a.titleColor, onChange: function (v) { setA({ titleColor: v || '#111827' }); } },
190 { label: __('Excerpt'), value: a.excerptColor, onChange: function (v) { setA({ excerptColor: v || '#6b7280' }); } },
191 { label: __('Meta'), value: a.metaColor, onChange: function (v) { setA({ metaColor: v || '#9ca3af' }); } },
192 { label: __('Link / Button'),value: a.linkColor, onChange: function (v) { setA({ linkColor: v || '#2563eb' }); } },
193 ],
194 }),
195 el(PanelColorSettings, {
196 title: __('Navigation Colors'), initialOpen: false,
197 colorSettings: [
198 { label: __('Arrow BG'), value: a.arrowBg, onChange: function (v) { setA({ arrowBg: v || '#ffffff' }); } },
199 { label: __('Arrow Color'), value: a.arrowColor, onChange: function (v) { setA({ arrowColor: v || '#111827' }); } },
200 { label: __('Dot'), value: a.dotColor, onChange: function (v) { setA({ dotColor: v || '#d1d5db' }); } },
201 { label: __('Dot Active'), value: a.dotActiveColor, onChange: function (v) { setA({ dotActiveColor: v || '#111827' }); } },
202 ],
203 })
204 )
205 );
206
207 /* ── Simple editor preview ── */
208 var demoCards = [1, 2, 3].slice(0, a.slidesPerView);
209 var trackStyle = {
210 display: 'flex',
211 gap: a.gap + 'px',
212 overflow:'hidden',
213 };
214 var cardW = 'calc(' + (100 / a.slidesPerView) + '% - ' + (a.gap * (a.slidesPerView - 1) / a.slidesPerView) + 'px)';
215
216 var _tvFn = getTypoCssVars();
217 var editorStyle = {};
218 Object.assign(editorStyle, _tvFn(a.titleTypo, '--bkbg-poc-tt-'));
219 Object.assign(editorStyle, _tvFn(a.excerptTypo, '--bkbg-poc-ex-'));
220 Object.assign(editorStyle, _tvFn(a.metaTypo, '--bkbg-poc-mt-'));
221
222 return el('div', { className: 'bkbg-poc-editor', style: editorStyle },
223 inspector,
224 el('div', { style: { background: '#f9fafb', border: '1px solid #e5e7eb', borderRadius: 10, padding: 16 } },
225 el('p', { style: { margin: '0 0 12px', fontSize: 12, color: '#6b7280', fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.05em' } },
226 'Post Carousel — ' + a.perPage + ' posts · ' + a.slidesPerView + ' per row'
227 ),
228 el('div', { style: trackStyle },
229 demoCards.map(function (n) {
230 return el('div', {
231 key: n,
232 style: {
233 width: cardW,
234 flexShrink: 0,
235 background: a.cardBg,
236 borderRadius: a.cardRadius + 'px',
237 overflow: 'hidden',
238 boxShadow: a.cardStyle === 'shadow' ? '0 4px 12px rgba(0,0,0,0.1)' : 'none',
239 border: a.cardStyle === 'outlined' ? '1px solid #e5e7eb' : 'none',
240 }
241 },
242 a.showImage && el('div', { style: { paddingBottom: a.imageRatio + '%', background: '#e5e7eb', position: 'relative' } },
243 el('div', { style: { position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#9ca3af', fontSize: 12 } }, 'Image ' + n)
244 ),
245 el('div', { style: { padding: '14px' } },
246 a.showMeta && el('div', { className: 'bkbg-poc-meta', style: { color: a.metaColor, marginBottom: 6 } }, 'Jan ' + (n * 5) + ', 2025'),
247 el('div', { className: 'bkbg-poc-title', style: { color: a.titleColor, marginBottom: 6 } }, 'Post Title ' + n),
248 a.showExcerpt && el('div', { className: 'bkbg-poc-excerpt', style: { color: a.excerptColor } }, 'Post excerpt preview text here…'),
249 a.showReadMore && el('span', { className: 'bkbg-poc-rm', style: { color: a.linkColor, marginTop: 10, display: 'block' } }, a.readMoreLabel + '')
250 )
251 );
252 })
253 ),
254 a.showArrows && el('div', { style: { display: 'flex', justifyContent: 'space-between', marginTop: 12 } },
255 el('span', { style: { background: a.arrowBg, color: a.arrowColor, borderRadius: a.arrowStyle === 'circle' ? '50%' : 4, width: 36, height: 36, display: 'flex', alignItems: 'center', justifyContent: 'center', boxShadow: '0 2px 6px rgba(0,0,0,0.1)', fontSize: 16 } }, ''),
256 el('span', { style: { background: a.arrowBg, color: a.arrowColor, borderRadius: a.arrowStyle === 'circle' ? '50%' : 4, width: 36, height: 36, display: 'flex', alignItems: 'center', justifyContent: 'center', boxShadow: '0 2px 6px rgba(0,0,0,0.1)', fontSize: 16 } }, '')
257 ),
258 a.showDots && el('div', { style: { display: 'flex', gap: 6, justifyContent: 'center', marginTop: 12 } },
259 [0,1,2].map(function (i) {
260 return el('span', { key: i, style: { width: 8, height: 8, borderRadius: '50%', background: i === 0 ? a.dotActiveColor : a.dotColor } });
261 })
262 )
263 )
264 );
265 },
266
267 save: function (props) {
268 var a = props.attributes;
269 return el('div', {
270 className: 'bkbg-poc-wrap',
271 'data-post-type': a.postType,
272 'data-orderby': a.orderby,
273 'data-order': a.order,
274 'data-per-page': a.perPage,
275 'data-excerpt-len': a.excerptLen,
276 'data-spv': a.slidesPerView,
277 'data-spv-tablet': a.slidesPerViewTablet,
278 'data-spv-mobile': a.slidesPerViewMobile,
279 'data-gap': a.gap,
280 'data-autoplay': a.autoplay ? '1' : '0',
281 'data-ap-speed': a.autoplaySpeed,
282 'data-pause-hover': a.pauseOnHover ? '1' : '0',
283 'data-loop': a.loop ? '1' : '0',
284 'data-arrows': a.showArrows ? '1' : '0',
285 'data-arrow-style': a.arrowStyle,
286 'data-dots': a.showDots ? '1' : '0',
287 'data-show-image': a.showImage ? '1' : '0',
288 'data-show-meta': a.showMeta ? '1' : '0',
289 'data-show-excerpt':a.showExcerpt ? '1' : '0',
290 'data-show-rm': a.showReadMore ? '1' : '0',
291 'data-rm-label': a.readMoreLabel,
292 'data-ratio': a.imageRatio,
293 'data-card-style': a.cardStyle,
294 'data-card-bg': a.cardBg,
295 'data-card-radius': a.cardRadius,
296 'data-title-c': a.titleColor,
297 'data-excerpt-c': a.excerptColor,
298 'data-meta-c': a.metaColor,
299 'data-link-c': a.linkColor,
300 'data-arrow-bg': a.arrowBg,
301 'data-arrow-c': a.arrowColor,
302 'data-dot-c': a.dotColor,
303 'data-dot-active': a.dotActiveColor,
304 'data-title-typo': JSON.stringify(a.titleTypo || {}),
305 'data-excerpt-typo': JSON.stringify(a.excerptTypo || {}),
306 'data-meta-typo': JSON.stringify(a.metaTypo || {}),
307 });
308 },
309 });
310 })();
311