PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / trunk
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder vtrunk
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 1.2.0 1.2.1 All 78 releases
ablocks / includes / controls / position.php

position.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder trunk, at includes/controls/position.php

101 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Controls;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\ControlBaseAbstract;
9
10 class Position extends ControlBaseAbstract {
11 public static function get_attribute_default_value( $is_responsive = false ) {
12 if ( $is_responsive ) {
13 return [
14 'positionType' => 'relative',
15 'positionTypeTablet' => '',
16 'positionTypeMobile' => '',
17 'hOrientation' => '',
18 'hOffset' => '',
19 'hOffsetTablet' => '',
20 'hOffsetMobile' => '',
21 'hOffsetUnit' => 'px',
22 'hOffsetUnitTablet' => 'px',
23 'hOffsetUnitMobile' => 'px',
24 'vOrientation' => '',
25 'vOffset' => '',
26 'vOffsetTablet' => '',
27 'vOffsetMobile' => '',
28 'vOffsetUnit' => 'px',
29 'vOffsetUnitTablet' => 'px',
30 'vOffsetUnitMobile' => 'px',
31 ];
32 }//end if
33 return [
34 'positionType' => 'relative',
35 'hOrientation' => '',
36 'hOffset' => '0',
37 'hOffsetUnit' => 'px',
38 'vOrientation' => '',
39 'vOffset' => '0',
40 'vOffsetUnit' => 'px',
41 ];
42 }
43
44 public static function get_attribute( $attributeName, $is_responsive = false ) {
45 return [
46 $attributeName => [
47 'type' => 'object',
48 'default' => self::get_attribute_default_value( $is_responsive ),
49 ]
50 ];
51 }
52
53 public static function get_css( $attribute_value, $property = '', $device = '' ) {
54 $default_attr_value = self::get_attribute_default_value( (bool) $device );
55 $value = wp_parse_args( $attribute_value, $default_attr_value );
56 $css = [];
57
58 $h_offset_unit = self::get_unit(
59 [
60 'unit' => ! empty( $value['hOffsetUnit'] ) ? $value['hOffsetUnit'] : '',
61 'unitTablet' => ! empty( $value['hOffsetUnitTablet'] ) ? $value['hOffsetUnitTablet'] : '',
62 'unitMobile' => ! empty( $value['hOffsetUnitMobile'] ) ? $value['hOffsetUnitMobile'] : '',
63 ],
64 $device
65 );
66 $v_offset_unit = self::get_unit(
67 [
68 'unit' => ! empty( $value['vOffsetUnit'] ) ? $value['vOffsetUnit'] : '',
69 'unitTablet' => ! empty( $value['vOffsetUnitTablet'] ) ? $value['vOffsetUnitTablet'] : '',
70 'unitMobile' => ! empty( $value['vOffsetUnitMobile'] ) ? $value['vOffsetUnitMobile'] : '',
71 ],
72 $device
73 );
74
75 if ( ! empty( $value['positionType'] ) ) {
76 $css[ $property ] = $value['positionType'];
77 }
78
79 $is_absolute_or_fixed = $value['positionType'] === 'absolute' || $value['positionType'] === 'fixed';
80
81 if ( $is_absolute_or_fixed ) {
82 if ( ! empty( $value[ 'hOrientation' . $device ] ) && $value[ 'hOrientation' . $device ] === 'right' ) {
83 $css['right'] = $value[ 'hOffset' . $device ] . $h_offset_unit;
84 unset( $css['left'] );
85 } elseif ( ! empty( $value[ 'hOffset' . $device ] ) ) {
86 $css['left'] = $value[ 'hOffset' . $device ] . $h_offset_unit;
87 unset( $css['right'] );
88 }
89
90 if ( ! empty( $value[ 'vOrientation' . $device ] ) && $value[ 'vOrientation' . $device ] === 'bottom' ) {
91 $css['bottom'] = $value[ 'vOffset' . $device ] . $v_offset_unit;
92 unset( $css['top'] );
93 } elseif ( ! empty( $value[ 'vOffset' . $device ] ) ) {
94 $css['top'] = $value[ 'vOffset' . $device ] . $v_offset_unit;
95 unset( $css['bottom'] );
96 }
97 }
98 return $css;
99 }
100 }
101