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 / blocks / menu / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/menu/block.php

380 lines 14.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\Menu;
3
4 use ABlocks\Controls\Typography;
5 use ABlocks\Controls\Dimensions;
6 use ABlocks\Controls\Border;
7 use ABlocks\Classes\BlockBaseAbstract;
8 use ABlocks\Classes\CssGenerator;
9 use ABlocks\Controls\Range;
10 use ABlocks\Controls\BoxShadow;
11
12 class Block extends BlockBaseAbstract {
13 protected $block_name = 'menu';
14
15 public function build_css( $attributes ) {
16 // Generate CSS
17 $css_generator = new CssGenerator( $attributes );
18 // Wrapper CSS
19 $css_generator->add_class_styles(
20 '{{WRAPPER}} .ablocks-menu',
21 $this->get_menu_css( $attributes, '' ),
22 $this->get_menu_css( $attributes, 'Tablet' ),
23 $this->get_menu_css( $attributes, 'Mobile' )
24 );
25 $css_generator->add_class_styles(
26 '{{WRAPPER}}.ablocks-menu',
27 $this->get_menu_css( $attributes, '' ),
28 $this->get_menu_css( $attributes, 'Tablet' ),
29 $this->get_menu_css( $attributes, 'Mobile' )
30 );
31 $css_generator->add_class_styles(
32 '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item',
33 $this->get_menu_item_css( $attributes ),
34 $this->get_menu_item_css( $attributes, 'Tablet' ),
35 $this->get_menu_item_css( $attributes, 'Mobile' )
36 );
37 $css_generator->add_class_styles(
38 '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item:hover',
39 $this->get_menu_item_hover_css( $attributes, '' ),
40 $this->get_menu_item_hover_css( $attributes, 'Tablet' ),
41 $this->get_menu_item_hover_css( $attributes, 'Mobile' )
42 );
43 $css_generator->add_class_styles(
44 '{{WRAPPER}} .ablocks-block--menu-child-sub',
45 $this->get_sub_menu_css( $attributes, '' ),
46 $this->get_sub_menu_css( $attributes, 'Tablet' ),
47 $this->get_sub_menu_css( $attributes, 'Mobile' ),
48 );
49 $css_generator->add_class_styles(
50 '{{WRAPPER}} .ablocks-block--menu-child-sub:hover',
51 $this->get_sub_menu_hover_css( $attributes, '' ),
52 $this->get_sub_menu_hover_css( $attributes, 'Tablet' ),
53 $this->get_sub_menu_hover_css( $attributes, 'Mobile' ),
54 );
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item',
57 $this->get_subMenu_responsive_css( $attributes, '' ),
58 $this->get_subMenu_responsive_css( $attributes, 'Tablet' ),
59 $this->get_subMenu_responsive_css( $attributes, 'Mobile' ),
60 );
61 $css_generator->add_class_styles(
62 '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item:hover',
63 $this->get_subMenu_responsive_hover_css( $attributes, '' ),
64 );
65 $css_generator->add_class_styles(
66 '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item .ablocks-menu-item__link',
67 $this->get_subMenu_responsive_text_css( $attributes, '' ),
68 $this->get_subMenu_responsive_text_css( $attributes, 'Tablet' ),
69 $this->get_subMenu_responsive_text_css( $attributes, 'Mobile' ),
70 );
71 $css_generator->add_class_styles(
72 '{{WRAPPER}} .ablocks-menu-child-mega',
73 $this->getMegaMenuCSS( $attributes ),
74 $this->getMegaMenuCSS( $attributes, 'Tablet' ),
75 $this->getMegaMenuCSS( $attributes, 'Mobile' )
76 );
77 $css_generator->add_class_styles(
78 '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item > .ablocks-menu-item__link',
79 $this->get_menu_item_link_css( $attributes, '' ),
80 $this->get_menu_item_link_css( $attributes, 'Tablet' ),
81 $this->get_menu_item_link_css( $attributes, 'Mobile' )
82 );
83 $css_generator->add_class_styles(
84 '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item:hover > .ablocks-menu-item__link ',
85 $this->get_menu_item_link_hover_css( $attributes, '' ),
86 );
87 $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item > .ablocks-menu-item__dropdown-icon svg',
88 $this->get_menu_item_dropdown_icon_css( $attributes ),
89 $this->get_menu_item_dropdown_icon_css( $attributes, 'Tablet' ),
90 $this->get_menu_item_dropdown_icon_css( $attributes, 'Mobile' )
91 );
92 $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item:hover > .ablocks-menu-item__dropdown-icon svg', $this->get_menu_item_dropdown_icon_hover_css( $attributes ) );
93 $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper', $this->get_hamburger_menu_wrapper_css( $attributes ) );
94 $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger ',
95 $this->get_hamburger_menu_css( $attributes ),
96 $this->get_hamburger_menu_css( $attributes, 'Tablet' ),
97 $this->get_hamburger_menu_css( $attributes, 'Mobile' ),
98 );
99 $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger:hover ',
100 $this->get_hamburgerHoverCSS( $attributes ),
101 $this->get_hamburgerHoverCSS( $attributes, 'Tablet' ),
102 $this->get_hamburgerHoverCSS( $attributes, 'Mobile' ),
103 );
104 $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger .ablocks-menu__trigger-item ', $this->get_hamburger_menu_item_css( $attributes ) );
105
106 return $css_generator->generate_css();
107 }
108
109 private function get_menu_css( $attributes, $device = '' ) {
110 $css = [];
111 $padding = isset( $attributes['padding'] ) ? $attributes['padding'] : '';
112
113 if ( ! empty( $attributes['alignment'] ) ) {
114 $css['justify-content'] = $attributes['alignment'];
115 }
116 return array_merge(
117 Dimensions::get_css( $padding, 'padding', $device ),
118 $css
119 );
120 }
121
122
123
124
125 private function get_menu_item_css( $attributes, $device = '' ) {
126 $menu_border_css = ! empty( $attributes['menuItemBorder'] ) ? Border::get_css( $attributes['menuItemBorder'], '', $device ) : array();
127 $css = array_merge(
128 $menu_border_css,
129 Typography::get_css( isset( $attributes['menuItemTypography'] ) ? $attributes['menuItemTypography'] : [], '', $device ),
130 Dimensions::get_css( isset( $attributes['menuItemPadding'] ) ? $attributes['menuItemPadding'] : [], 'padding', $device ),
131 Dimensions::get_css( isset( $attributes['menuItemMargin'] ) ? $attributes['menuItemMargin'] : [], 'margin', $device )
132 );
133
134 if ( isset( $attributes[ 'menuItemDirection' . $device ] ) && ! empty( $attributes[ 'menuItemDirection' . $device ] ) ) {
135 $css['flex-direction'] = $attributes[ 'menuItemDirection' . $device ];
136 }
137
138 // Justify content
139 if ( isset( $attributes[ 'menuItemJustify' . $device ] ) && ! empty( $attributes[ 'menuItemJustify' . $device ] ) ) {
140 $css['justify-content'] = $attributes[ 'menuItemJustify' . $device ];
141 }
142
143 // Align items
144 if ( isset( $attributes[ 'menuItemAlign' . $device ] ) && ! empty( $attributes[ 'menuItemAlign' . $device ] ) ) {
145 $css['align-items'] = $attributes[ 'menuItemAlign' . $device ];
146 }
147 // Text color
148 if ( ! empty( $attributes['menuItemTextColor'] ) ) {
149 $css['color'] = $attributes['menuItemTextColor'];
150 }
151 if ( ! empty( $attributes['menuItemBackground'] ) ) {
152 $css['background'] = $attributes['menuItemBackground'];
153 }
154 if ( ! empty( $attributes['menuItemTransition'] ) ) {
155 $css['transition'] = $attributes['menuItemTransition'] . 's';
156 }
157 if (
158 ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) ||
159 ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' )
160 ) {
161 $background_color = isset( $attributes['menuResponsiveBackground'] ) ? $attributes['menuResponsiveBackground'] : '';
162 if ( ! empty( $background_color ) ) {
163 $css['background'] = $background_color;
164 }
165 }
166 return $css;
167 }
168 private function get_menu_item_link_css( $attributes, $device = '' ) {
169 $css = [];
170 if ( ! empty( $attributes['menuItemTextColor'] ) ) {
171 $css['color'] = $attributes['menuItemTextColor'];
172 }
173 if (
174 ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) ||
175 ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' )
176 ) {
177 $text_color = isset( $attributes['menuResponsiveTextColor'] ) ? $attributes['menuResponsiveTextColor'] : '';
178 if ( ! empty( $text_color ) ) {
179 $css['color'] = $text_color . ' !important';
180 }
181 }
182 return $css;
183 }
184
185 private function get_menu_item_hover_css( $attributes, $device = '' ) {
186 $css = array_merge(
187 Border::get_hover_css( isset( $attributes['menuItemBorder'] ) ? $attributes['menuItemBorder'] : [], $device )
188 );
189
190 // Text color on hover
191 if ( ! empty( $attributes['menuItemTextColorH'] ) ) {
192 $css['color'] = $attributes['menuItemTextColorH'];
193 }
194 if ( ! empty( $attributes['menuItemBackgroundH'] ) ) {
195 $css['background'] = $attributes['menuItemBackgroundH'];
196 }
197 return $css;
198 }
199 private function get_menu_item_link_hover_css( $attributes ) {
200 $css = [];
201 if ( ! empty( $attributes['menuItemTextColorH'] ) ) {
202 $css['color'] = $attributes['menuItemTextColorH'];
203 }
204
205 return $css;
206 }
207 private function get_sub_menu_css( $attributes, $device = '' ) {
208 $css = [];
209 if ( isset( $attributes['menuItemBorder']['commonWidth'] ) ) {
210 $css['margin-top'] = $attributes['menuItemBorder']['commonWidth'] . 'px';
211 }
212 if ( isset( $attributes['menuItemBorder']['bottomWidth'] ) ) {
213 $css['margin-top'] = $attributes['menuItemBorder']['bottomWidth'] . 'px';
214 }
215 return array_merge(
216 $css,
217 Range::get_css([
218 'attributeValue' => $attributes['subMenuWidth'],
219 'attribute_object_key' => 'value',
220 'isResponsive' => true,
221 'defaultValue' => 250,
222 'hasUnit' => true,
223 'unitDefaultValue' => 'px',
224 'property' => 'width',
225 'device' => $device,
226 ]),
227 BoxShadow::get_css( ! empty( $attributes['subMenuBoxShadow'] ) ? $attributes['subMenuBoxShadow'] : '', $device ),
228 Dimensions::get_css( $attributes['subMenuPadding'], 'padding', $device ),
229 Border::get_css( $attributes['subMenuBorder'], '', $device ),
230 );
231 }
232 private function get_sub_menu_hover_css( $attributes, $device = '' ) {
233 return array_merge(
234 Border::get_hover_css( $attributes['subMenuBorder'], '', $device ),
235 BoxShadow::get_hover_css( $attributes['subMenuBoxShadow'], '', $device )
236 );
237 }
238 private function get_subMenu_responsive_css( $attributes, $device = '' ) {
239 $css = [];
240 if ( ! empty( $attributes['subMenuItemBackground'] ) ) {
241 $css['background'] = $attributes['subMenuItemBackground'];
242 }
243 if ( ! empty( $attributes['subMenuItemTransition'] ) ) {
244 $css['transition-duration'] = $attributes['subMenuItemTransition'] . 's';
245 }
246 if (
247 ( isset( $attributes['sideBarMenuDevice'] ) && $attributes['sideBarMenuDevice'] === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) ) ||
248 ( isset( $attributes['sideBarMenuDevice'] ) && $attributes['sideBarMenuDevice'] !== 'tablet' && $device === 'Mobile' )
249 ) {
250 $background_color = $attributes['subMenuResponsiveBg'] ?? '';
251 if ( ! empty( $background_color ) ) {
252 $css['background'] = $background_color . '!important';
253 }
254 }
255 return $css;
256 }
257
258 private function get_subMenu_responsive_hover_css( $attributes ) {
259 $css = [];
260 if ( ! empty( $attributes['subMenuItemTextColorH'] ) ) {
261 $css['color'] = $attributes['subMenuItemTextColorH'];
262 }
263 if ( ! empty( $attributes['subMenuItemBackgroundH'] ) ) {
264 $css['background'] = $attributes['subMenuItemBackgroundH'];
265 }
266
267 return $css;
268 }
269 private function get_subMenu_responsive_text_css( $attributes, $device = '' ) {
270 $css = [];
271 if ( ! empty( $attributes['subMenuItemTextColor'] ) ) {
272 $css['color'] = $attributes['subMenuItemTextColor'];
273 }
274 if (
275 ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) ||
276 ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' )
277 ) {
278 $text_color = isset( $attributes['subMenuResponsiveColor'] ) ? $attributes['subMenuResponsiveColor'] : '';
279 if ( ! empty( $text_color ) ) {
280 $css['color'] = $text_color . ' !important';
281 }
282 }
283
284 return $css;
285 }
286 private function getMegaMenuCSS( $attributes, $device = '' ) {
287 $css = [];
288 if ( isset( $attributes['sideBarMenuDevice'] ) && $attributes['sideBarMenuDevice'] === 'tablet' && $device === 'Tablet' ) {
289 $css['position'] = 'static !important';
290 }
291
292 return $css;
293 }
294
295
296 private function get_menu_item_dropdown_icon_css( $attributes, $device = '' ) {
297 $css = [];
298 if ( ! empty( $attributes['menuItemTextColor'] ) ) {
299 $css['fill'] = $attributes['menuItemTextColor'];
300 }
301 if (
302 ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) ||
303 ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' )
304 ) {
305 $text_color = isset( $attributes['menuResponsiveTextColor'] ) ? $attributes['menuResponsiveTextColor'] : '';
306 if ( ! empty( $text_color ) ) {
307 $css['fill'] = $text_color . ' !important';
308 }
309 }
310 return $css;
311 }
312 private function get_menu_item_dropdown_icon_hover_css( $attributes ) {
313 $css = [];
314 if ( ! empty( $attributes['menuItemTextColorH'] ) ) {
315 $css['fill'] = $attributes['menuItemTextColorH'];
316 }
317 return $css;
318 }
319 private function get_hamburger_menu_wrapper_css( $attributes ) {
320 $css = [];
321 if ( isset( $attributes['hamburgerAlignment'] ) ) {
322 $css['justify-content'] = $attributes['hamburgerAlignment'];
323 }
324 return $css;
325 }
326 public function get_hamburger_menu_css( $attributes, $device = '' ) {
327 $hamburger_border_css = ! empty( $attributes['hamburgerBorder'] ) ? Border::get_css( $attributes['hamburgerBorder'], '', $device ) : array();
328 $css = array_merge(
329 $hamburger_border_css,
330 Dimensions::get_css( isset( $attributes['hamburgerPadding'] ) ? $attributes['hamburgerPadding'] : [], 'padding', $device )
331 );
332
333 if ( isset( $attributes['hamburgerBackground'] ) ) {
334 $css['background'] = $attributes['hamburgerBackground'];
335 }
336 $height_humber = 30 + ( isset( $attributes['hamburgerHeight.value'] ) ? $attributes['hamburgerHeight.value'] : 0 );
337 if ( $height_humber ) {
338 $css['height'] = "{$height_humber}px";
339 }
340
341 return $css;
342 }
343 public function get_hamburgerHoverCSS( $attributes, $device = '' ) {
344 $css = Border::get_hover_css( isset( $attributes['hamburgerBorder'] ) ? $attributes['hamburgerBorder'] : [], $device );
345 return $css;
346 }
347
348
349 public function get_hamburger_menu_item_css( $attributes, $device = '' ) {
350 $css = [];
351 if ( isset( $attributes['hamburgerColor'] ) ) {
352 $css['background'] = $attributes['hamburgerColor'];
353 }
354
355 return array_merge(
356 $css,
357 Range::get_css([
358 'attributeValue' => $attributes['hamburgerHeight'],
359 'attribute_object_key' => 'value',
360 'isResponsive' => false,
361 'defaultValue' => 3,
362 'hasUnit' => true,
363 'unitDefaultValue' => 'px',
364 'property' => 'height',
365 'device' => $device,
366 ]),
367 Range::get_css([
368 'attributeValue' => $attributes['hamburgerWidth'],
369 'attribute_object_key' => 'value',
370 'isResponsive' => false,
371 'defaultValue' => 30,
372 'hasUnit' => true,
373 'unitDefaultValue' => 'px',
374 'property' => 'width',
375 'device' => $device,
376 ])
377 );
378 }
379 }
380