PluginProbe ʕ •ᴥ•ʔ
FrontBlocks for Gutenberg/GeneratePress / ci-artifacts
FrontBlocks for Gutenberg/GeneratePress vci-artifacts
trunk 0.2.0 0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 ci-artifacts
frontblocks / includes / Frontend / Carousel.php
frontblocks / includes / Frontend Last commit date
Animations.php 1 month ago BackButton.php 7 months ago BeforeAfter.php 1 month ago BlockPatterns.php 4 months ago Carousel.php 1 month ago ContainerEdgeAlignment.php 1 month ago Counter.php 1 month ago Events.php 6 months ago FaqSchema.php 1 month ago FluidTypography.php 4 months ago Gallery.php 8 months ago GravityFormsInline.php 1 month ago Headline.php 1 month ago InsertPost.php 1 month ago ProductCategories.php 8 months ago ReadingProgress.php 7 months ago ReadingTime.php 8 months ago ShapeAnimations.php 1 month ago StackedImages.php 4 months ago StickyColumn.php 1 month ago Testimonials.php 8 months ago TextAnimation.php 1 month ago
Carousel.php
604 lines
1 <?php
2 /**
3 * Carousel module for FrontBlocks.
4 *
5 * @package FrontBlocks
6 * @author David Perez <david@close.technology>
7 * @copyright 2023 Closemarketing
8 * @version 1.0
9 */
10
11 namespace FrontBlocks\Frontend;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Carousel class.
17 *
18 * @since 1.0.0
19 */
20 class Carousel {
21
22 /**
23 * Constructor.
24 */
25 public function __construct() {
26 $this->init_hooks();
27 }
28
29 /**
30 * Initialize hooks.
31 *
32 * @return void
33 */
34 private function init_hooks() {
35 add_action( 'init', array( $this, 'register_frontend_assets' ) );
36 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
37 add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_canvas_assets' ) );
38 add_filter( 'render_block_generateblocks/grid', array( $this, 'add_custom_attributes_to_grid_block' ), 10, 2 );
39 add_filter( 'render_block_generateblocks/element', array( $this, 'add_custom_attributes_to_element_block' ), 10, 2 );
40 add_filter( 'render_block_core/group', array( $this, 'add_custom_attributes_to_core_group_block' ), 10, 2 );
41 add_filter( 'render_block_core/query', array( $this, 'add_custom_attributes_to_query_block' ), 10, 2 );
42 add_action( 'init', array( $this, 'register_custom_attributes' ), 5 );
43 }
44
45 /**
46 * Register frontend carousel assets for conditional enqueueing.
47 *
48 * @return void
49 */
50 public function register_frontend_assets() {
51 // Assets are registered in Plugin_Main::register_scripts().
52 // This method exists as a hook point for any additional registration needs.
53 }
54
55 /**
56 * Enqueue carousel frontend assets when a carousel block is detected.
57 *
58 * @return void
59 */
60 private function enqueue_carousel_assets() {
61 if ( ! wp_style_is( 'frontblocks-carousel', 'enqueued' ) ) {
62 wp_enqueue_style( 'frontblocks-carousel' );
63 }
64 if ( ! wp_script_is( 'frontblocks-carousel-custom', 'enqueued' ) ) {
65 wp_enqueue_script( 'frontblocks-carousel-custom' );
66 }
67 }
68
69 /**
70 * Enqueue carousel CSS in the editor canvas (iframe).
71 *
72 * @return void
73 */
74 public function enqueue_block_canvas_assets() {
75 if ( ! is_admin() ) {
76 return;
77 }
78 wp_enqueue_style(
79 'frontblocks-carousel-editor',
80 FRBL_PLUGIN_URL . 'assets/carousel/frontblocks-carousel-editor.css',
81 array(),
82 FRBL_VERSION
83 );
84 }
85
86 /**
87 * Enqueue block editor assets.
88 *
89 * @return void
90 */
91 public function enqueue_block_editor_assets() {
92 wp_enqueue_script(
93 'frontblocks-advanced-option',
94 FRBL_PLUGIN_URL . 'assets/carousel/frontblocks-advanced-option.js',
95 array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-data', 'wp-edit-post' ),
96 FRBL_VERSION,
97 true
98 );
99
100 // Set script translations for JavaScript.
101 wp_set_script_translations(
102 'frontblocks-advanced-option',
103 'frontblocks'
104 );
105 }
106
107 /**
108 * Add custom attributes to grid block.
109 *
110 * @param string $block_content Block content.
111 * @param array $block Block attributes.
112 * @return string
113 */
114 public function add_custom_attributes_to_grid_block( $block_content, $block ) {
115 $attrs = $block['attrs'] ?? array();
116 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
117 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
118 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
119 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
120 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
121 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
122 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
123 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
124 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
125 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
126 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
127 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
128 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
129
130 // Add data attributes to the wrapper div if carousel is enabled.
131 if ( 'carousel' === $custom_option || 'slider' === $custom_option ) {
132 $attributes = '';
133 if ( 'slider' === $custom_option ) {
134 $attributes .= ' data-rewind="' . esc_attr( $rewind ) . '"';
135 }
136
137 // Add data attributes and the 'frontblocks-carousel' class to the first div in the block content.
138 $block_content = preg_replace(
139 '/<div([^>]*)class="([^"]*gb-grid-wrapper[^"]*)"([^>]*)>/',
140 '<div$1class="$2 frontblocks-carousel"$3' .
141 ' data-type="' . esc_attr( $custom_option ) . '"' .
142 ' data-view="' . esc_attr( $items_to_view ) . '"' .
143 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
144 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
145 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
146 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
147 ' data-gap="' . esc_attr( $gap ) . '"' .
148 ' data-buttons="' . esc_attr( $buttons ) . '"' .
149 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
150 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
151 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
152 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
153 $attributes .
154 '>',
155 $block_content,
156 1 // Only replace the first occurrence.
157 );
158
159 $this->enqueue_carousel_assets();
160 }
161
162 return $block_content;
163 }
164
165 /**
166 * Add custom attributes to element block.
167 *
168 * @param string $block_content Block content.
169 * @param array $block Block attributes.
170 * @return string
171 */
172 public function add_custom_attributes_to_element_block( $block_content, $block ) {
173 $attrs = $block['attrs'] ?? array();
174
175 // Check if this element has grid display.
176 $styles = $attrs['styles'] ?? array();
177 $display = $styles['display'] ?? '';
178
179 // Only process if it's a grid element.
180 if ( 'grid' !== $display ) {
181 return $block_content;
182 }
183
184 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
185 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
186 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
187 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
188 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
189 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
190 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
191 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
192 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
193 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
194 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
195 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
196 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
197
198 // Add data attributes to the wrapper div if carousel is enabled.
199 if ( 'carousel' === $custom_option || 'slider' === $custom_option ) {
200 $attributes = '';
201 if ( 'slider' === $custom_option ) {
202 $attributes .= ' data-rewind="' . esc_attr( $rewind ) . '"';
203 }
204
205 // Add data attributes and the 'frontblocks-carousel' class to the first div in the block content.
206 $block_content = preg_replace(
207 '/<div([^>]*)class="([^"]*gb-element-[^"]*)"([^>]*)>/',
208 '<div$1class="$2 frontblocks-carousel"$3' .
209 ' data-type="' . esc_attr( $custom_option ) . '"' .
210 ' data-view="' . esc_attr( $items_to_view ) . '"' .
211 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
212 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
213 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
214 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
215 ' data-gap="' . esc_attr( $gap ) . '"' .
216 ' data-buttons="' . esc_attr( $buttons ) . '"' .
217 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
218 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
219 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
220 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
221 $attributes .
222 '>',
223 $block_content,
224 1 // Only replace the first occurrence.
225 );
226
227 $this->enqueue_carousel_assets();
228 }
229
230 return $block_content;
231 }
232
233 /**
234 * Add custom attributes to core/group block.
235 *
236 * @param string $block_content Block content.
237 * @param array $block Block attributes.
238 * @return string
239 */
240 public function add_custom_attributes_to_core_group_block( $block_content, $block ) {
241 $attrs = $block['attrs'] ?? array();
242
243 // Check if this group has grid layout.
244 $layout = $attrs['layout'] ?? array();
245 $layout_type = $layout['type'] ?? '';
246
247 // Only process if it's a grid layout.
248 if ( 'grid' !== $layout_type ) {
249 return $block_content;
250 }
251
252 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
253 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
254 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
255 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
256 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
257 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
258 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
259 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
260 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
261 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
262 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
263 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
264 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
265
266 // Add data attributes to the wrapper div if carousel is enabled.
267 if ( 'carousel' === $custom_option || 'slider' === $custom_option ) {
268 $attributes = '';
269 if ( 'slider' === $custom_option ) {
270 $attributes .= ' data-rewind="' . esc_attr( $rewind ) . '"';
271 }
272
273 // Add data attributes and the 'frontblocks-carousel' class to the first div in the block content.
274 $block_content = preg_replace(
275 '/<div([^>]*)class="([^"]*wp-block-group[^"]*)"([^>]*)>/',
276 '<div$1class="$2 frontblocks-carousel"$3' .
277 ' data-type="' . esc_attr( $custom_option ) . '"' .
278 ' data-view="' . esc_attr( $items_to_view ) . '"' .
279 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
280 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
281 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
282 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
283 ' data-gap="' . esc_attr( $gap ) . '"' .
284 ' data-buttons="' . esc_attr( $buttons ) . '"' .
285 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
286 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
287 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
288 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
289 $attributes .
290 '>',
291 $block_content,
292 1 // Only replace the first occurrence.
293 );
294
295 $this->enqueue_carousel_assets();
296 }
297
298 return $block_content;
299 }
300
301 /**
302 * Add custom attributes to core/query block.
303 *
304 * @param string $block_content Block content.
305 * @param array $block Block attributes.
306 * @return string
307 */
308 public function add_custom_attributes_to_query_block( $block_content, $block ) {
309 $attrs = $block['attrs'] ?? array();
310 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
311
312 if ( 'carousel' !== $custom_option && 'slider' !== $custom_option ) {
313 return $block_content;
314 }
315
316 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
317 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
318 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
319 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
320 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
321 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
322 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
323 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
324 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
325 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
326 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
327 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
328
329 $extra = '';
330 if ( 'slider' === $custom_option ) {
331 $extra .= ' data-rewind="' . esc_attr( $rewind ) . '"';
332 }
333
334 $block_content = preg_replace(
335 '/<ul([^>]*)class="([^"]*wp-block-post-template[^"]*)"([^>]*)>/',
336 '<ul$1class="$2 frontblocks-carousel"$3' .
337 ' data-type="' . esc_attr( $custom_option ) . '"' .
338 ' data-view="' . esc_attr( $items_to_view ) . '"' .
339 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
340 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
341 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
342 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
343 ' data-gap="' . esc_attr( $gap ) . '"' .
344 ' data-buttons="' . esc_attr( $buttons ) . '"' .
345 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
346 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
347 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
348 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
349 $extra .
350 '>',
351 $block_content,
352 1
353 );
354
355 $this->enqueue_carousel_assets();
356
357 return $block_content;
358 }
359
360 /**
361 * Register custom attributes for blocks.
362 *
363 * @return void
364 */
365 public function register_custom_attributes() {
366 // Register attributes before GenerateBlocks registers its blocks.
367 add_filter(
368 'generateblocks_blocks_registered_block',
369 array( $this, 'register_custom_attributes_for_grid_block' ),
370 9,
371 2
372 );
373
374 // Register attributes for core/query block.
375 add_filter( 'register_block_type_args', array( $this, 'register_query_block_attributes' ), 10, 2 );
376
377 // Register attributes from frontend side too.
378 add_action(
379 'enqueue_block_editor_assets',
380 array( $this, 'add_inline_script_for_attributes' )
381 );
382 }
383
384 /**
385 * Register custom attributes for GenerateBlocks Grid and Element blocks.
386 *
387 * @param array $block_args The block arguments.
388 * @param string $block_type The name of the block.
389 * @return array Modified block arguments.
390 */
391 public function register_custom_attributes_for_grid_block( $block_args, $block_type ) {
392 if ( 'generateblocks/grid' !== $block_type && 'generateblocks/element' !== $block_type ) {
393 return $block_args;
394 }
395
396 $block_args['attributes']['frblGridOption'] = array(
397 'type' => 'string',
398 'default' => 'none',
399 );
400 $block_args['attributes']['frblItemsToView'] = array(
401 'type' => 'string',
402 'default' => '4',
403 );
404 $block_args['attributes']['frblLaptopToView'] = array(
405 'type' => 'string',
406 'default' => '3',
407 );
408 $block_args['attributes']['frblTabletToView'] = array(
409 'type' => 'string',
410 'default' => '2',
411 );
412 $block_args['attributes']['frblResponsiveToView'] = array(
413 'type' => 'string',
414 'default' => '1',
415 );
416 $block_args['attributes']['frblAutoplay'] = array(
417 'type' => 'string',
418 'default' => '',
419 );
420 $block_args['attributes']['frblGap'] = array(
421 'type' => 'string',
422 'default' => '20',
423 );
424 $block_args['attributes']['frblRewind'] = array(
425 'type' => 'boolean',
426 'default' => true,
427 );
428 $block_args['attributes']['frblButtons'] = array(
429 'type' => 'string',
430 'default' => 'arrows',
431 );
432 $block_args['attributes']['frblButtonColor'] = array(
433 'type' => 'string',
434 'default' => '',
435 );
436 $block_args['attributes']['frblButtonBgColor'] = array(
437 'type' => 'string',
438 'default' => '',
439 );
440 $block_args['attributes']['frblButtonsPosition'] = array(
441 'type' => 'string',
442 'default' => 'side',
443 );
444 $block_args['attributes']['frblDisableOnDesktop'] = array(
445 'type' => 'boolean',
446 'default' => false,
447 );
448
449 return $block_args;
450 }
451
452 /**
453 * Register custom attributes for core/query block.
454 *
455 * @param array $args Block type arguments.
456 * @param string $block_type Block type name.
457 * @return array
458 */
459 public function register_query_block_attributes( $args, $block_type ) {
460 if ( 'core/query' !== $block_type ) {
461 return $args;
462 }
463
464 if ( ! isset( $args['attributes'] ) ) {
465 $args['attributes'] = array();
466 }
467
468 $args['attributes']['frblGridOption'] = array(
469 'type' => 'string',
470 'default' => 'none',
471 );
472 $args['attributes']['frblItemsToView'] = array(
473 'type' => 'string',
474 'default' => '4',
475 );
476 $args['attributes']['frblLaptopToView'] = array(
477 'type' => 'string',
478 'default' => '3',
479 );
480 $args['attributes']['frblTabletToView'] = array(
481 'type' => 'string',
482 'default' => '2',
483 );
484 $args['attributes']['frblResponsiveToView'] = array(
485 'type' => 'string',
486 'default' => '1',
487 );
488 $args['attributes']['frblAutoplay'] = array(
489 'type' => 'string',
490 'default' => '',
491 );
492 $args['attributes']['frblGap'] = array(
493 'type' => 'string',
494 'default' => '20',
495 );
496 $args['attributes']['frblRewind'] = array(
497 'type' => 'boolean',
498 'default' => true,
499 );
500 $args['attributes']['frblButtons'] = array(
501 'type' => 'string',
502 'default' => 'arrows',
503 );
504 $args['attributes']['frblButtonColor'] = array(
505 'type' => 'string',
506 'default' => '',
507 );
508 $args['attributes']['frblButtonBgColor'] = array(
509 'type' => 'string',
510 'default' => '',
511 );
512 $args['attributes']['frblButtonsPosition'] = array(
513 'type' => 'string',
514 'default' => 'side',
515 );
516 $args['attributes']['frblDisableOnDesktop'] = array(
517 'type' => 'boolean',
518 'default' => false,
519 );
520
521 return $args;
522 }
523
524 /**
525 * Add inline script for block attributes.
526 *
527 * @return void
528 */
529 public function add_inline_script_for_attributes() {
530 wp_add_inline_script(
531 'wp-blocks',
532 "
533 wp.hooks.addFilter(
534 'blocks.registerBlockType',
535 'frontblocks/grid-attributes',
536 function( settings, name ) {
537 if ( name !== 'generateblocks/grid' && name !== 'generateblocks/element' && name !== 'core/group' && name !== 'core/query' ) {
538 return settings;
539 }
540
541 settings.attributes = {
542 ...settings.attributes,
543 frblGridOption: {
544 type: 'string',
545 default: 'none'
546 },
547 frblItemsToView: {
548 type: 'string',
549 default: '4'
550 },
551 frblLaptopToView: {
552 type: 'string',
553 default: '3'
554 },
555 frblTabletToView: {
556 type: 'string',
557 default: '2'
558 },
559 frblResponsiveToView: {
560 type: 'string',
561 default: '1'
562 },
563 frblAutoplay: {
564 type: 'string',
565 default: ''
566 },
567 frblGap: {
568 type: 'string',
569 default: '20'
570 },
571 frblButtons: {
572 type: 'string',
573 default: 'arrows'
574 },
575 frblButtonsPosition: {
576 type: 'string',
577 default: 'side'
578 },
579 frblButtonColor: {
580 type: 'string',
581 default: ''
582 },
583 frblButtonBgColor: {
584 type: 'string',
585 default: ''
586 },
587 frblRewind: {
588 type: 'boolean',
589 default: true
590 },
591 frblDisableOnDesktop: {
592 type: 'boolean',
593 default: false
594 }
595 };
596
597 return settings;
598 }
599 );
600 "
601 );
602 }
603 }
604