PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 3.2.0
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v3.2.0
3.2.0 3.1.0 3.0.0 2.13.2 2.13.1 2.13.0 trunk 1.0.0 2.1.0 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.1 2.5.3 2.5.4 2.5.5 All 57 releases
slider-blocks / includes / Blocks / StaticSlider.php

StaticSlider.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 3.2.0, at includes/Blocks/StaticSlider.php

73 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare( strict_types=1 );
3
4 namespace GutSlider\Blocks;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 /**
11 * Static slider (gutsliders/content-slider): motion effects on the page.
12 *
13 * The block saves static markup and many are published, so the newer motion settings
14 * (content reveal, pointer effect, magnetic buttons) are added to the saved HTML as it is
15 * printed: classes on the block wrapper, which frontend.js and style.scss act on.
16 *
17 * @package GutSlider\Blocks
18 * @since 3.2.0
19 */
20 final class StaticSlider {
21
22 /** Values the motion settings may take. */
23 const REVEALS = array( 'words', 'letters', 'blur', 'mask' );
24 const POINTERS = array( 'depth', 'tilt', 'spotlight' );
25
26 /**
27 * Constructor.
28 */
29 public function __construct() {
30 add_filter( 'render_block_gutsliders/content-slider', array( $this, 'render' ), 20, 2 );
31 }
32
33 /**
34 * Add the motion classes to the slider wrapper.
35 *
36 * @param string $content Block HTML.
37 * @param array $block Parsed block.
38 * @return string
39 */
40 public function render( $content, $block ) {
41 $attrs = $block['attrs'] ?? array();
42 $reveal = in_array( $attrs['textReveal'] ?? '', self::REVEALS, true ) ? $attrs['textReveal'] : '';
43 $pointer = in_array( $attrs['pointerEffect'] ?? '', self::POINTERS, true ) ? $attrs['pointerEffect'] : '';
44 $magnet = ! empty( $attrs['magneticButtons'] );
45
46 if ( ! $reveal && ! $pointer && ! $magnet ) {
47 return $content;
48 }
49
50 $tags = new \WP_HTML_Tag_Processor( $content );
51 if ( ! $tags->next_tag( array( 'class_name' => 'wp-block-gutsliders-content-slider' ) ) ) {
52 return $content;
53 }
54
55 // Read by motion.js and style.scss.
56 if ( $reveal ) {
57 $tags->add_class( 'gs-reveal' );
58 $tags->add_class( 'gs-reveal-' . $reveal );
59 if ( in_array( $attrs['revealSpeed'] ?? '', array( 'slow', 'fast' ), true ) ) {
60 $tags->add_class( 'gs-reveal-' . $attrs['revealSpeed'] );
61 }
62 }
63 if ( $pointer ) {
64 $tags->add_class( 'gs-pointer-' . $pointer );
65 }
66 if ( $magnet ) {
67 $tags->add_class( 'gs-magnetic' );
68 }
69
70 return $tags->get_updated_html();
71 }
72 }
73