PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.0
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
← All changes | includes/controls/box-shadow.php +106 -0 2.7.72.13.0 View file →
@@ -1,0 +1,106 @@
1 +<?php
2 +namespace ABlocks\Controls;
3 +
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
8 +use ABlocks\Classes\ControlBaseAbstract;
9 +use ABlocks\Controls\Color;
10 +
11 +class BoxShadow extends ControlBaseAbstract {
12 + public static function get_attribute_default_value( $is_responsive = false ) {
13 + return [
14 + 'preset' => '',
15 + 'shadowType' => 'default',
16 + 'shadow' => '',
17 + 'horizontal' => '',
18 + 'vertical' => '',
19 + 'blur' => '',
20 + 'spread' => '',
21 + 'color' => '',
22 + 'presetH' => '',
23 + 'shadowTypeH' => 'default',
24 + 'shadowH' => '',
25 + 'horizontalH' => '',
26 + 'verticalH' => '',
27 + 'blurH' => '',
28 + 'spreadH' => '',
29 + 'colorH' => '',
30 + 'transitionDuration' => '0',
31 + ];
32 + }
33 +
34 + public static function get_attribute( $attributeName, $is_responsive = false ) {
35 + return [
36 + $attributeName => [
37 + 'type' => 'object',
38 + 'default' => self::get_attribute_default_value( true ),
39 + ],
40 + ];
41 + }
42 + public static function get_css( $attribute_value, $property = '', $device = '' ) {
43 + $value = wp_parse_args( $attribute_value,
44 + self::get_attribute_default_value( true )
45 + );
46 + $css = [];
47 + $color = Color::get_css( $value['color'] ? $value['color'] : '#000000' );
48 + if ( $value['shadowType'] !== 'default' && $value['shadowType'] === 'inner_shadow' ) {
49 + if ( ! empty( $value['preset'] ) ) {
50 + $css['box-shadow'] = 'inset ' . $value['horizontal'] . 'px ' . $value['vertical'] . 'px ' . $value['blur'] . 'px ' . $value['spread'] . 'px ' . $color;
51 +
52 + }
53 + } elseif ( $value['shadowType'] !== 'default' && $value['shadowType'] === 'outer_shadow' ) {
54 + if ( ! empty( $value['preset'] ) ) {
55 + $css['box-shadow'] = $value['horizontal'] . 'px ' . $value['vertical'] . 'px ' . $value['blur'] . 'px ' . $value['spread'] . 'px ' . $color;
56 + }
57 + } else {
58 + // A 0 offset is a valid shadow (e.g. a centered glow); only an unset
59 + // value skips it, matching the editor's '' / undefined check.
60 + if ( self::is_offset_set( $value['horizontal'] ) && self::is_offset_set( $value['vertical'] ) ) {
61 + $css['box-shadow'] = $value['horizontal'] . 'px ' . $value['vertical'] . 'px ' . $value['blur'] . 'px ' . $value['spread'] . 'px ' . $color;
62 + }
63 + }
64 + if ( $value['transitionDuration'] ) {
65 + // This control animates the box-shadow, so the transition property is
66 + // always "box-shadow". Previously it used $property, which callers
67 + // pass inconsistently (often the device string), producing invalid
68 + // CSS like "transition:Tablet 0.3s".
69 + $css['transition'] = 'box-shadow ' . $value['transitionDuration'] . 's';
70 + }
71 + return $css;
72 + }
73 +
74 + public static function get_hover_css( $attribute, $device = '' ) {
75 + $value = wp_parse_args(
76 + $attribute,
77 + self::get_attribute_default_value( true ),
78 + );
79 +
80 + $css = [];
81 + $colorH = Color::get_css( $value['colorH'] ? $value['colorH'] : '#000000' );
82 + if ( $value['shadowTypeH'] !== 'default' && $value['shadowTypeH'] === 'inner_shadow' ) {
83 + if ( ! empty( $value['presetH'] ) ) {
84 + $css['box-shadow'] = 'inset ' . $value['horizontalH'] . 'px ' . $value['verticalH'] . 'px ' . $value['blurH'] . 'px ' . $value['spreadH'] . 'px ' . $colorH;
85 + }
86 + } elseif ( $value['shadowTypeH'] !== 'default' && $value['shadowTypeH'] === 'outer_shadow' ) {
87 + if ( ! empty( $value['presetH'] ) ) {
88 + $css['box-shadow'] = $value['horizontalH'] . 'px ' . $value['verticalH'] . 'px ' . $value['blurH'] . 'px ' . $value['spreadH'] . 'px ' . $colorH;
89 + }
90 + } else {
91 + if ( self::is_offset_set( $value['horizontalH'] ) && self::is_offset_set( $value['verticalH'] ) ) {
92 + $css['box-shadow'] = $value['horizontalH'] . 'px ' . $value['verticalH'] . 'px ' . $value['blurH'] . 'px ' . $value['spreadH'] . 'px ' . $colorH;
93 + }
94 + }
95 + return $css;
96 + }
97 +
98 + /**
99 + * Whether a shadow offset is set. 0 / "0" count as set; only null and ''
100 + * mean "not configured".
101 + */
102 + private static function is_offset_set( $value ) {
103 + return null !== $value && '' !== $value;
104 + }
105 +
106 +}