| @@ -7,17 +7,83 @@ | ||
| 7 | 7 | |
| 8 | 8 | use ABlocks\Classes\BlockBaseAbstract; |
| 9 | 9 | use ABlocks\Classes\CssGenerator; |
| 10 | 10 | use ABlocks\Controls\Border; |
| 11 | +use ABlocks\Classes\CssGeneratorV2; | |
| 12 | +use ABlocks\Controls\Color; | |
| 11 | 13 | |
| 12 | 14 | class Block extends BlockBaseAbstract { |
| 13 | 15 | protected $block_name = 'table'; |
| 14 | 16 | |
| 15 | - public function build_css( $attributes ) { | |
| 17 | + public function build_css_v1( $attributes ) { | |
| 18 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 19 | + $css_generator->add_class_styles( | |
| 20 | + '{{WRAPPER}}.ablocks-block--table table', | |
| 21 | + $this->get_table_css( $attributes ) | |
| 22 | + ); | |
| 23 | + $css_generator->add_class_styles( | |
| 24 | + '{{WRAPPER}}.ablocks-block--table table, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell , {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell', | |
| 25 | + $this->get_table_border_css( $attributes ), | |
| 26 | + $this->get_table_border_css( $attributes, 'Tablet' ), | |
| 27 | + $this->get_table_border_css( $attributes, 'Mobile' ), | |
| 28 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_css( $attributes, $device ); } ) | |
| 29 | + ); | |
| 30 | + $css_generator->add_class_styles( | |
| 31 | + '{{WRAPPER}}.ablocks-block--table table:hover, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell:hover, {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell:hover', | |
| 32 | + $this->get_table_border_hover_css( $attributes ), | |
| 33 | + $this->get_table_border_hover_css( $attributes, 'Tablet' ), | |
| 34 | + $this->get_table_border_hover_css( $attributes, 'Mobile' ), | |
| 35 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_hover_css( $attributes, $device ); } ) | |
| 36 | + ); | |
| 37 | + $css_generator->add_class_styles( | |
| 38 | + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--odd', | |
| 39 | + $this->get_row_odd_css( $attributes ) | |
| 40 | + ); | |
| 41 | + $css_generator->add_class_styles( | |
| 42 | + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--odd:hover', | |
| 43 | + $this->get_row_odd_hover_css( $attributes ) | |
| 44 | + ); | |
| 45 | + $css_generator->add_class_styles( | |
| 46 | + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--even', | |
| 47 | + $this->get_row_even_css( $attributes ) | |
| 48 | + ); | |
| 49 | + $css_generator->add_class_styles( | |
| 50 | + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--even:hover', | |
| 51 | + $this->get_row_even_hover_css( $attributes ) | |
| 52 | + ); | |
| 53 | + // ---header---- | |
| 54 | + $css_generator->add_class_styles( | |
| 55 | + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-header', | |
| 56 | + $this->get_header_css( $attributes ) | |
| 57 | + ); | |
| 58 | + $css_generator->add_class_styles( | |
| 59 | + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-header:hover', | |
| 60 | + $this->get_header_hover_css( $attributes ) | |
| 61 | + ); | |
| 62 | + // --table body---- | |
| 63 | + $css_generator->add_class_styles( | |
| 64 | + '{{WRAPPER}} .ablocks-block--table-body', | |
| 65 | + $this->get_body_css( $attributes ) | |
| 66 | + ); | |
| 67 | + $css_generator->add_class_styles( | |
| 68 | + '{{WRAPPER}} .ablocks-block--table-body:hover', | |
| 69 | + $this->get_body_hover_css( $attributes ) | |
| 70 | + ); | |
| 16 | 71 | |
| 17 | - // Generate CSS start | |
| 18 | - $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 72 | + // --table footer-- | |
| 19 | 73 | $css_generator->add_class_styles( |
| 74 | + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-footer', | |
| 75 | + $this->get_footer_css( $attributes ) | |
| 76 | + ); | |
| 77 | + $css_generator->add_class_styles( | |
| 78 | + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-footer:hover', | |
| 79 | + $this->get_footer_hover_css( $attributes ) | |
| 80 | + ); | |
| 81 | + return $css_generator->generate_css(); | |
| 82 | + } | |
| 83 | + public function build_css_v2( $attributes ) { | |
| 84 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 85 | + $css_generator->add_class_styles( | |
| 20 | 86 | '{{WRAPPER}}.ablocks-block--table table', |
| 21 | 87 | $this->get_table_css( $attributes ) |
| 22 | 88 | ); |
| 23 | 89 | $css_generator->add_class_styles( |
| @@ -23,15 +89,17 @@ | ||
| 23 | 89 | $css_generator->add_class_styles( |
| 24 | 90 | '{{WRAPPER}}.ablocks-block--table table, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell , {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell', |
| 25 | 91 | $this->get_table_border_css( $attributes ), |
| 26 | 92 | $this->get_table_border_css( $attributes, 'Tablet' ), |
| 27 | - $this->get_table_border_css( $attributes, 'Mobile' ) | |
| 93 | + $this->get_table_border_css( $attributes, 'Mobile' ), | |
| 94 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_css( $attributes, $device ); } ) | |
| 28 | 95 | ); |
| 29 | 96 | $css_generator->add_class_styles( |
| 30 | 97 | '{{WRAPPER}}.ablocks-block--table table:hover, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell:hover, {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell:hover', |
| 31 | 98 | $this->get_table_border_hover_css( $attributes ), |
| 32 | 99 | $this->get_table_border_hover_css( $attributes, 'Tablet' ), |
| 33 | - $this->get_table_border_hover_css( $attributes, 'Mobile' ) | |
| 100 | + $this->get_table_border_hover_css( $attributes, 'Mobile' ), | |
| 101 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_hover_css( $attributes, $device ); } ) | |
| 34 | 102 | ); |
| 35 | 103 | $css_generator->add_class_styles( |
| 36 | 104 | '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--odd', |
| 37 | 105 | $this->get_row_odd_css( $attributes ) |
| @@ -77,8 +145,14 @@ | ||
| 77 | 145 | $this->get_footer_hover_css( $attributes ) |
| 78 | 146 | ); |
| 79 | 147 | return $css_generator->generate_css(); |
| 80 | 148 | } |
| 149 | + public function build_css( $attributes ) { | |
| 150 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 151 | + return $this->build_css_v2( $attributes ); | |
| 152 | + } | |
| 153 | + return $this->build_css_v1( $attributes ); | |
| 154 | + } | |
| 81 | 155 | public function get_table_css( $attributes, $device = '' ) { |
| 82 | 156 | $css = []; |
| 83 | 157 | |
| 84 | 158 | if ( ! empty( $attributes['borderCollapse'] ) && $attributes['borderCollapse'] === 'collapse' ) { |
| @@ -100,53 +174,34 @@ | ||
| 100 | 174 | return Border::get_hover_css( $attributes['border'], '', $device ); |
| 101 | 175 | } |
| 102 | 176 | |
| 103 | 177 | public function get_row_odd_css( $attributes, $device = '' ) { |
| 104 | - $css = []; | |
| 105 | - if ( ! empty( $attributes['rowOddColor'] ) ) { | |
| 106 | - $css['background'] = $attributes['rowOddColor']; | |
| 107 | - } | |
| 108 | - return $css; | |
| 178 | + return [ 'background' => Color::get_css( isset( $attributes['rowOddColor'] ) ? $attributes['rowOddColor'] : '' ) ]; | |
| 109 | 179 | } |
| 110 | 180 | |
| 111 | 181 | public function get_row_odd_hover_css( $attributes, $device = '' ) { |
| 112 | - $css = []; | |
| 113 | - if ( ! empty( $attributes['rowOddColorH'] ) ) { | |
| 114 | - $css['background'] = $attributes['rowOddColorH']; | |
| 115 | - } | |
| 116 | - return $css; | |
| 182 | + return [ 'background' => Color::get_css( isset( $attributes['rowOddColorH'] ) ? $attributes['rowOddColorH'] : '' ) ]; | |
| 117 | 183 | } |
| 118 | 184 | |
| 119 | 185 | public function get_row_even_css( $attributes, $device = '' ) { |
| 120 | - $css = []; | |
| 121 | - if ( ! empty( $attributes['rowEvenColor'] ) ) { | |
| 122 | - $css['background'] = $attributes['rowEvenColor']; | |
| 123 | - } | |
| 124 | - return $css; | |
| 186 | + return [ 'background' => Color::get_css( isset( $attributes['rowEvenColor'] ) ? $attributes['rowEvenColor'] : '' ) ]; | |
| 125 | 187 | } |
| 126 | 188 | |
| 127 | 189 | public function get_row_even_hover_css( $attributes, $device = '' ) { |
| 128 | - $css = []; | |
| 129 | - if ( ! empty( $attributes['rowEvenColorH'] ) ) { | |
| 130 | - $css['background'] = $attributes['rowEvenColorH']; | |
| 131 | - } | |
| 132 | - return $css; | |
| 190 | + return [ 'background' => Color::get_css( isset( $attributes['rowEvenColorH'] ) ? $attributes['rowEvenColorH'] : '' ) ]; | |
| 133 | 191 | } |
| 134 | 192 | |
| 135 | 193 | public function get_header_css( $attributes, $device = '' ) { |
| 136 | 194 | $css = []; |
| 137 | - if ( ! empty( $attributes['headerColor'] ) ) { | |
| 138 | - $css['background'] = $attributes['headerColor'] . ' !important'; | |
| 139 | - } | |
| 140 | - | |
| 195 | + $css['background'] = Color::get_css( | |
| 196 | + isset( $attributes['headerColor'] ) ? $attributes['headerColor'] : '') . ' !important'; | |
| 141 | 197 | return $css; |
| 142 | 198 | } |
| 143 | 199 | |
| 144 | 200 | public function get_header_hover_css( $attributes, $device = '' ) { |
| 145 | 201 | $css = []; |
| 146 | - if ( ! empty( $attributes['headerColorH'] ) ) { | |
| 147 | - $css['background'] = $attributes['headerColorH'] . ' !important'; | |
| 148 | - } | |
| 202 | + $css['background'] = Color::get_css( | |
| 203 | + isset( $attributes['headerColorH'] ) ? $attributes['headerColorH'] : '') . ' !important'; | |
| 149 | 204 | |
| 150 | 205 | return $css; |
| 151 | 206 | } |
| 152 | 207 | |
| @@ -151,19 +206,17 @@ | ||
| 151 | 206 | } |
| 152 | 207 | |
| 153 | 208 | public function get_body_css( $attributes, $device = '' ) { |
| 154 | 209 | $css = []; |
| 155 | - if ( ! empty( $attributes['bodyBg'] ) ) { | |
| 156 | - $css['background'] = $attributes['bodyBg'] . ' !important'; | |
| 157 | - } | |
| 210 | + $css['background'] = Color::get_css( | |
| 211 | + isset( $attributes['bodyBg'] ) ? $attributes['bodyBg'] : '') . ' !important'; | |
| 158 | 212 | return $css; |
| 159 | 213 | } |
| 160 | 214 | |
| 161 | 215 | public function get_body_hover_css( $attributes, $device = '' ) { |
| 162 | 216 | $css = []; |
| 163 | - if ( ! empty( $attributes['bodyBgH'] ) ) { | |
| 164 | - $css['background'] = $attributes['bodyBgH'] . ' !important'; | |
| 165 | - } | |
| 217 | + $css['background'] = Color::get_css( | |
| 218 | + isset( $attributes['bodyBgH'] ) ? $attributes['bodyBgH'] : '') . ' !important'; | |
| 166 | 219 | |
| 167 | 220 | return $css; |
| 168 | 221 | } |
| 169 | 222 | |
| @@ -168,11 +221,10 @@ | ||
| 168 | 221 | } |
| 169 | 222 | |
| 170 | 223 | public function get_footer_css( $attributes, $device = '' ) { |
| 171 | 224 | $css = []; |
| 172 | - if ( ! empty( $attributes['footerColor'] ) ) { | |
| 173 | - $css['background'] = $attributes['footerColor'] . ' !important'; | |
| 174 | - } | |
| 225 | + $css['background'] = Color::get_css( | |
| 226 | + isset( $attributes['footerColor'] ) ? $attributes['footerColor'] : '') . ' !important'; | |
| 175 | 227 | |
| 176 | 228 | return $css; |
| 177 | 229 | } |
| 178 | 230 | |
| @@ -177,11 +229,11 @@ | ||
| 177 | 229 | } |
| 178 | 230 | |
| 179 | 231 | public function get_footer_hover_css( $attributes, $device = '' ) { |
| 180 | 232 | $css = []; |
| 181 | - if ( ! empty( $attributes['footerColorH'] ) ) { | |
| 182 | - $css['background'] = $attributes['footerColorH'] . ' !important'; | |
| 183 | - } | |
| 233 | + | |
| 234 | + $css['background'] = Color::get_css( | |
| 235 | + isset( $attributes['footerColorH'] ) ? $attributes['footerColorH'] : '') . ' !important'; | |
| 184 | 236 | |
| 185 | 237 | return $css; |
| 186 | 238 | } |
| 187 | 239 | } |