PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / classes / block-global.php

block-global.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.13.1, at includes/classes/block-global.php

165 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Classes;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Controls\Dimensions;
9 use ABlocks\Controls\Width;
10 use ABlocks\Controls\Border;
11 use ABlocks\Controls\Position;
12 use ABlocks\Controls\Background;
13 use ABlocks\Controls\Zindex;
14 use ABlocks\Controls\Transform;
15 use ABlocks\Controls\Mask;
16 use ABlocks\Controls\Animation;
17 use ABlocks\Controls\BoxShadow;
18 use ABlocks\Controls\GsapAnimation;
19 use ABlocks\Helper;
20
21 class BlockGlobal {
22 public static function get_attributes() {
23 $attributes = [
24 '_hide_on_desktop' => [
25 'type' => 'boolean',
26 'default' => false,
27 ],
28 '_hide_on_tablet' => [
29 'type' => 'boolean',
30 'default' => false,
31 ],
32 '_hide_on_mobile' => [
33 'type' => 'boolean',
34 'default' => false,
35 ],
36 '_custom_css' => [
37 'type' => 'string',
38 'default' => '',
39 ],
40 '_animation_element_trigger' => [
41 'type' => 'array',
42 'default' => [],
43 'items' => [
44 'type' => 'object'
45 ]
46 ],
47 '_animation_page_trigger' => [
48 'type' => 'array',
49 'default' => [],
50 'items' => [
51 'type' => 'object'
52 ]
53 ],
54 ];
55 $attributes = array_merge(
56 Dimensions::get_attribute( '_margin', true ),
57 Dimensions::get_attribute( '_padding', true ),
58 Width::get_attribute( '_width', true ),
59 Border::get_attribute( '_border', true ),
60 Position::get_attribute( '_position', true ),
61 Background::get_attribute( '_background', true ),
62 Zindex::get_attribute( '_zIndex', true ),
63 Transform::get_attribute( '_transform', true ),
64 Mask::get_attribute( '_mask', true ),
65 Animation::get_attribute( '_animation', true ),
66 BoxShadow::get_attribute( '_boxShadow', true ),
67 Transform::get_attribute( '_transform', true ),
68 GsapAnimation::get_attribute( '_gsapAnimation', true ),
69 $attributes,
70 );
71 return apply_filters( 'ablocks/get_block_common_attributes', $attributes );
72 }
73 public static function get_wrapper_css( $attribute, $device = '' ) {
74 $transitions = [];
75 $transition_types = [
76 '_border' => 'border',
77 '_background' => 'background',
78 '_boxShadow' => 'box-shadow',
79 ];
80 foreach ( $transition_types as $key => $property ) {
81 // Only add a transition when the user actually set a non-zero
82 // duration. Previously every block emitted the no-op
83 // "transition:border 0s ease,background 0s ease,box-shadow 0s ease"
84 // on its wrapper (0s = no transition) — dead CSS on every block.
85 if ( isset( $attribute[ $key ]['transitionDuration'] ) && (float) $attribute[ $key ]['transitionDuration'] > 0 ) {
86 $duration = $attribute[ $key ]['transitionDuration'];
87 $transitions[] = "{$property} {$duration}s ease";
88 }
89 }
90 $transition_string = implode( ',', $transitions );
91
92 $css = array_merge(
93 Dimensions::get_css( $attribute['_margin'], 'margin', $device ),
94 Dimensions::get_css( $attribute['_padding'], 'padding', $device ),
95 Mask::get_css( $attribute['_mask'], '', $device ),
96 Background::get_css( $attribute['_background'], 'background', $device ),
97 Border::get_css( $attribute['_border'], '', $device ),
98 Width::get_css( $attribute['_width'], 'width', $device ),
99 BoxShadow::get_css( $attribute['_boxShadow'], $device ),
100 Position::get_css( $attribute['_position'], 'position', $device ),
101 Zindex::get_css( $attribute['_zIndex'], 'z-index', $device ),
102 // Only emit transition when there's a real (non-zero) one.
103 '' !== $transition_string ? [ 'transition' => $transition_string ] : []
104 );
105 return apply_filters( 'ablocks/get_block_common_wrapper_css', $css, $attribute, $device );
106 }
107 public static function get_wrapper_hover_css( $attribute, $device = '' ) {
108 $css = array_merge(
109 Background::get_hover_css( $attribute['_background'], 'background', $device ),
110 Border::get_hover_css( $attribute['_border'], '', $device ),
111 BoxShadow::get_hover_css( $attribute['_boxShadow'], '', $device ),
112 );
113 return apply_filters( 'ablocks/get_block_common_wrapper_hover_css', $css, $attribute, $device );
114 }
115 public static function get_container_css( $attribute, $device = '' ) {
116 $css = array_merge(
117 Transform::get_css( $attribute['_transform'], 'transform', $device ),
118 );
119 return apply_filters( 'ablocks/get_block_common_container_css', $css, $attribute, $device );
120 }
121 public static function get_container_hover_css( $attribute, $device = '' ) {
122 $css = array_merge(
123 Transform::get_hover_css( $attribute['_transform'], 'transform', $device ),
124 );
125 return apply_filters( 'ablocks/get_block_common_container_hover_css', $css, $attribute, $device );
126 }
127 public static function get_wrapper_device_responsive_css( $attribute, $device = '' ) {
128 if (
129 ! isset( $attribute['_hide_on_desktop'] ) &&
130 ! isset( $attribute['_hide_on_tablet'] ) &&
131 ! isset( $attribute['_hide_on_mobile'] )
132 ) {
133 return [];
134 }
135
136 // Desktop (default view)
137 if ( '' === $device && Helper::has_value( $attribute['_hide_on_desktop'] ) ) {
138 return [ 'display' => 'none' ];
139 }
140
141 // Tablet
142 if ( 'Tablet' === $device ) {
143 if ( Helper::has_value( $attribute['_hide_on_tablet'] ) ) {
144 return [ 'display' => 'none' ];
145 }
146 if ( Helper::has_value( $attribute['_hide_on_desktop'] ) ) {
147 return [ 'display' => 'block' ];
148 }
149 }
150
151 // Mobile
152 if ( 'Mobile' === $device ) {
153 if ( Helper::has_value( $attribute['_hide_on_mobile'] ) ) {
154 return [ 'display' => 'none' ];
155 }
156 if ( Helper::has_value( $attribute['_hide_on_tablet'] ) ) {
157 return [ 'display' => 'block' ];
158 }
159 }
160
161 return [];
162 }
163
164 }
165