PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.2
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.2
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / controls / group / button-background.php

button-background.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.2, at inc/controls/group/button-background.php

311 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Controls\Group;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Base;
7
8
9 if (!defined('ABSPATH')) {
10 exit; // Exit if accessed directly.
11 }
12
13
14 /**
15 * Addon button background control.
16 *
17 * A base controls group for creating button background controls.
18 * Displays fields to define the background color or gradient.
19 */
20 class JLTMA_Button_Background extends Group_Control_Base
21 {
22
23 const JLTMA_BTN_BG_GROUP = 'jltma-button-background';
24
25 /**
26 * Holds all the group control fields.
27 */
28 protected static $fields;
29
30 /**
31 * Holds all the available background types.
32 * @var array
33 */
34 private static $background_types;
35
36 /**
37 * Get background control type.
38 * Retrieve the control type, in this case `background`.
39 * @return string Control type.
40 */
41 public static function get_type()
42 {
43 return self::JLTMA_BTN_BG_GROUP;
44 }
45
46 /**
47 * Retrieve available background types.
48 * @return array Available background types.
49 */
50 public static function get_background_types()
51 {
52 if (null === self::$background_types) {
53 self::$background_types = self::get_default_background_types();
54 }
55
56 return self::$background_types;
57 }
58
59 /**
60 * Get Default background types.
61 * Retrieve button background control initial types.
62 * @return array Default background types.
63 */
64 private static function get_default_background_types()
65 {
66 return array(
67 'color' => array(
68 'title' => _x('Color', 'Button Background Control', 'master-addons' ),
69 'icon' => 'eicon-paint-brush',
70 ),
71 'gradient' => array(
72 'title' => _x('Gradient', 'Button Background Control', 'master-addons' ),
73 'icon' => 'eicon-barcode',
74 ),
75 );
76 }
77
78 /**
79 * Init fields.
80 * Initialize control group fields.
81 * @return array Control fields.
82 */
83 public function init_fields()
84 {
85 $fields = array();
86
87 $fields['background'] = array(
88 'label' => _x('Background Type', 'Button Background Control', 'master-addons' ),
89 'type' => Controls_Manager::CHOOSE,
90 'toggle' => false,
91 'render_type' => 'ui',
92 );
93
94 $fields['color'] = array(
95 'label' => _x('Background Color', 'Button Background Control', 'master-addons' ),
96 'type' => Controls_Manager::COLOR,
97 'default' => '',
98 'selectors' => array(
99 '{{SELECTOR}}' => '--button-bg-color: {{VALUE}}; ' .
100 'background: var( --button-bg-color );',
101 ),
102 'condition' => array(
103 'background' => array(
104 'color',
105 'gradient',
106 ),
107 ),
108 );
109
110 $fields['color_stop'] = array(
111 'label' => _x('Location', 'Button Background Control', 'master-addons' ),
112 'type' => Controls_Manager::SLIDER,
113 'size_units' => array('%'),
114 'default' => array(
115 'unit' => '%',
116 'size' => 0,
117 ),
118 'render_type' => 'ui',
119 'condition' => array(
120 'background' => array('gradient'),
121 ),
122 'of_type' => 'gradient',
123 );
124
125 $fields['color_b'] = array(
126 'label' => _x('Second Background Color', 'Button Background Control', 'master-addons' ),
127 'type' => Controls_Manager::COLOR,
128 'default' => '#f2295b',
129 'render_type' => 'ui',
130 'condition' => array(
131 'background' => array('gradient'),
132 ),
133 'of_type' => 'gradient',
134 );
135
136 $fields['color_b_stop'] = array(
137 'label' => _x('Location', 'Button Background Control', 'master-addons' ),
138 'type' => Controls_Manager::SLIDER,
139 'size_units' => array('%'),
140 'default' => array(
141 'unit' => '%',
142 'size' => 100,
143 ),
144 'render_type' => 'ui',
145 'condition' => array(
146 'background' => array('gradient'),
147 ),
148 'of_type' => 'gradient',
149 );
150
151 $fields['gradient_type'] = array(
152 'label' => _x('Type', 'Button Background Control', 'master-addons' ),
153 'label_block' => false,
154 'type' => 'jltma-choose-text',
155 'options' => array(
156 'linear' => _x('Linear', 'Button Background Control', 'master-addons' ),
157 'radial' => _x('Radial', 'Button Background Control', 'master-addons' ),
158 ),
159 'default' => 'linear',
160 'render_type' => 'ui',
161 'condition' => array(
162 'background' => array('gradient'),
163 ),
164 'of_type' => 'gradient',
165 );
166
167 $fields['gradient_angle'] = array(
168 'label' => _x('Angle', 'Button Background Control', 'master-addons' ),
169 'type' => Controls_Manager::SLIDER,
170 'size_units' => array('deg'),
171 'default' => array(
172 'unit' => 'deg',
173 'size' => 180,
174 ),
175 'range' => array(
176 'deg' => array('step' => 10),
177 ),
178 'selectors' => array(
179 '{{SELECTOR}}' => 'background-color: transparent; ' .
180 'background-image: linear-gradient({{SIZE}}{{UNIT}}, var( --button-bg-color ) {{color_stop.SIZE}}{{color_stop.UNIT}}, {{color_b.VALUE}} {{color_b_stop.SIZE}}{{color_b_stop.UNIT}})',
181 ),
182 'condition' => array(
183 'background' => array('gradient'),
184 'gradient_type' => 'linear',
185 ),
186 'separator' => 'after',
187 'of_type' => 'gradient',
188 );
189
190 $fields['gradient_position'] = array(
191 'label' => _x('Position', 'Button Background Control', 'master-addons' ),
192 'type' => Controls_Manager::SELECT,
193 'options' => array(
194 'center center' => _x('Center Center', 'Button Background Control', 'master-addons' ),
195 'center left' => _x('Center Left', 'Button Background Control', 'master-addons' ),
196 'center right' => _x('Center Right', 'Button Background Control', 'master-addons' ),
197 'top center' => _x('Top Center', 'Button Background Control', 'master-addons' ),
198 'top left' => _x('Top Left', 'Button Background Control', 'master-addons' ),
199 'top right' => _x('Top Right', 'Button Background Control', 'master-addons' ),
200 'bottom center' => _x('Bottom Center', 'Button Background Control', 'master-addons' ),
201 'bottom left' => _x('Bottom Left', 'Button Background Control', 'master-addons' ),
202 'bottom right' => _x('Bottom Right', 'Button Background Control', 'master-addons' ),
203 ),
204 'default' => 'center center',
205 'selectors' => array(
206 '{{SELECTOR}}' => 'background-color: transparent; ' .
207 'background-image: radial-gradient(at {{VALUE}}, var( --button-bg-color ) {{color_stop.SIZE}}{{color_stop.UNIT}}, {{color_b.VALUE}} {{color_b_stop.SIZE}}{{color_b_stop.UNIT}})',
208 ),
209 'condition' => array(
210 'background' => array('gradient'),
211 'gradient_type' => 'radial',
212 ),
213 'separator' => 'after',
214 'of_type' => 'gradient',
215 );
216
217 return $fields;
218 }
219
220 /**
221 * Get child default args.
222 *
223 * Retrieve the default arguments for all the child controls for a
224 * specific group control.
225 *
226 * @since 1.1.0
227 *
228 * @return array Default arguments for all the child controls.
229 */
230 protected function get_child_default_args()
231 {
232 return array(
233 'types' => array(
234 'color',
235 'gradient',
236 ),
237 'selector' => '{{WRAPPER}}',
238 );
239 }
240
241 /**
242 * Filter fields.
243 *
244 * Filter which controls to display, using `include`, `exclude`,
245 * `condition` and `of_type` arguments.
246 *
247 * @since 1.1.0
248 *
249 * @return array Control fields.
250 */
251 protected function filter_fields()
252 {
253 $fields = parent::filter_fields();
254
255 $args = $this->get_args();
256
257 foreach ($fields as &$field) {
258 if (
259 isset($field['of_type']) &&
260 !in_array($field['of_type'], $args['types'], true)
261 ) {
262 unset($field);
263 }
264 }
265
266 return $fields;
267 }
268
269 /**
270 * Prepare fields.
271 * Process button background control fields before adding them to `add_control()`.
272 * @param array $fields Control group fields.
273 *
274 * @return array Processed fields.
275 */
276 protected function prepare_fields($fields)
277 {
278 $args = $this->get_args();
279
280 $background_types = self::get_background_types();
281
282 $choose_types = array();
283
284 foreach ($args['types'] as $type) {
285 if (isset($background_types[$type])) {
286 $choose_types[$type] = $background_types[$type];
287 }
288 }
289
290 $fields['background']['options'] = $choose_types;
291 $fields['background']['default'] = key($choose_types);
292
293 return parent::prepare_fields($fields);
294 }
295
296 /**
297 * Get default options.
298 *
299 * Retrieve the default options of the button background control.
300 * Used to return the default options while initializing the button background control.
301 *
302 * @since 1.1.0
303 *
304 * @return array Default background control options.
305 */
306 protected function get_default_options()
307 {
308 return array('popover' => false);
309 }
310 }
311