PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.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
← All changes | includes/controls/width.php +104 -0 1.0-beta32.13.1 View file →
@@ -1,0 +1,104 @@
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 Width extends ControlBaseAbstract {
12 +
13 + public static function get_attribute_default_value( $is_responsive = false ) {
14 + if ( $is_responsive ) {
15 + return [
16 + 'widthType' => 'default',
17 + 'widthTypeTablet' => '',
18 + 'widthTypeMobile' => '',
19 + 'customWidth' => '',
20 + 'customWidthTablet' => '',
21 + 'customWidthMobile' => '',
22 + 'customWidthUnit' => '%',
23 + 'customWidthUnitTablet' => '',
24 + 'customWidthUnitMobile' => '',
25 + ];
26 + }
27 + return [
28 + 'widthType' => 'default',
29 + 'customWidth' => '',
30 + 'customWidthUnit' => '%',
31 + ];
32 + }
33 +
34 + public static function get_attribute( $attributeName, $isResponsive = false ) {
35 + if ( $isResponsive ) {
36 + return [
37 + $attributeName => [
38 + 'type' => 'object',
39 + 'default' => self::get_attribute_default_value(
40 + $isResponsive
41 + ),
42 + ],
43 + ];
44 + }
45 + return [
46 + $attributeName => [
47 + 'type' => 'object',
48 + 'default' => self::get_attribute_default_value( $isResponsive ),
49 + ],
50 + ];
51 + }
52 + public static function get_css(
53 + $attribute_value,
54 + $property = '',
55 + $device = ''
56 + ) {
57 + $attribute_value = wp_parse_args(
58 + $attribute_value,
59 + self::get_attribute_default_value( (bool) $device )
60 + );
61 +
62 + $css = [];
63 +
64 + // Width type (uses responsive fallback)
65 + $width_type = Helper::get_responsive_value(
66 + $attribute_value,
67 + 'widthType',
68 + $device,
69 + self::get_attribute_default_value()
70 + );
71 +
72 + if ( ! empty( $width_type ) ) {
73 + if ( $width_type === 'full' ) {
74 + $css[ $property ] = '100%';
75 + } elseif ( $width_type === 'auto' ) {
76 + $css[ $property ] = 'auto';
77 + $css['display'] = 'inline-block';
78 + } elseif ( $width_type === 'custom' ) {
79 + // Get custom width with responsive fallback
80 + $custom_width = Helper::get_responsive_value(
81 + $attribute_value,
82 + 'customWidth',
83 + $device,
84 + self::get_attribute_default_value()
85 + );
86 +
87 + // Get responsive unit (delegates to your get_unit function)
88 + $unit = self::get_unit(
89 + [
90 + 'unit' => Helper::get_responsive_value( $attribute_value, 'customWidthUnit', 'Desktop' ),
91 + 'unitTablet' => Helper::get_responsive_value( $attribute_value, 'customWidthUnit', 'Tablet' ),
92 + 'unitMobile' => Helper::get_responsive_value( $attribute_value, 'customWidthUnit', 'Mobile' ),
93 + ],
94 + $device
95 + );
96 +
97 + $css[ $property ] = $custom_width . $unit;
98 + }//end if
99 + }//end if
100 +
101 + return $css;
102 + }
103 +
104 +}