PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.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 All 81 releases
← All changes | includes/controls/position.php +87 -0 1.0 → 2.14.0 View file →
@@ -1,0 +1,87 @@
1 +<?php
2 +namespace ABlocks\Controls;
3 +
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
8 +use ABlocks\Classes\ControlBaseAbstract;
9 +use ABlocks\Helper;
10 +
11 +class Position extends ControlBaseAbstract {
12 + public static function get_attribute_default_value( $is_responsive = false ) {
13 + if ( $is_responsive ) {
14 + return [
15 + 'positionType' => 'relative',
16 + 'positionTypeTablet' => '',
17 + 'positionTypeMobile' => '',
18 + 'hOrientation' => '',
19 + 'hOffset' => '',
20 + 'hOffsetTablet' => '',
21 + 'hOffsetMobile' => '',
22 + 'hOffsetUnit' => 'px',
23 + 'hOffsetUnitTablet' => 'px',
24 + 'hOffsetUnitMobile' => 'px',
25 + 'vOrientation' => '',
26 + 'vOffset' => '',
27 + 'vOffsetTablet' => '',
28 + 'vOffsetMobile' => '',
29 + 'vOffsetUnit' => 'px',
30 + 'vOffsetUnitTablet' => 'px',
31 + 'vOffsetUnitMobile' => 'px',
32 + ];
33 + }//end if
34 + return [
35 + 'positionType' => 'relative',
36 + 'hOrientation' => '',
37 + 'hOffset' => '0',
38 + 'hOffsetUnit' => 'px',
39 + 'vOrientation' => '',
40 + 'vOffset' => '0',
41 + 'vOffsetUnit' => 'px',
42 + ];
43 + }
44 +
45 + public static function get_attribute( $attributeName, $is_responsive = false ) {
46 + return [
47 + $attributeName => [
48 + 'type' => 'object',
49 + 'default' => self::get_attribute_default_value( $is_responsive ),
50 + ]
51 + ];
52 + }
53 +
54 + public static function get_css( $attribute_value, $property = '', $device = '' ) {
55 + $default_attr_value = self::get_attribute_default_value( (bool) $device );
56 + $value = wp_parse_args( $attribute_value, $default_attr_value );
57 + $css = [];
58 +
59 + $h_offset_unit = Helper::get_responsive_value( $value, 'hOffsetUnit', $device );
60 + $v_offset_unit = Helper::get_responsive_value( $value, 'vOffsetUnit', $device );
61 +
62 + if ( ! empty( $value['positionType'] ) ) {
63 + $css[ $property ] = $value['positionType'];
64 + }
65 +
66 + $is_absolute_or_fixed = $value['positionType'] === 'absolute' || $value['positionType'] === 'fixed';
67 +
68 + if ( $is_absolute_or_fixed ) {
69 + if ( ! empty( $value[ 'hOrientation' . $device ] ) && $value[ 'hOrientation' . $device ] === 'right' ) {
70 + $css['right'] = $value[ 'hOffset' . $device ] . $h_offset_unit;
71 + unset( $css['left'] );
72 + } elseif ( ! empty( $value[ 'hOffset' . $device ] ) ) {
73 + $css['left'] = $value[ 'hOffset' . $device ] . $h_offset_unit;
74 + unset( $css['right'] );
75 + }
76 +
77 + if ( ! empty( $value[ 'vOrientation' . $device ] ) && $value[ 'vOrientation' . $device ] === 'bottom' ) {
78 + $css['bottom'] = $value[ 'vOffset' . $device ] . $v_offset_unit;
79 + unset( $css['top'] );
80 + } elseif ( ! empty( $value[ 'vOffset' . $device ] ) ) {
81 + $css['top'] = $value[ 'vOffset' . $device ] . $v_offset_unit;
82 + unset( $css['bottom'] );
83 + }
84 + }
85 + return $css;
86 + }
87 +}