PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.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 / controls / width.php

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

95 lines 2.3 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 Width extends ControlBaseAbstract {
11
12 public static function get_attribute_default_value( $is_responsive = false ) {
13 if ( $is_responsive ) {
14 return [
15 'widthType' => 'default',
16 'widthTypeTablet' => '',
17 'widthTypeMobile' => '',
18 'customWidth' => '',
19 'customWidthTablet' => '',
20 'customWidthMobile' => '',
21 'customWidthUnit' => '%',
22 'customWidthUnitTablet' => '',
23 'customWidthUnitMobile' => '',
24 ];
25 }
26 return [
27 'widthType' => 'default',
28 'customWidth' => '',
29 'customWidthUnit' => '%',
30 ];
31 }
32
33 public static function get_attribute( $attributeName, $isResponsive = false ) {
34 if ( $isResponsive ) {
35 return [
36 $attributeName => [
37 'type' => 'object',
38 'default' => self::get_attribute_default_value(
39 $isResponsive
40 ),
41 ],
42 ];
43 }
44 return [
45 $attributeName => [
46 'type' => 'object',
47 'default' => self::get_attribute_default_value( $isResponsive ),
48 ],
49 ];
50 }
51 public static function get_css(
52 $attribute_value,
53 $property = '',
54 $device = ''
55 ) {
56 $attribute_value = wp_parse_args(
57 $attribute_value,
58 self::get_attribute_default_value( (bool) $device )
59 );
60 $css = [];
61 if ( ! empty( $attribute_value[ 'widthType' . $device ] ) ) {
62 if ( $attribute_value[ 'widthType' . $device ] === 'full' ) {
63 $css[ $property ] = '100%';
64 } elseif ( $attribute_value[ 'widthType' . $device ] === 'auto' ) {
65 $css[ $property ] = 'auto';
66 $css['display'] = 'inline-block';
67 } elseif ( $attribute_value[ 'widthType' . $device ] === 'custom' ) {
68 $css[ $property ] =
69 $attribute_value[ 'customWidth' . $device ] .
70 self::get_unit(
71 [
72 'unit' => ! empty(
73 $attribute_value['customWidthUnit']
74 )
75 ? $attribute_value['customWidthUnit']
76 : '',
77 'unitTablet' => ! empty(
78 $attribute_value['customWidthUnitTablet']
79 )
80 ? $attribute_value['customWidthUnitTablet']
81 : '',
82 'unitMobile' => ! empty(
83 $attribute_value['customWidthUnitTablet']
84 )
85 ? $attribute_value['customWidthUnitTablet']
86 : '',
87 ],
88 $device
89 ) . '!important';
90 }//end if
91 }//end if
92 return $css;
93 }
94 }
95