| @@ -12,9 +12,11 @@ | ||
| 12 | 12 | use ABlocks\Controls\TextStroke; |
| 13 | 13 | use ABlocks\Controls\Border; |
| 14 | 14 | use ABlocks\Controls\Dimensions; |
| 15 | 15 | use ABlocks\Controls\Range; |
| 16 | +use ABlocks\Controls\Color; | |
| 16 | 17 | |
| 18 | + | |
| 17 | 19 | class Block extends BlockBaseAbstract { |
| 18 | 20 | protected $parent_block_name = 'accordion'; |
| 19 | 21 | protected $block_name = 'single-accordion'; |
| 20 | 22 | |
| @@ -29,9 +31,10 @@ | ||
| 29 | 31 | $css_generator->add_class_styles( |
| 30 | 32 | '{{WRAPPER}}.ablocks-block--single-accordion:hover', |
| 31 | 33 | $this->get_item_hover_css( $attributes ), |
| 32 | 34 | $this->get_item_hover_css( $attributes, 'Tablet' ), |
| 33 | - $this->get_item_hover_css( $attributes, 'Mobile' ) | |
| 35 | + $this->get_item_hover_css( $attributes, 'Mobile' ), | |
| 36 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_item_hover_css( $attributes, $device ); } ) | |
| 34 | 37 | ); |
| 35 | 38 | $css_generator->add_class_styles( |
| 36 | 39 | '{{WRAPPER}} .ablocks-block--single-accordion__heading .ablocks-block-accordion-title', |
| 37 | 40 | $this->get_title_css( $attributes ), |
| @@ -40,21 +43,24 @@ | ||
| 40 | 43 | ); |
| 41 | 44 | $css_generator->add_class_styles( |
| 42 | 45 | '{{WRAPPER}} .ablocks-block--single-accordion__heading:hover .ablocks-block-accordion-title', $this->get_title_hover_css( $attributes ), |
| 43 | 46 | $this->get_title_hover_css( $attributes, 'Tablet' ), |
| 44 | - $this->get_title_hover_css( $attributes, 'Mobile' ) | |
| 47 | + $this->get_title_hover_css( $attributes, 'Mobile' ), | |
| 48 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_title_hover_css( $attributes, $device ); } ) | |
| 45 | 49 | ); |
| 46 | 50 | $css_generator->add_class_styles( |
| 47 | 51 | '{{WRAPPER}}.ablocks-block--single-accordion-is-selected .ablocks-block-accordion-title', |
| 48 | 52 | $this->get_title_active_css( $attributes ), |
| 49 | 53 | $this->get_title_active_css( $attributes, 'Tablet' ), |
| 50 | - $this->get_title_active_css( $attributes, 'Mobile' ) | |
| 54 | + $this->get_title_active_css( $attributes, 'Mobile' ), | |
| 55 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_title_active_css( $attributes, $device ); } ) | |
| 51 | 56 | ); |
| 52 | 57 | $css_generator->add_class_styles( |
| 53 | 58 | '{{WRAPPER}} .ablocks-block--single-accordion__heading', |
| 54 | 59 | $this->get_panel_css( $attributes ), |
| 55 | 60 | $this->get_panel_css( $attributes, 'Tablet' ), |
| 56 | - $this->get_panel_css( $attributes, 'Mobile' ) | |
| 61 | + $this->get_panel_css( $attributes, 'Mobile' ), | |
| 62 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_panel_css( $attributes, $device ); } ) | |
| 57 | 63 | ); |
| 58 | 64 | $css_generator->add_class_styles( |
| 59 | 65 | '{{WRAPPER}} .ablocks-block--single-accordion__heading:hover', |
| 60 | 66 | $this->get_panel_hover_css( $attributes ), |
| @@ -64,9 +70,10 @@ | ||
| 64 | 70 | $css_generator->add_class_styles( |
| 65 | 71 | '{{WRAPPER}}.ablocks-block--single-accordion-is-selected .ablocks-block--single-accordion__heading', |
| 66 | 72 | $this->get_panel_active_css( $attributes ), |
| 67 | 73 | $this->get_panel_active_css( $attributes, 'Tablet' ), |
| 68 | - $this->get_panel_active_css( $attributes, 'Mobile' ) | |
| 74 | + $this->get_panel_active_css( $attributes, 'Mobile' ), | |
| 75 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_panel_active_css( $attributes, $device ); } ) | |
| 69 | 76 | ); |
| 70 | 77 | $css_generator->add_class_styles( |
| 71 | 78 | '{{WRAPPER}} .ablocks-block--single-accordion__heading svg.ablocks-svg-icon', |
| 72 | 79 | $this->get_icon_css( $attributes ) |
| @@ -78,15 +85,17 @@ | ||
| 78 | 85 | $css_generator->add_class_styles( |
| 79 | 86 | '{{WRAPPER}} .ablocks-block--single-accordion__body-content', |
| 80 | 87 | $this->get_content_css( $attributes ), |
| 81 | 88 | $this->get_content_css( $attributes, 'Tablet' ), |
| 82 | - $this->get_content_css( $attributes, 'Mobile' ) | |
| 89 | + $this->get_content_css( $attributes, 'Mobile' ), | |
| 90 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_css( $attributes, $device ); } ) | |
| 83 | 91 | ); |
| 84 | 92 | $css_generator->add_class_styles( |
| 85 | 93 | '{{WRAPPER}} .ablocks-block--single-accordion__body-content:hover', |
| 86 | 94 | $this->get_content_hover_css( $attributes ), |
| 87 | 95 | $this->get_content_hover_css( $attributes, 'Tablet' ), |
| 88 | - $this->get_content_hover_css( $attributes, 'Mobile' ) | |
| 96 | + $this->get_content_hover_css( $attributes, 'Mobile' ), | |
| 97 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_hover_css( $attributes, $device ); } ) | |
| 89 | 98 | ); |
| 90 | 99 | return $css_generator->generate_css(); |
| 91 | 100 | } |
| 92 | 101 | public function get_item_css( $attributes, $device = '' ) { |
| @@ -110,17 +119,14 @@ | ||
| 110 | 119 | Border::get_hover_css( $attributes['itemBorder'], '', $device ) |
| 111 | 120 | ); |
| 112 | 121 | } |
| 113 | 122 | public function get_title_css( $attributes, $device = '' ) { |
| 114 | - $css = []; | |
| 115 | - if ( ! empty( $attributes['headerTextColor'] ) ) { | |
| 116 | - $css['color'] = $attributes['headerTextColor']; | |
| 117 | - } | |
| 118 | - $typography_css = Typography::get_css( $attributes['headerTypography'], '', $device ); | |
| 123 | + $typographyValueGlobal = ! empty( $attributes['headerTypographyGlobal'] ) ? $attributes['headerTypographyGlobal'] : array(); | |
| 124 | + $typography_css = Typography::get_css( $attributes['headerTypography'], '', $device, $typographyValueGlobal ); | |
| 119 | 125 | $textShadowCss = TextShadow::get_css( $attributes['headerTextShadow'], '', $device ); |
| 120 | 126 | $textStrokeCss = TextStroke::get_css( $attributes['headerTextStroke'], '', $device ); |
| 121 | 127 | return array_merge( |
| 122 | - $css, | |
| 128 | + [ 'color' => Color::get_css( isset( $attributes['headerTextColor'] ) ? $attributes['headerTextColor'] : '' ) ], | |
| 123 | 129 | $typography_css, |
| 124 | 130 | $textShadowCss, |
| 125 | 131 | $textStrokeCss |
| 126 | 132 | ); |
| @@ -126,61 +132,32 @@ | ||
| 126 | 132 | ); |
| 127 | 133 | } |
| 128 | 134 | |
| 129 | 135 | public function get_title_hover_css( $attributes, $device = '' ) { |
| 130 | - $css = []; | |
| 131 | - if ( ! empty( $attributes['headerTextColorH'] ) ) { | |
| 132 | - $css['color'] = $attributes['headerTextColorH']; | |
| 133 | - } | |
| 134 | - return array_merge( | |
| 135 | - $css, | |
| 136 | - ); | |
| 136 | + return [ 'color' => Color::get_css( isset( $attributes['headerTextColorH'] ) ? $attributes['headerTextColorH'] : '' ) ]; | |
| 137 | 137 | } |
| 138 | 138 | public function get_title_active_css( $attributes, $device = '' ) { |
| 139 | - $css = []; | |
| 140 | - if ( ! empty( $attributes['headerTextActiveColor'] ) ) { | |
| 141 | - $css['color'] = $attributes['headerTextActiveColor']; | |
| 142 | - } | |
| 143 | - return array_merge( | |
| 144 | - $css, | |
| 145 | - ); | |
| 139 | + return [ 'color' => Color::get_css( isset( $attributes['headerTextActiveColor'] ) ? $attributes['headerTextActiveColor'] : '' ) ]; | |
| 146 | 140 | } |
| 147 | 141 | public function get_panel_css( $attributes, $device = '' ) { |
| 148 | - $css = []; | |
| 149 | - if ( ! empty( $attributes['headerBackgroundColor'] ) ) { | |
| 150 | - $css['background'] = $attributes['headerBackgroundColor']; | |
| 151 | - } | |
| 152 | 142 | return array_merge( |
| 153 | - $css, | |
| 143 | + [ 'background' => Color::get_css( isset( $attributes['headerBackgroundColor'] ) ? $attributes['headerBackgroundColor'] : '' ) ], | |
| 154 | 144 | Border::get_css( $attributes['headerBorder'], '', $device ), |
| 155 | 145 | Dimensions::get_css( $attributes['headerPadding'], 'padding', $device ) |
| 156 | 146 | ); |
| 157 | 147 | } |
| 158 | 148 | public function get_panel_hover_css( $attributes, $device = '' ) { |
| 159 | - $css = []; | |
| 160 | - if ( ! empty( $attributes['headerBackgroundColorH'] ) ) { | |
| 161 | - $css['background'] = $attributes['headerBackgroundColorH']; | |
| 162 | - } | |
| 163 | 149 | return array_merge( |
| 164 | - $css, | |
| 150 | + [ 'background' => Color::get_css( isset( $attributes['headerBackgroundColorH'] ) ? $attributes['headerBackgroundColorH'] : '' ) ], | |
| 165 | 151 | Border::get_hover_css( $attributes['headerBorder'], '', $device ) |
| 166 | 152 | ); |
| 167 | 153 | } |
| 168 | 154 | public function get_panel_active_css( $attributes, $device = '' ) { |
| 169 | - $css = []; | |
| 170 | - if ( ! empty( $attributes['headerBackgroundActiveColor'] ) ) { | |
| 171 | - $css['background'] = $attributes['headerBackgroundActiveColor']; | |
| 172 | - } | |
| 173 | - return array_merge( | |
| 174 | - $css, | |
| 175 | - ); | |
| 155 | + return [ 'background' => Color::get_css( isset( $attributes['headerBackgroundActiveColor'] ) ? $attributes['headerBackgroundActiveColor'] : '' ) ]; | |
| 176 | 156 | } |
| 177 | 157 | public function get_icon_css( $attributes, $device = '' ) { |
| 178 | - $css = []; | |
| 179 | - if ( ! empty( $attributes['iconColor'] ) ) { | |
| 180 | - $css['fill'] = $attributes['iconColor'] . ' !important'; | |
| 181 | - } | |
| 182 | - return array_merge( $css, | |
| 158 | + return array_merge( | |
| 159 | + [ 'fill' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '' ) . ' !important' ], | |
| 183 | 160 | Range::get_css( [ |
| 184 | 161 | 'attributeValue' => $attributes['iconSize'], |
| 185 | 162 | 'attribute_object_key' => 'value', |
| 186 | 163 | 'isResponsive' => false, |
| @@ -190,30 +167,17 @@ | ||
| 190 | 167 | ); |
| 191 | 168 | } |
| 192 | 169 | |
| 193 | 170 | public function get_icon_hover_css( $attributes ) { |
| 194 | - $css = []; | |
| 195 | - if ( ! empty( $attributes['iconColorH'] ) ) { | |
| 196 | - $css['fill'] = $attributes['iconColorH'] . ' !important'; | |
| 197 | - } | |
| 198 | - return array_merge( $css ); | |
| 171 | + return [ 'fill' => Color::get_css( isset( $attributes['iconColorH'] ) ? $attributes['iconColorH'] : '' ) . ' !important' ]; | |
| 172 | + | |
| 199 | 173 | } |
| 200 | 174 | public function get_content_css( $attributes, $device = '' ) { |
| 201 | - $css = []; | |
| 202 | - if ( ! empty( $attributes['bodyBackground'] ) ) { | |
| 203 | - $css['background'] = $attributes['bodyBackground']; | |
| 204 | - } | |
| 205 | 175 | return array_merge( |
| 206 | - $css, | |
| 176 | + [ 'background' => Color::get_css( isset( $attributes['bodyBackground'] ) ? $attributes['bodyBackground'] : '' ) ], | |
| 207 | 177 | Dimensions::get_css( $attributes['bodyPadding'], 'padding', $device ) |
| 208 | 178 | ); |
| 209 | 179 | } |
| 210 | 180 | public function get_content_hover_css( $attributes, $device = '' ) { |
| 211 | - $css = []; | |
| 212 | - if ( ! empty( $attributes['bodyBackgroundH'] ) ) { | |
| 213 | - $css['background'] = $attributes['bodyBackgroundH']; | |
| 214 | - } | |
| 215 | - return array_merge( | |
| 216 | - $css, | |
| 217 | - ); | |
| 181 | + return [ 'background' => Color::get_css( isset( $attributes['bodyBackgroundH'] ) ? $attributes['bodyBackgroundH'] : '' ) ]; | |
| 218 | 182 | } |
| 219 | 183 | } |