| @@ -14,8 +14,9 @@ | ||
| 14 | 14 | use ABlocks\Controls\Transform; |
| 15 | 15 | use ABlocks\Controls\Mask; |
| 16 | 16 | use ABlocks\Controls\Animation; |
| 17 | 17 | use ABlocks\Controls\BoxShadow; |
| 18 | +use ABlocks\Controls\GsapAnimation; | |
| 18 | 19 | use ABlocks\Helper; |
| 19 | 20 | |
| 20 | 21 | class BlockGlobal { |
| 21 | 22 | public static function get_attributes() { |
| @@ -34,9 +35,23 @@ | ||
| 34 | 35 | ], |
| 35 | 36 | '_custom_css' => [ |
| 36 | 37 | 'type' => 'string', |
| 37 | 38 | 'default' => '', |
| 38 | - ] | |
| 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 | + ], | |
| 39 | 54 | ]; |
| 40 | 55 | $attributes = array_merge( |
| 41 | 56 | Dimensions::get_attribute( '_margin', true ), |
| 42 | 57 | Dimensions::get_attribute( '_padding', true ), |
| @@ -49,8 +64,9 @@ | ||
| 49 | 64 | Mask::get_attribute( '_mask', true ), |
| 50 | 65 | Animation::get_attribute( '_animation', true ), |
| 51 | 66 | BoxShadow::get_attribute( '_boxShadow', true ), |
| 52 | 67 | Transform::get_attribute( '_transform', true ), |
| 68 | + GsapAnimation::get_attribute( '_gsapAnimation', true ), | |
| 53 | 69 | $attributes, |
| 54 | 70 | ); |
| 55 | 71 | return apply_filters( 'ablocks/get_block_common_attributes', $attributes ); |
| 56 | 72 | } |
| @@ -61,10 +77,14 @@ | ||
| 61 | 77 | '_background' => 'background', |
| 62 | 78 | '_boxShadow' => 'box-shadow', |
| 63 | 79 | ]; |
| 64 | 80 | foreach ( $transition_types as $key => $property ) { |
| 65 | - if ( isset( $attribute[ $key ] ) ) { | |
| 66 | - $duration = ! empty( $attribute[ $key ]['transitionDuration'] ) ? $attribute[ $key ]['transitionDuration'] : '0'; | |
| 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']; | |
| 67 | 87 | $transitions[] = "{$property} {$duration}s ease"; |
| 68 | 88 | } |
| 69 | 89 | } |
| 70 | 90 | $transition_string = implode( ',', $transitions ); |
| @@ -71,9 +91,9 @@ | ||
| 71 | 91 | |
| 72 | 92 | $css = array_merge( |
| 73 | 93 | Dimensions::get_css( $attribute['_margin'], 'margin', $device ), |
| 74 | 94 | Dimensions::get_css( $attribute['_padding'], 'padding', $device ), |
| 75 | - Mask::get_css( $attribute['_mask'], $device ), | |
| 95 | + Mask::get_css( $attribute['_mask'], '', $device ), | |
| 76 | 96 | Background::get_css( $attribute['_background'], 'background', $device ), |
| 77 | 97 | Border::get_css( $attribute['_border'], '', $device ), |
| 78 | 98 | Width::get_css( $attribute['_width'], 'width', $device ), |
| 79 | 99 | BoxShadow::get_css( $attribute['_boxShadow'], $device ), |
| @@ -78,9 +98,10 @@ | ||
| 78 | 98 | Width::get_css( $attribute['_width'], 'width', $device ), |
| 79 | 99 | BoxShadow::get_css( $attribute['_boxShadow'], $device ), |
| 80 | 100 | Position::get_css( $attribute['_position'], 'position', $device ), |
| 81 | 101 | Zindex::get_css( $attribute['_zIndex'], 'z-index', $device ), |
| 82 | - [ 'transition' => $transition_string ] | |
| 102 | + // Only emit transition when there's a real (non-zero) one. | |
| 103 | + '' !== $transition_string ? [ 'transition' => $transition_string ] : [] | |
| 83 | 104 | ); |
| 84 | 105 | return apply_filters( 'ablocks/get_block_common_wrapper_css', $css, $attribute, $device ); |
| 85 | 106 | } |
| 86 | 107 | public static function get_wrapper_hover_css( $attribute, $device = '' ) { |
| @@ -103,30 +124,41 @@ | ||
| 103 | 124 | ); |
| 104 | 125 | return apply_filters( 'ablocks/get_block_common_container_hover_css', $css, $attribute, $device ); |
| 105 | 126 | } |
| 106 | 127 | public static function get_wrapper_device_responsive_css( $attribute, $device = '' ) { |
| 107 | - if ( ! isset( $attribute['_hide_on_desktop'] ) && ! isset( $attribute['_hide_on_tablet'] ) && ! isset( $attribute['_hide_on_mobile'] ) ) { | |
| 128 | + if ( | |
| 129 | + ! isset( $attribute['_hide_on_desktop'] ) && | |
| 130 | + ! isset( $attribute['_hide_on_tablet'] ) && | |
| 131 | + ! isset( $attribute['_hide_on_mobile'] ) | |
| 132 | + ) { | |
| 108 | 133 | return []; |
| 109 | 134 | } |
| 110 | 135 | |
| 111 | - if ( ! $device && Helper::has_value( $attribute['_hide_on_desktop'] ) ) { | |
| 112 | - return [ | |
| 113 | - 'display' => 'none' | |
| 114 | - ]; | |
| 136 | + // Desktop (default view) | |
| 137 | + if ( '' === $device && Helper::has_value( $attribute['_hide_on_desktop'] ) ) { | |
| 138 | + return [ 'display' => 'none' ]; | |
| 115 | 139 | } |
| 116 | 140 | |
| 117 | - if ( 'Tablet' === $device && Helper::has_value( $attribute['_hide_on_tablet'] ) ) { | |
| 118 | - return [ | |
| 119 | - 'display' => 'none' | |
| 120 | - ]; | |
| 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 | + } | |
| 121 | 149 | } |
| 122 | - if ( 'Mobile' === $device && Helper::has_value( $attribute['_hide_on_mobile'] ) ) { | |
| 123 | - return [ | |
| 124 | - 'display' => 'none' | |
| 125 | - ]; | |
| 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 | + } | |
| 126 | 159 | } |
| 127 | 160 | |
| 128 | - return [ | |
| 129 | - 'display' => 'inherit' | |
| 130 | - ]; | |
| 161 | + return []; | |
| 131 | 162 | } |
| 163 | + | |
| 132 | 164 | } |