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/width.php +98 -0 1.0.3 → 2.14.0 View file →
@@ -1,0 +1,98 @@
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 + // The device's own unit, else the nearest containing wider
88 + // device's (custom breakpoints included), else Desktop's.
89 + $unit = Helper::get_responsive_value( $attribute_value, 'customWidthUnit', $device );
90 +
91 + $css[ $property ] = $custom_width . $unit;
92 + }//end if
93 + }//end if
94 +
95 + return $css;
96 + }
97 +
98 +}