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 / range.php

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

129 lines 3.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\ControlBaseAbstractTwo;
9
10 class Range extends ControlBaseAbstractTwo {
11
12 public static function get_attribute_default_value( $args ) {
13
14 $unitObject = $args['hasUnit'] ? [
15 $args['attributeObjectKey'] . 'Unit' => $args['unitDefaultValue'],
16 $args['attributeObjectKey'] . 'UnitTablet' => '',
17 $args['attributeObjectKey'] . 'UnitMobile' => '',
18 ] : [];
19
20 if ( $args['isResponsive'] ) {
21 return array_merge([
22 $args['attributeObjectKey'] => $args['defaultValue'],
23 $args['attributeObjectKey'] . 'Tablet' => $args['defaultValueTablet'],
24 $args['attributeObjectKey'] . 'Mobile' => $args['defaultValueMobile']
25 ], $unitObject);
26 } elseif ( ! $args['isResponsive'] && $args['hasUnit'] ) {
27 return array_merge([
28 $args['attributeObjectKey'] => $args['defaultValue'],
29 $args['attributeObjectKey'] . 'Unit' => $args['unitDefaultValue']
30 ], $unitObject);
31 }
32
33 return $args['defaultValue'];
34 }
35
36 public static function get_attribute( $args ) {
37 $defaults = [
38 'attributeName' => '',
39 'isResponsive' => false,
40 'defaultValue' => '',
41 'defaultValueTablet' => '',
42 'defaultValueMobile' => '',
43 'hasUnit' => false,
44 'unitDefaultValue' => 'px',
45 'attributeObjectKey' => 'value',
46 ];
47
48 $args = wp_parse_args( $args, $defaults );
49
50 if ( $args['isResponsive'] ) {
51 return [
52 $args['attributeName'] => [
53 'type' => 'object',
54 'default' => self::get_attribute_default_value( $args )
55 ]
56 ];
57 } elseif ( ! $args['isResponsive'] && $args['hasUnit'] ) {
58 return [
59 $args['attributeName'] => [
60 'type' => 'object',
61 'default' => self::get_attribute_default_value( $args )
62 ]
63 ];
64 }
65
66 return [
67 $args['attributeName'] => [
68 'type' => 'number',
69 'default' => $args['defaultValue']
70 ]
71 ];
72 }
73
74 public static function get_css( $args ) {
75 if ( ! isset( $args['property'] ) ||
76 empty( $args['property'] )
77 ) {
78 return [];
79 }
80
81 // Set default values for missing arguments
82 $args = wp_parse_args( $args, [
83 'attributeValue' => '',
84 'isResponsive' => false,
85 'defaultValue' => '',
86 'defaultValueTablet' => '',
87 'defaultValueMobile' => '',
88 'hasUnit' => false,
89 'unitDefaultValue' => 'px',
90 'attributeObjectKey' => 'value',
91 'device' => '',
92 ]);
93
94 $value = $args['attributeValue'];
95 $css = [];
96
97 if ( ! $args['isResponsive'] && ! $args['hasUnit'] ) {
98 if ( $args['property'] === 'value' ) {
99 $css['value'] = $value;
100 $css['valueUnit'] = $args['unitDefaultValue'];
101 } else {
102 $css[ $args['property'] ] = $value . $args['unitDefaultValue'];
103 }
104 return $css;
105 }
106
107 // Check and generate CSS for the specified device
108 $deviceValueKey = $args['attributeObjectKey'] . $args['device'];
109 if ( ! empty( $value[ $deviceValueKey ] ) ) {
110 $unit = self::get_unit( [
111 'attributeValue' => $value,
112 'attributeObjectKey' => $args['attributeObjectKey'],
113 'unitDefaultValue' => $args['unitDefaultValue'],
114 'device' => $args['device'],
115 ] );
116
117 if ( $args['property'] === 'value' ) {
118 $css['value'] = $value[ $deviceValueKey ];
119 $css['valueUnit'] = $unit;
120 } else {
121 $css[ $args['property'] ] = $value[ $deviceValueKey ] . $unit;
122 }
123 }
124
125 return $css;
126 }
127
128 }
129