PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.3
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.3
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / extend / effects / index.php

index.php in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.3, at gutenberg/extend/effects/index.php

115 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Effects Extension.
4 *
5 * @package ghostkit
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class GhostKit_Extension_Effects
14 */
15 class GhostKit_Extension_Effects {
16 /**
17 * GhostKit_Extension_Effects constructor.
18 */
19 public function __construct() {
20 GhostKit_Extensions::register(
21 'effects',
22 array(
23 'default_supports' => array(
24 'effects' => array(
25 'reveal' => true,
26 'mouseHover' => true,
27 'mousePress' => true,
28 'mouseMove' => true,
29 'scroll' => true,
30 'loop' => true,
31 ),
32 ),
33 'render_block' => array( $this, 'render_block' ),
34 )
35 );
36
37 add_action( 'wp_head', array( $this, 'add_reveal_styles' ) );
38 }
39
40 /**
41 * Renders attributes to the block wrapper.
42 *
43 * @param string $block_content Rendered block content.
44 * @param array $block Block object.
45 * @param WP_Block_Type $block_type Block type.
46 *
47 * @return string Filtered block content.
48 */
49 public function render_block( $block_content, $block, $block_type ) {
50 $has_effects_support = block_has_support( $block_type, array( 'ghostkit', 'effects' ), null );
51
52 if ( ! $has_effects_support ) {
53 return $block_content;
54 }
55
56 $effects_data = array();
57
58 $has_reveal_support = block_has_support( $block_type, array( 'ghostkit', 'effects', 'reveal' ), null );
59 $reveal_data = _wp_array_get( $block['attrs'], array( 'ghostkit', 'effects', 'reveal' ), false );
60
61 if ( $has_reveal_support && $reveal_data && is_array( $reveal_data ) ) {
62 $effects_data['reveal'] = $reveal_data;
63 }
64
65 $effects_data = apply_filters( 'gkt_extension_effects_data', $effects_data, $block_content, $block, $block_type );
66
67 if ( empty( $effects_data ) ) {
68 return $block_content;
69 }
70
71 // Inject data attribute to block container markup.
72 $processor = new WP_HTML_Tag_Processor( $block_content );
73
74 if ( $processor->next_tag() ) {
75 $effects_data_string = wp_json_encode( $effects_data );
76
77 $processor->set_attribute( 'data-gkt-effects', esc_attr( $effects_data_string ) );
78
79 if ( ! empty( $effects_data['reveal'] ) ) {
80 $processor->add_class( 'ghostkit-effects-reveal' );
81 }
82
83 $processor = apply_filters( 'gkt_extension_effects_tag_processor', $processor, $effects_data, $block_content, $block, $block_type );
84 }
85
86 return $processor->get_updated_html();
87 }
88
89 /**
90 * Add styles using JS for effects reveal feature.
91 * As we need to hide blocks, we should make sure that
92 * 1. JS is enabled in the browser.
93 * 2. User has not set reduced motion in the OS settings.
94 */
95 public function add_reveal_styles() {
96 ?>
97 <style type="text/css">
98 .ghostkit-effects-enabled .ghostkit-effects-reveal {
99 pointer-events: none;
100 visibility: hidden;
101 }
102 </style>
103 <script>
104 if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
105 document.documentElement.classList.add(
106 'ghostkit-effects-enabled'
107 );
108 }
109 </script>
110 <?php
111 }
112 }
113
114 new GhostKit_Extension_Effects();
115