| @@ -1,0 +1,576 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\Menu; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Controls\Typography; | |
| 9 | +use ABlocks\Controls\Dimensions; | |
| 10 | +use ABlocks\Controls\Border; | |
| 11 | +use ABlocks\Classes\BlockBaseAbstract; | |
| 12 | +use ABlocks\Classes\CssGenerator; | |
| 13 | +use ABlocks\Controls\Range; | |
| 14 | +use ABlocks\Controls\BoxShadow; | |
| 15 | +use ABlocks\Classes\CssGeneratorV2; | |
| 16 | +use ABlocks\Controls\Color; | |
| 17 | +use ABlocks\Controls\Alignment; | |
| 18 | + | |
| 19 | +class Block extends BlockBaseAbstract { | |
| 20 | + protected $block_name = 'menu'; | |
| 21 | + | |
| 22 | + public function build_css_v1( $attributes ) { | |
| 23 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 24 | + $css_generator->add_class_styles( | |
| 25 | + '{{WRAPPER}} .ablocks-menu', | |
| 26 | + $this->get_menu_css( $attributes, '' ), | |
| 27 | + $this->get_menu_css( $attributes, 'Tablet' ), | |
| 28 | + $this->get_menu_css( $attributes, 'Mobile' ), | |
| 29 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_css( $attributes, $device ); } ) | |
| 30 | + ); | |
| 31 | + $css_generator->add_class_styles( | |
| 32 | + '{{WRAPPER}}.ablocks-menu', | |
| 33 | + $this->get_menu_css( $attributes, '' ), | |
| 34 | + $this->get_menu_css( $attributes, 'Tablet' ), | |
| 35 | + $this->get_menu_css( $attributes, 'Mobile' ), | |
| 36 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_css( $attributes, $device ); } ) | |
| 37 | + ); | |
| 38 | + $css_generator->add_class_styles( | |
| 39 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item', | |
| 40 | + $this->get_menu_item_css( $attributes ), | |
| 41 | + $this->get_menu_item_css( $attributes, 'Tablet' ), | |
| 42 | + $this->get_menu_item_css( $attributes, 'Mobile' ), | |
| 43 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_css( $attributes, $device ); } ) | |
| 44 | + ); | |
| 45 | + $css_generator->add_class_styles( | |
| 46 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item .ablocks-menu-item__link', | |
| 47 | + $this->get_menu_item_css( $attributes ), | |
| 48 | + $this->get_menu_item_css( $attributes, 'Tablet' ), | |
| 49 | + $this->get_menu_item_css( $attributes, 'Mobile' ), | |
| 50 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_css( $attributes, $device ); } ) | |
| 51 | + ); | |
| 52 | + $css_generator->add_class_styles( | |
| 53 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item:hover', | |
| 54 | + $this->get_menu_item_hover_css( $attributes, '' ), | |
| 55 | + $this->get_menu_item_hover_css( $attributes, 'Tablet' ), | |
| 56 | + $this->get_menu_item_hover_css( $attributes, 'Mobile' ), | |
| 57 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_hover_css( $attributes, $device ); } ) | |
| 58 | + ); | |
| 59 | + $css_generator->add_class_styles( | |
| 60 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item > .ablocks-menu-item__link:hover', | |
| 61 | + $this->get_menu_item_hover_css( $attributes, '' ), | |
| 62 | + $this->get_menu_item_hover_css( $attributes, 'Tablet' ), | |
| 63 | + $this->get_menu_item_hover_css( $attributes, 'Mobile' ), | |
| 64 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_hover_css( $attributes, $device ); } ) | |
| 65 | + ); | |
| 66 | + $css_generator->add_class_styles( | |
| 67 | + '{{WRAPPER}} .ablocks-block--menu-child-sub', | |
| 68 | + $this->get_sub_menu_css( $attributes, '' ), | |
| 69 | + $this->get_sub_menu_css( $attributes, 'Tablet' ), | |
| 70 | + $this->get_sub_menu_css( $attributes, 'Mobile' ), | |
| 71 | + ); | |
| 72 | + $css_generator->add_class_styles( | |
| 73 | + '{{WRAPPER}} .ablocks-block--menu-child-sub:hover', | |
| 74 | + $this->get_sub_menu_hover_css( $attributes, '' ), | |
| 75 | + $this->get_sub_menu_hover_css( $attributes, 'Tablet' ), | |
| 76 | + $this->get_sub_menu_hover_css( $attributes, 'Mobile' ), | |
| 77 | + ); | |
| 78 | + $css_generator->add_class_styles( | |
| 79 | + '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item', | |
| 80 | + $this->get_subMenu_responsive_css( $attributes, '' ), | |
| 81 | + $this->get_subMenu_responsive_css( $attributes, 'Tablet' ), | |
| 82 | + $this->get_subMenu_responsive_css( $attributes, 'Mobile' ), | |
| 83 | + ); | |
| 84 | + $css_generator->add_class_styles( | |
| 85 | + '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item:hover', | |
| 86 | + $this->get_subMenu_responsive_hover_css( $attributes, '' ), | |
| 87 | + ); | |
| 88 | + $css_generator->add_class_styles( | |
| 89 | + '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item .ablocks-menu-item__link', | |
| 90 | + $this->get_subMenu_responsive_text_css( $attributes, '' ), | |
| 91 | + $this->get_subMenu_responsive_text_css( $attributes, 'Tablet' ), | |
| 92 | + $this->get_subMenu_responsive_text_css( $attributes, 'Mobile' ), | |
| 93 | + ); | |
| 94 | + $css_generator->add_class_styles( | |
| 95 | + '{{WRAPPER}} .ablocks-menu-child-mega', | |
| 96 | + $this->getMegaMenuCSS( $attributes ), | |
| 97 | + $this->getMegaMenuCSS( $attributes, 'Tablet' ), | |
| 98 | + $this->getMegaMenuCSS( $attributes, 'Mobile' ), | |
| 99 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getMegaMenuCSS( $attributes, $device ); } ) | |
| 100 | + ); | |
| 101 | + $css_generator->add_class_styles( | |
| 102 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item > .ablocks-menu-item__link', | |
| 103 | + $this->get_menu_item_link_css( $attributes, '' ), | |
| 104 | + $this->get_menu_item_link_css( $attributes, 'Tablet' ), | |
| 105 | + $this->get_menu_item_link_css( $attributes, 'Mobile' ), | |
| 106 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_link_css( $attributes, $device ); } ) | |
| 107 | + ); | |
| 108 | + $css_generator->add_class_styles( | |
| 109 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item:hover > .ablocks-menu-item__link ', | |
| 110 | + $this->get_menu_item_link_hover_css( $attributes, '' ), | |
| 111 | + ); | |
| 112 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item > .ablocks-menu-item__dropdown-icon svg', | |
| 113 | + $this->get_menu_item_dropdown_icon_css( $attributes ), | |
| 114 | + $this->get_menu_item_dropdown_icon_css( $attributes, 'Tablet' ), | |
| 115 | + $this->get_menu_item_dropdown_icon_css( $attributes, 'Mobile' ), | |
| 116 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_dropdown_icon_css( $attributes, $device ); } ) | |
| 117 | + ); | |
| 118 | + $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 ) ); | |
| 119 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper', $this->get_hamburger_menu_wrapper_css( $attributes ) ); | |
| 120 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger ', | |
| 121 | + $this->get_hamburger_menu_css( $attributes ), | |
| 122 | + $this->get_hamburger_menu_css( $attributes, 'Tablet' ), | |
| 123 | + $this->get_hamburger_menu_css( $attributes, 'Mobile' ), | |
| 124 | + ); | |
| 125 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger:hover ', | |
| 126 | + $this->get_hamburgerHoverCSS( $attributes ), | |
| 127 | + $this->get_hamburgerHoverCSS( $attributes, 'Tablet' ), | |
| 128 | + $this->get_hamburgerHoverCSS( $attributes, 'Mobile' ), | |
| 129 | + ); | |
| 130 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger .ablocks-menu__trigger-item ', $this->get_hamburger_menu_item_css( $attributes ) ); | |
| 131 | + | |
| 132 | + return $css_generator->generate_css(); | |
| 133 | + } | |
| 134 | + public function build_css_v2( $attributes ) { | |
| 135 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 136 | + // Wrapper CSS | |
| 137 | + $css_generator->add_class_styles( | |
| 138 | + '{{WRAPPER}} .ablocks-menu', | |
| 139 | + $this->get_menu_css( $attributes, '' ), | |
| 140 | + $this->get_menu_css( $attributes, 'Tablet' ), | |
| 141 | + $this->get_menu_css( $attributes, 'Mobile' ), | |
| 142 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_css( $attributes, $device ); } ) | |
| 143 | + ); | |
| 144 | + $css_generator->add_class_styles( | |
| 145 | + '{{WRAPPER}}.ablocks-menu', | |
| 146 | + $this->get_menu_css( $attributes, '' ), | |
| 147 | + $this->get_menu_css( $attributes, 'Tablet' ), | |
| 148 | + $this->get_menu_css( $attributes, 'Mobile' ), | |
| 149 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_css( $attributes, $device ); } ) | |
| 150 | + ); | |
| 151 | + $css_generator->add_class_styles( | |
| 152 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item', | |
| 153 | + $this->get_menu_item_css( $attributes ), | |
| 154 | + $this->get_menu_item_css( $attributes, 'Tablet' ), | |
| 155 | + $this->get_menu_item_css( $attributes, 'Mobile' ), | |
| 156 | + $this->get_menu_tablet_hamburger_css( $attributes, $this->get_menu_responsive_background_only_css( $attributes ) ), | |
| 157 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_css( $attributes, $device ); } ) | |
| 158 | + ); | |
| 159 | + $css_generator->add_class_styles( | |
| 160 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item .ablocks-menu-item__link', | |
| 161 | + $this->get_menu_item_css( $attributes ), | |
| 162 | + $this->get_menu_item_css( $attributes, 'Tablet' ), | |
| 163 | + $this->get_menu_item_css( $attributes, 'Mobile' ), | |
| 164 | + $this->get_menu_tablet_hamburger_css( $attributes, $this->get_menu_responsive_background_only_css( $attributes ) ), | |
| 165 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_css( $attributes, $device ); } ) | |
| 166 | + ); | |
| 167 | + $css_generator->add_class_styles( | |
| 168 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item:hover', | |
| 169 | + $this->get_menu_item_hover_css( $attributes, '' ), | |
| 170 | + $this->get_menu_item_hover_css( $attributes, 'Tablet' ), | |
| 171 | + $this->get_menu_item_hover_css( $attributes, 'Mobile' ), | |
| 172 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_hover_css( $attributes, $device ); } ) | |
| 173 | + ); | |
| 174 | + $css_generator->add_class_styles( | |
| 175 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item .ablocks-menu-item__link:hover', | |
| 176 | + $this->get_menu_item_hover_css( $attributes, '' ), | |
| 177 | + $this->get_menu_item_hover_css( $attributes, 'Tablet' ), | |
| 178 | + $this->get_menu_item_hover_css( $attributes, 'Mobile' ), | |
| 179 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_hover_css( $attributes, $device ); } ) | |
| 180 | + ); | |
| 181 | + $css_generator->add_class_styles( | |
| 182 | + '{{WRAPPER}} .ablocks-block--menu-child-sub', | |
| 183 | + $this->get_sub_menu_css( $attributes, '' ), | |
| 184 | + $this->get_sub_menu_css( $attributes, 'Tablet' ), | |
| 185 | + $this->get_sub_menu_css( $attributes, 'Mobile' ), | |
| 186 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_sub_menu_css( $attributes, $device ); } ) | |
| 187 | + ); | |
| 188 | + $css_generator->add_class_styles( | |
| 189 | + '{{WRAPPER}} .ablocks-block--menu-child-sub:hover', | |
| 190 | + $this->get_sub_menu_hover_css( $attributes, '' ), | |
| 191 | + $this->get_sub_menu_hover_css( $attributes, 'Tablet' ), | |
| 192 | + $this->get_sub_menu_hover_css( $attributes, 'Mobile' ), | |
| 193 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_sub_menu_hover_css( $attributes, $device ); } ) | |
| 194 | + ); | |
| 195 | + $css_generator->add_class_styles( | |
| 196 | + '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item', | |
| 197 | + $this->get_subMenu_responsive_css( $attributes, '' ), | |
| 198 | + $this->get_subMenu_responsive_css( $attributes, 'Tablet' ), | |
| 199 | + $this->get_subMenu_responsive_css( $attributes, 'Mobile' ), | |
| 200 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_subMenu_responsive_css( $attributes, $device ); } ) | |
| 201 | + ); | |
| 202 | + $css_generator->add_class_styles( | |
| 203 | + '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item:hover', | |
| 204 | + $this->get_subMenu_responsive_hover_css( $attributes, '' ), | |
| 205 | + ); | |
| 206 | + $css_generator->add_class_styles( | |
| 207 | + '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-block--menu-item .ablocks-menu-item__link', | |
| 208 | + $this->get_subMenu_responsive_text_css( $attributes, '' ), | |
| 209 | + $this->get_subMenu_responsive_text_css( $attributes, 'Tablet' ), | |
| 210 | + $this->get_subMenu_responsive_text_css( $attributes, 'Mobile' ), | |
| 211 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_subMenu_responsive_text_css( $attributes, $device ); } ) | |
| 212 | + ); | |
| 213 | + $css_generator->add_class_styles( | |
| 214 | + '{{WRAPPER}} .ablocks-block--menu-child-sub .ablocks-menu-item:hover .ablocks-menu-item__link', | |
| 215 | + $this->get_subMenu__text_hover_css( $attributes ) | |
| 216 | + ); | |
| 217 | + $css_generator->add_class_styles( | |
| 218 | + '{{WRAPPER}} .ablocks-menu-child-mega', | |
| 219 | + $this->getMegaMenuCSS( $attributes ), | |
| 220 | + $this->getMegaMenuCSS( $attributes, 'Tablet' ), | |
| 221 | + $this->getMegaMenuCSS( $attributes, 'Mobile' ), | |
| 222 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->getMegaMenuCSS( $attributes, $device ); } ) | |
| 223 | + ); | |
| 224 | + $css_generator->add_class_styles( | |
| 225 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item > .ablocks-menu-item__link', | |
| 226 | + $this->get_menu_item_link_css( $attributes, '' ), | |
| 227 | + $this->get_menu_item_link_css( $attributes, 'Tablet' ), | |
| 228 | + $this->get_menu_item_link_css( $attributes, 'Mobile' ), | |
| 229 | + $this->get_menu_tablet_hamburger_css( $attributes, $this->get_menu_item_link_css( $attributes, 'Mobile' ) ), | |
| 230 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_link_css( $attributes, $device ); } ) | |
| 231 | + ); | |
| 232 | + $css_generator->add_class_styles( | |
| 233 | + '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item:hover > .ablocks-menu-item__link ', | |
| 234 | + $this->get_menu_item_link_hover_css( $attributes, '' ), | |
| 235 | + ); | |
| 236 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-main-menu > .ablocks-menu-item > .ablocks-menu-item__dropdown-icon svg', | |
| 237 | + $this->get_menu_item_dropdown_icon_css( $attributes ), | |
| 238 | + $this->get_menu_item_dropdown_icon_css( $attributes, 'Tablet' ), | |
| 239 | + $this->get_menu_item_dropdown_icon_css( $attributes, 'Mobile' ), | |
| 240 | + $this->get_menu_tablet_hamburger_css( $attributes, $this->get_menu_item_dropdown_icon_css( $attributes, 'Mobile' ) ), | |
| 241 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_item_dropdown_icon_css( $attributes, $device ); } ) | |
| 242 | + ); | |
| 243 | + $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 ) ); | |
| 244 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper', $this->get_hamburger_menu_wrapper_css( $attributes ) ); | |
| 245 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger ', | |
| 246 | + $this->get_hamburger_menu_css( $attributes ), | |
| 247 | + $this->get_hamburger_menu_css( $attributes, 'Tablet' ), | |
| 248 | + $this->get_hamburger_menu_css( $attributes, 'Mobile' ), | |
| 249 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_hamburger_menu_css( $attributes, $device ); } ) | |
| 250 | + ); | |
| 251 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger:hover ', | |
| 252 | + $this->get_hamburgerHoverCSS( $attributes ), | |
| 253 | + $this->get_hamburgerHoverCSS( $attributes, 'Tablet' ), | |
| 254 | + $this->get_hamburgerHoverCSS( $attributes, 'Mobile' ), | |
| 255 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_hamburgerHoverCSS( $attributes, $device ); } ) | |
| 256 | + ); | |
| 257 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-menu__trigger-wrapper .ablocks-menu__trigger .ablocks-menu__trigger-item ', | |
| 258 | + $this->get_hamburger_menu_item_css( $attributes ) | |
| 259 | + ); | |
| 260 | + // menu active syle | |
| 261 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-main-menu .ablocks-menu-item.ablocks-block--menu-item-active', | |
| 262 | + $this->get_menu_active_styles_css( $attributes ), | |
| 263 | + $this->get_menu_active_styles_css( $attributes, 'Tablet' ), | |
| 264 | + $this->get_menu_active_styles_css( $attributes, 'Mobile' ), | |
| 265 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_active_styles_css( $attributes, $device ); } ) | |
| 266 | + ); | |
| 267 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-main-menu .ablocks-menu-item.ablocks-block--menu-item-active > .ablocks-menu-item__link', | |
| 268 | + [ 'color' => $this->get_menu_active_color_value( $attributes, '' ) ], | |
| 269 | + [ 'color' => $this->get_menu_active_color_value( $attributes, 'Tablet' ) ], | |
| 270 | + [ 'color' => $this->get_menu_active_color_value( $attributes, 'Mobile' ) ], | |
| 271 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return [ 'color' => $this->get_menu_active_color_value( $attributes, $device ) ]; } ) | |
| 272 | + ); | |
| 273 | + $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-main-menu .ablocks-menu-item.ablocks-block--menu-item-active > .ablocks-menu-item__dropdown-icon svg', | |
| 274 | + [ 'fill' => $this->get_menu_active_color_value( $attributes, '' ) ], | |
| 275 | + [ 'fill' => $this->get_menu_active_color_value( $attributes, 'Tablet' ) ], | |
| 276 | + [ 'fill' => $this->get_menu_active_color_value( $attributes, 'Mobile' ) ], | |
| 277 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return [ 'fill' => $this->get_menu_active_color_value( $attributes, $device ) ]; } ) | |
| 278 | + ); | |
| 279 | + return $css_generator->generate_css(); | |
| 280 | + } | |
| 281 | + | |
| 282 | + private function get_menu_css( $attributes, $device = '' ) { | |
| 283 | + $css = []; | |
| 284 | + $padding = isset( $attributes['padding'] ) ? $attributes['padding'] : ''; | |
| 285 | + | |
| 286 | + $alignment = isset( $attributes['alignment'] ) ? $attributes['alignment'] : ''; | |
| 287 | + if ( is_string( $alignment ) ) { | |
| 288 | + // `alignment` became a responsive object; a menu saved before that | |
| 289 | + // still has the old plain string, which only ever applied to desktop. | |
| 290 | + if ( '' === $device && '' !== $alignment ) { | |
| 291 | + $css['justify-content'] = $alignment; | |
| 292 | + } | |
| 293 | + } else { | |
| 294 | + $css = array_merge( $css, Alignment::get_css( $alignment, 'justify-content', $device ) ); | |
| 295 | + } | |
| 296 | + | |
| 297 | + return array_merge( | |
| 298 | + Dimensions::get_css( $padding, 'padding', $device ), | |
| 299 | + $css | |
| 300 | + ); | |
| 301 | + } | |
| 302 | + public function build_css( $attributes ) { | |
| 303 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 304 | + return $this->build_css_v2( $attributes ); | |
| 305 | + } | |
| 306 | + return $this->build_css_v1( $attributes ); | |
| 307 | + } | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + private function get_menu_item_css( $attributes, $device = '' ) { | |
| 312 | + $menu_border_css = ! empty( $attributes['menuItemBorder'] ) ? Border::get_css( $attributes['menuItemBorder'], '', $device ) : array(); | |
| 313 | + $typographyValueGlobal = ! empty( $attributes['menuItemTypographyGlobal'] ) ? $attributes['menuItemTypographyGlobal'] : array(); | |
| 314 | + $css = array_merge( | |
| 315 | + $menu_border_css, | |
| 316 | + isset( $attributes['menuItemTypography'] ) ? Typography::get_css( $attributes['menuItemTypography'], '', $device, $typographyValueGlobal ) : [], | |
| 317 | + Dimensions::get_css( isset( $attributes['menuItemPadding'] ) ? $attributes['menuItemPadding'] : [], 'padding', $device ), | |
| 318 | + Dimensions::get_css( isset( $attributes['menuItemMargin'] ) ? $attributes['menuItemMargin'] : [], 'margin', $device ) | |
| 319 | + ); | |
| 320 | + | |
| 321 | + if ( isset( $attributes[ 'menuItemDirection' . $device ] ) && ! empty( $attributes[ 'menuItemDirection' . $device ] ) ) { | |
| 322 | + $css['flex-direction'] = $attributes[ 'menuItemDirection' . $device ]; | |
| 323 | + } | |
| 324 | + | |
| 325 | + // Justify content | |
| 326 | + if ( isset( $attributes[ 'menuItemJustify' . $device ] ) && ! empty( $attributes[ 'menuItemJustify' . $device ] ) ) { | |
| 327 | + $css['justify-content'] = $attributes[ 'menuItemJustify' . $device ]; | |
| 328 | + } | |
| 329 | + | |
| 330 | + // Align items | |
| 331 | + if ( isset( $attributes[ 'menuItemAlign' . $device ] ) && ! empty( $attributes[ 'menuItemAlign' . $device ] ) ) { | |
| 332 | + $css['align-items'] = $attributes[ 'menuItemAlign' . $device ]; | |
| 333 | + } | |
| 334 | + if ( ! empty( $attributes['menuItemTransition'] ) ) { | |
| 335 | + $css['transition'] = $attributes['menuItemTransition'] . 's'; | |
| 336 | + } | |
| 337 | + if ( | |
| 338 | + ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) || | |
| 339 | + ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' ) | |
| 340 | + ) { | |
| 341 | + $css['background'] = Color::get_css( isset( $attributes['menuResponsiveBackground'] ) ? $attributes['menuResponsiveBackground'] : '' ); | |
| 342 | + } | |
| 343 | + return array_merge( | |
| 344 | + [ 'color' => Color::get_css( isset( $attributes['menuItemTextColor'] ) ? $attributes['menuItemTextColor'] : '' ) ], | |
| 345 | + [ 'background' => Color::get_css( isset( $attributes['menuItemBackground'] ) ? $attributes['menuItemBackground'] : '' ) ], | |
| 346 | + $css | |
| 347 | + ); | |
| 348 | + } | |
| 349 | + private function get_menu_item_link_css( $attributes, $device = '' ) { | |
| 350 | + $css = []; | |
| 351 | + if ( | |
| 352 | + ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) || | |
| 353 | + ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' ) | |
| 354 | + ) { | |
| 355 | + $css['color'] = Color::get_css( isset( $attributes['menuResponsiveTextColor'] ) ? $attributes['menuResponsiveTextColor'] : '' ) . ' !important'; | |
| 356 | + | |
| 357 | + } | |
| 358 | + return array_merge( | |
| 359 | + [ 'color' => Color::get_css( isset( $attributes['menuItemTextColor'] ) ? $attributes['menuItemTextColor'] : '' ) ], | |
| 360 | + $css | |
| 361 | + ); | |
| 362 | + } | |
| 363 | + | |
| 364 | + private function get_menu_item_hover_css( $attributes, $device = '' ) { | |
| 365 | + return array_merge( | |
| 366 | + [ 'color' => Color::get_css( isset( $attributes['menuItemTextColorH'] ) ? $attributes['menuItemTextColorH'] : '' ) ], | |
| 367 | + [ 'background' => Color::get_css( isset( $attributes['menuItemBackgroundH'] ) ? $attributes['menuItemBackgroundH'] : '' ) ], | |
| 368 | + Border::get_hover_css( isset( $attributes['menuItemBorder'] ) ? $attributes['menuItemBorder'] : [], $device ) | |
| 369 | + ); | |
| 370 | + } | |
| 371 | + private function get_menu_item_link_hover_css( $attributes ) { | |
| 372 | + return [ 'color' => Color::get_css( isset( $attributes['menuItemTextColorH'] ) ? $attributes['menuItemTextColorH'] : '' ) ]; | |
| 373 | + } | |
| 374 | + private function get_sub_menu_css( $attributes, $device = '' ) { | |
| 375 | + $css = []; | |
| 376 | + if ( isset( $attributes['menuItemBorder']['commonWidth'] ) ) { | |
| 377 | + $css['margin-top'] = $attributes['menuItemBorder']['commonWidth'] . 'px'; | |
| 378 | + } | |
| 379 | + if ( isset( $attributes['menuItemBorder']['bottomWidth'] ) ) { | |
| 380 | + $css['margin-top'] = $attributes['menuItemBorder']['bottomWidth'] . 'px'; | |
| 381 | + } | |
| 382 | + return array_merge( | |
| 383 | + $css, | |
| 384 | + Range::get_css([ | |
| 385 | + 'attributeValue' => $attributes['subMenuWidth'], | |
| 386 | + 'attribute_object_key' => 'value', | |
| 387 | + 'isResponsive' => true, | |
| 388 | + 'defaultValue' => 250, | |
| 389 | + 'hasUnit' => true, | |
| 390 | + 'unitDefaultValue' => 'px', | |
| 391 | + 'property' => 'width', | |
| 392 | + 'device' => $device, | |
| 393 | + ]), | |
| 394 | + BoxShadow::get_css( ! empty( $attributes['subMenuBoxShadow'] ) ? $attributes['subMenuBoxShadow'] : '', $device ), | |
| 395 | + Dimensions::get_css( $attributes['subMenuPadding'], 'padding', $device ), | |
| 396 | + Border::get_css( $attributes['subMenuBorder'], '', $device ), | |
| 397 | + ); | |
| 398 | + } | |
| 399 | + private function get_sub_menu_hover_css( $attributes, $device = '' ) { | |
| 400 | + return array_merge( | |
| 401 | + Border::get_hover_css( $attributes['subMenuBorder'], '', $device ), | |
| 402 | + BoxShadow::get_hover_css( $attributes['subMenuBoxShadow'], '', $device ) | |
| 403 | + ); | |
| 404 | + } | |
| 405 | + private function get_subMenu_responsive_css( $attributes, $device = '' ) { | |
| 406 | + $css = []; | |
| 407 | + if ( ! empty( $attributes['subMenuItemTransition'] ) ) { | |
| 408 | + $css['transition-duration'] = $attributes['subMenuItemTransition'] . 's'; | |
| 409 | + } | |
| 410 | + if ( | |
| 411 | + ( isset( $attributes['sideBarMenuDevice'] ) && $attributes['sideBarMenuDevice'] === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) ) || | |
| 412 | + ( isset( $attributes['sideBarMenuDevice'] ) && $attributes['sideBarMenuDevice'] !== 'tablet' && $device === 'Mobile' ) | |
| 413 | + ) { | |
| 414 | + $css['background'] = Color::get_css( isset( $attributes['subMenuResponsiveBg'] ) ? $attributes['subMenuResponsiveBg'] : '' ) . '!important'; | |
| 415 | + } | |
| 416 | + return array_merge( | |
| 417 | + [ 'background' => Color::get_css( isset( $attributes['subMenuItemBackground'] ) ? $attributes['subMenuItemBackground'] : '' ) ], | |
| 418 | + $css | |
| 419 | + ); | |
| 420 | + } | |
| 421 | + | |
| 422 | + private function get_subMenu_responsive_hover_css( $attributes ) { | |
| 423 | + return array_merge( | |
| 424 | + [ 'color' => Color::get_css( isset( $attributes['subMenuItemTextColorH'] ) ? $attributes['subMenuItemTextColorH'] : '' ) ], | |
| 425 | + [ 'background' => Color::get_css( isset( $attributes['subMenuItemBackgroundH'] ) ? $attributes['subMenuItemBackgroundH'] : '' ) ] | |
| 426 | + ); | |
| 427 | + } | |
| 428 | + private function get_subMenu_responsive_text_css( $attributes, $device = '' ) { | |
| 429 | + $css = []; | |
| 430 | + if ( | |
| 431 | + ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) || | |
| 432 | + ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' ) | |
| 433 | + ) { | |
| 434 | + $css['color'] = Color::get_css( isset( $attributes['subMenuResponsiveColor'] ) ? $attributes['subMenuResponsiveColor'] : '' ) . ' !important'; | |
| 435 | + } | |
| 436 | + | |
| 437 | + return array_merge( | |
| 438 | + [ 'color' => Color::get_css( isset( $attributes['subMenuItemTextColor'] ) ? $attributes['subMenuItemTextColor'] : '' ) ], | |
| 439 | + $css | |
| 440 | + ); | |
| 441 | + } | |
| 442 | + private function get_subMenu__text_hover_css( $attributes, $device = '' ) { | |
| 443 | + return [ 'color' => Color::get_css( isset( $attributes['subMenuItemTextColorH'] ) ? $attributes['subMenuItemTextColorH'] : '' ) ]; | |
| 444 | + } | |
| 445 | + private function getMegaMenuCSS( $attributes, $device = '' ) { | |
| 446 | + $css = []; | |
| 447 | + if ( isset( $attributes['sideBarMenuDevice'] ) && $attributes['sideBarMenuDevice'] === 'tablet' && $device === 'Tablet' ) { | |
| 448 | + $css['position'] = 'static !important'; | |
| 449 | + } | |
| 450 | + return $css; | |
| 451 | + } | |
| 452 | + | |
| 453 | + | |
| 454 | + private function get_menu_item_dropdown_icon_css( $attributes, $device = '' ) { | |
| 455 | + $css = []; | |
| 456 | + if ( | |
| 457 | + ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) || | |
| 458 | + ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' ) | |
| 459 | + ) { | |
| 460 | + $css['fill'] = Color::get_css( isset( $attributes['menuResponsiveTextColor'] ) ? $attributes['menuResponsiveTextColor'] : '' ) . ' !important'; | |
| 461 | + } | |
| 462 | + return array_merge( | |
| 463 | + [ 'fill' => Color::get_css( isset( $attributes['menuItemTextColor'] ) ? $attributes['menuItemTextColor'] : '' ) ], | |
| 464 | + $css | |
| 465 | + ); | |
| 466 | + } | |
| 467 | + private function get_menu_item_dropdown_icon_hover_css( $attributes ) { | |
| 468 | + return [ 'fill' => Color::get_css( isset( $attributes['menuItemTextColorH'] ) ? $attributes['menuItemTextColorH'] : '' ) ]; | |
| 469 | + } | |
| 470 | + private function get_hamburger_menu_wrapper_css( $attributes ) { | |
| 471 | + $css = []; | |
| 472 | + if ( isset( $attributes['hamburgerAlignment'] ) ) { | |
| 473 | + $css['justify-content'] = $attributes['hamburgerAlignment']; | |
| 474 | + } | |
| 475 | + return $css; | |
| 476 | + } | |
| 477 | + public function get_hamburger_menu_css( $attributes, $device = '' ) { | |
| 478 | + $hamburger_border_css = ! empty( $attributes['hamburgerBorder'] ) ? Border::get_css( $attributes['hamburgerBorder'], '', $device ) : array(); | |
| 479 | + $css = array_merge( | |
| 480 | + $hamburger_border_css, | |
| 481 | + Dimensions::get_css( isset( $attributes['hamburgerPadding'] ) ? $attributes['hamburgerPadding'] : [], 'padding', $device ), | |
| 482 | + [ 'background' => Color::get_css( isset( $attributes['hamburgerBackground'] ) ? $attributes['hamburgerBackground'] : '' ) ], | |
| 483 | + ); | |
| 484 | + $height_humber = 30 + ( isset( $attributes['hamburgerHeight.value'] ) ? $attributes['hamburgerHeight.value'] : 0 ); | |
| 485 | + if ( $height_humber ) { | |
| 486 | + $css['height'] = "{$height_humber}px"; | |
| 487 | + } | |
| 488 | + | |
| 489 | + return $css; | |
| 490 | + } | |
| 491 | + public function get_hamburgerHoverCSS( $attributes, $device = '' ) { | |
| 492 | + $css = Border::get_hover_css( isset( $attributes['hamburgerBorder'] ) ? $attributes['hamburgerBorder'] : [], $device ); | |
| 493 | + return $css; | |
| 494 | + } | |
| 495 | + | |
| 496 | + | |
| 497 | + public function get_hamburger_menu_item_css( $attributes, $device = '' ) { | |
| 498 | + return array_merge( | |
| 499 | + [ 'background' => Color::get_css( isset( $attributes['hamburgerColor'] ) ? $attributes['hamburgerColor'] : '' ) ], | |
| 500 | + Range::get_css([ | |
| 501 | + 'attributeValue' => $attributes['hamburgerHeight'], | |
| 502 | + 'attribute_object_key' => 'value', | |
| 503 | + 'isResponsive' => false, | |
| 504 | + 'defaultValue' => 3, | |
| 505 | + 'hasUnit' => true, | |
| 506 | + 'unitDefaultValue' => 'px', | |
| 507 | + 'property' => 'height', | |
| 508 | + 'device' => $device, | |
| 509 | + ]), | |
| 510 | + Range::get_css([ | |
| 511 | + 'attributeValue' => $attributes['hamburgerWidth'], | |
| 512 | + 'attribute_object_key' => 'value', | |
| 513 | + 'isResponsive' => false, | |
| 514 | + 'defaultValue' => 30, | |
| 515 | + 'hasUnit' => true, | |
| 516 | + 'unitDefaultValue' => 'px', | |
| 517 | + 'property' => 'width', | |
| 518 | + 'device' => $device, | |
| 519 | + ]) | |
| 520 | + ); | |
| 521 | + } | |
| 522 | + // menu active color syle | |
| 523 | + public function get_menu_active_styles_css( $attributes, $device = '' ) { | |
| 524 | + return array_merge( | |
| 525 | + [ 'color' => Color::get_css( isset( $attributes['menuActveColor'] ) ? $attributes['menuActveColor'] : '' ) ], | |
| 526 | + [ 'background' => Color::get_css( isset( $attributes['menuActveColorBg'] ) ? $attributes['menuActveColorBg'] : '' ) ], | |
| 527 | + ); | |
| 528 | + } | |
| 529 | + // The responsive text color is emitted with !important on these devices, so the active color needs it too to win over it. | |
| 530 | + private function get_menu_active_color_value( $attributes, $device = '' ) { | |
| 531 | + $color = Color::get_css( isset( $attributes['menuActveColor'] ) ? $attributes['menuActveColor'] : '' ); | |
| 532 | + if ( | |
| 533 | + '' !== $color && | |
| 534 | + ( ( $attributes['sideBarMenuDevice'] ?? null ) === 'tablet' && in_array( $device, [ 'Tablet', 'Mobile' ], true ) || | |
| 535 | + ( ( $attributes['sideBarMenuDevice'] ?? null ) !== 'tablet' && $device === 'Mobile' ) ) | |
| 536 | + ) { | |
| 537 | + return $color . ' !important'; | |
| 538 | + } | |
| 539 | + return $color; | |
| 540 | + } | |
| 541 | + | |
| 542 | + /** | |
| 543 | + * Just the "Menu Responsive" background, with none of get_menu_item_css()'s | |
| 544 | + * other declarations (border, padding, direction, ...) that don't belong in | |
| 545 | + * the tablet-hamburger custom breakpoint below. | |
| 546 | + */ | |
| 547 | + private function get_menu_responsive_background_only_css( $attributes ) { | |
| 548 | + if ( empty( $attributes['menuResponsiveBackground'] ) ) { | |
| 549 | + return []; | |
| 550 | + } | |
| 551 | + return [ 'background' => Color::get_css( $attributes['menuResponsiveBackground'] ) ]; | |
| 552 | + } | |
| 553 | + | |
| 554 | + /** | |
| 555 | + * "Enable Tablet Hamburger Menu" shows a hamburger in the 768px-1024px range | |
| 556 | + * (see style.css) independently of the Tablet(800)/Mobile(480) breakpoints the | |
| 557 | + * responsive controls use, and independently of "Hamburger Menu Device". The | |
| 558 | + * "Menu Responsive" colors were only ever emitted for those two breakpoints, | |
| 559 | + * so they never reached this range. This adds them there too, as a custom | |
| 560 | + * breakpoint on the same selector, without touching the standard Tablet/Mobile | |
| 561 | + * output. | |
| 562 | + */ | |
| 563 | + private function get_menu_tablet_hamburger_css( $attributes, $styles ) { | |
| 564 | + if ( empty( $attributes['enableTabletHamburger'] ) || empty( $styles ) ) { | |
| 565 | + return []; | |
| 566 | + } | |
| 567 | + return [ | |
| 568 | + 'tabletHamburger' => [ | |
| 569 | + 'width' => 1024, | |
| 570 | + 'min' => 768, | |
| 571 | + 'max' => 1024, | |
| 572 | + 'styles' => $styles, | |
| 573 | + ], | |
| 574 | + ]; | |
| 575 | + } | |
| 576 | +} | |