class-do-css.php
6 years ago
class-enqueue-css.php
6 years ago
class-plugin-update.php
6 years ago
class-settings.php
6 years ago
dashboard.php
6 years ago
defaults.php
6 years ago
functions.php
6 years ago
general.php
6 years ago
generate-css.php
6 years ago
generate-css.php
1341 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Output our dynamic CSS. |
| 4 | * |
| 5 | * @package GenerateBlocks |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Build the CSS from our block attributes. |
| 14 | * |
| 15 | * @since 0.1 |
| 16 | * @param string $content The content we're looking through. |
| 17 | * |
| 18 | * @return string The dynamic CSS. |
| 19 | */ |
| 20 | function generateblocks_get_dynamic_css( $content = '' ) { |
| 21 | if ( ! $content ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $data = generateblocks_get_block_data( $content ); |
| 26 | |
| 27 | if ( empty( $data ) ) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | $blocks_exist = false; |
| 32 | $icon_css_added = false; |
| 33 | $main_css_data = array(); |
| 34 | $tablet_css_data = array(); |
| 35 | $mobile_css_data = array(); |
| 36 | |
| 37 | foreach ( $data as $name => $blockData ) { |
| 38 | /** |
| 39 | * Get our Grid block CSS. |
| 40 | * |
| 41 | * @since 0.1 |
| 42 | */ |
| 43 | if ( 'grid' === $name ) { |
| 44 | if ( empty( $blockData ) ) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $blocks_exist = true; |
| 49 | |
| 50 | $css = new GenerateBlocks_Dynamic_CSS(); |
| 51 | $tablet_css = new GenerateBlocks_Dynamic_CSS(); |
| 52 | $mobile_css = new GenerateBlocks_Dynamic_CSS(); |
| 53 | |
| 54 | $css->set_selector( '.gb-grid-wrapper' ); |
| 55 | $css->add_property( 'display', '-webkit-box' ); |
| 56 | $css->add_property( 'display', '-ms-flexbox' ); |
| 57 | $css->add_property( 'display', 'flex' ); |
| 58 | $css->add_property( '-ms-flex-wrap', 'wrap' ); |
| 59 | $css->add_property( 'flex-wrap', 'wrap' ); |
| 60 | |
| 61 | $css->set_selector( '.gb-grid-wrapper > .gb-grid-column > .gb-container' ); |
| 62 | $css->add_property( 'display', '-webkit-box' ); |
| 63 | $css->add_property( 'display', '-ms-flexbox' ); |
| 64 | $css->add_property( 'display', 'flex' ); |
| 65 | $css->add_property( '-ms-flex-direction', 'column' ); |
| 66 | $css->add_property( 'flex-direction', 'column' ); |
| 67 | $css->add_property( 'height', '100%' ); |
| 68 | |
| 69 | $css->set_selector( '.gb-grid-column' ); |
| 70 | $css->add_property( 'box-sizing', 'border-box' ); |
| 71 | |
| 72 | $css->set_selector( '.gb-grid-wrapper .wp-block-image' ); |
| 73 | $css->add_property( 'margin-bottom', '0px' ); |
| 74 | |
| 75 | foreach ( $blockData as $atts ) { |
| 76 | if ( ! isset( $atts['uniqueId'] ) ) { |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | $defaults = generateblocks_get_block_defaults(); |
| 81 | |
| 82 | $settings = wp_parse_args( |
| 83 | $atts, |
| 84 | $defaults['gridContainer'] |
| 85 | ); |
| 86 | |
| 87 | $id = $atts['uniqueId']; |
| 88 | |
| 89 | $css->set_selector( '.gb-grid-wrapper-' . $id ); |
| 90 | $css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignment'] ) ); |
| 91 | $css->add_property( 'align-items', $settings['verticalAlignment'] ); |
| 92 | $css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['horizontalAlignment'] ) ); |
| 93 | $css->add_property( 'justify-content', $settings['horizontalAlignment'] ); |
| 94 | |
| 95 | if ( $settings['horizontalGap'] ) { |
| 96 | $css->add_property( 'margin-left', '-' . $settings['horizontalGap'] . 'px' ); |
| 97 | } |
| 98 | |
| 99 | $css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' ); |
| 100 | $css->add_property( 'padding-left', $settings['horizontalGap'], 'px' ); |
| 101 | $css->add_property( 'padding-bottom', $settings['verticalGap'], 'px' ); |
| 102 | |
| 103 | $tablet_css->set_selector( '.gb-grid-wrapper-' . $id ); |
| 104 | |
| 105 | if ( 'inherit' !== $settings['verticalAlignmentTablet'] ) { |
| 106 | $tablet_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentTablet'] ) ); |
| 107 | $tablet_css->add_property( 'align-items', $settings['verticalAlignmentTablet'] ); |
| 108 | } |
| 109 | |
| 110 | if ( 'inherit' !== $settings['horizontalAlignmentTablet'] ) { |
| 111 | $tablet_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['horizontalAlignmentTablet'] ) ); |
| 112 | $tablet_css->add_property( 'justify-content', $settings['horizontalAlignmentTablet'] ); |
| 113 | } |
| 114 | |
| 115 | if ( $settings['horizontalGapTablet'] ) { |
| 116 | $tablet_css->add_property( 'margin-left', '-' . $settings['horizontalGapTablet'] . 'px' ); |
| 117 | } elseif ( 0 === $settings['horizontalGapTablet'] ) { |
| 118 | $tablet_css->add_property( 'margin-left', $settings['horizontalGapTablet'] ); |
| 119 | } |
| 120 | |
| 121 | $tablet_css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' ); |
| 122 | $tablet_css->add_property( 'padding-left', $settings['horizontalGapTablet'], 'px' ); |
| 123 | $tablet_css->add_property( 'padding-bottom', $settings['verticalGapTablet'], 'px' ); |
| 124 | |
| 125 | $mobile_css->set_selector( '.gb-grid-wrapper-' . $id ); |
| 126 | |
| 127 | if ( 'inherit' !== $settings['verticalAlignmentMobile'] ) { |
| 128 | $mobile_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentMobile'] ) ); |
| 129 | $mobile_css->add_property( 'align-items', $settings['verticalAlignmentMobile'] ); |
| 130 | } |
| 131 | |
| 132 | if ( 'inherit' !== $settings['horizontalAlignmentMobile'] ) { |
| 133 | $mobile_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['horizontalAlignmentMobile'] ) ); |
| 134 | $mobile_css->add_property( 'justify-content', $settings['horizontalAlignmentMobile'] ); |
| 135 | } |
| 136 | |
| 137 | if ( $settings['horizontalGapMobile'] ) { |
| 138 | $mobile_css->add_property( 'margin-left', '-' . $settings['horizontalGapMobile'] . 'px' ); |
| 139 | } elseif ( 0 === $settings['horizontalGapMobile'] ) { |
| 140 | $mobile_css->add_property( 'margin-left', $settings['horizontalGapMobile'] ); |
| 141 | } |
| 142 | |
| 143 | $mobile_css->set_selector( '.gb-grid-wrapper-' . $id . ' > .gb-grid-column' ); |
| 144 | $mobile_css->add_property( 'padding-left', $settings['horizontalGapMobile'], 'px' ); |
| 145 | $mobile_css->add_property( 'padding-bottom', $settings['verticalGapMobile'], 'px' ); |
| 146 | |
| 147 | /** |
| 148 | * Do generateblocks_block_css_data hook |
| 149 | * |
| 150 | * @since 1.0 |
| 151 | * |
| 152 | * @param object $css Our desktop/main CSS data. |
| 153 | * @param object $tablet_css Our tablet CSS data. |
| 154 | * @param object $mobile_css Our mobile CSS data. |
| 155 | * @param string $name The name of our block. |
| 156 | * @param array $settings The settings for the current block. |
| 157 | */ |
| 158 | do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings ); |
| 159 | } |
| 160 | |
| 161 | if ( $css->css_output() ) { |
| 162 | $main_css_data[] = $css->css_output(); |
| 163 | } |
| 164 | |
| 165 | if ( $tablet_css->css_output() ) { |
| 166 | $tablet_css_data[] = $tablet_css->css_output(); |
| 167 | } |
| 168 | |
| 169 | if ( $mobile_css->css_output() ) { |
| 170 | $mobile_css_data[] = $mobile_css->css_output(); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Get our Container block CSS. |
| 176 | * |
| 177 | * @since 0.1 |
| 178 | */ |
| 179 | if ( 'container' === $name ) { |
| 180 | if ( empty( $blockData ) ) { |
| 181 | continue; |
| 182 | } |
| 183 | |
| 184 | $blocks_exist = true; |
| 185 | |
| 186 | $css = new GenerateBlocks_Dynamic_CSS(); |
| 187 | $tablet_css = new GenerateBlocks_Dynamic_CSS(); |
| 188 | $mobile_css = new GenerateBlocks_Dynamic_CSS(); |
| 189 | |
| 190 | $css->set_selector( '.gb-container .wp-block-image img' ); |
| 191 | $css->add_property( 'vertical-align', 'middle' ); |
| 192 | |
| 193 | foreach ( $blockData as $atts ) { |
| 194 | if ( ! isset( $atts['uniqueId'] ) ) { |
| 195 | continue; |
| 196 | } |
| 197 | |
| 198 | $defaults = generateblocks_get_block_defaults(); |
| 199 | |
| 200 | $settings = wp_parse_args( |
| 201 | $atts, |
| 202 | $defaults['container'] |
| 203 | ); |
| 204 | |
| 205 | $id = $atts['uniqueId']; |
| 206 | |
| 207 | $grid_atts = array(); |
| 208 | |
| 209 | if ( isset( $atts['gridId'] ) && $atts['gridId'] ) { |
| 210 | foreach ( $data['grid'] as $grid ) { |
| 211 | if ( $atts['gridId'] === $grid['uniqueId'] ) { |
| 212 | $grid_atts = $grid; |
| 213 | break; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | $grid_settings = wp_parse_args( |
| 219 | $grid_atts, |
| 220 | $defaults['gridContainer'] |
| 221 | ); |
| 222 | |
| 223 | $fontFamily = $settings['fontFamily']; |
| 224 | |
| 225 | if ( $fontFamily && $settings['fontFamilyFallback'] ) { |
| 226 | $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback']; |
| 227 | } |
| 228 | |
| 229 | $css->set_selector( '.gb-container.gb-container-' . $id ); |
| 230 | $css->add_property( 'font-family', $fontFamily ); |
| 231 | $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] ); |
| 232 | $css->add_property( 'font-weight', $settings['fontWeight'] ); |
| 233 | $css->add_property( 'text-transform', $settings['textTransform'] ); |
| 234 | $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) ); |
| 235 | |
| 236 | if ( 'contained' === $settings['outerContainer'] && ! $settings['isGrid'] ) { |
| 237 | $css->add_property( 'max-width', absint( $settings['containerWidth'] ), 'px' ); |
| 238 | $css->add_property( 'margin-left', 'auto' ); |
| 239 | $css->add_property( 'margin-right', 'auto' ); |
| 240 | } |
| 241 | |
| 242 | $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) ); |
| 243 | $css->add_property( 'color', $settings['textColor'] ); |
| 244 | |
| 245 | if ( ! isset( $settings['bgOptions']['selector'] ) ) { |
| 246 | $settings['bgOptions']['selector'] = 'element'; |
| 247 | } |
| 248 | |
| 249 | $background_image = generateblocks_get_background_image_css( $settings ); |
| 250 | |
| 251 | if ( $settings['bgImage'] && 'element' === $settings['bgOptions']['selector'] && $background_image ) { |
| 252 | $css->add_property( 'background-image', $background_image ); |
| 253 | $css->add_property( 'background-repeat', $settings['bgOptions']['repeat'] ); |
| 254 | $css->add_property( 'background-position', $settings['bgOptions']['position'] ); |
| 255 | $css->add_property( 'background-size', $settings['bgOptions']['size'] ); |
| 256 | $css->add_property( 'background-attachment', $settings['bgOptions']['attachment'] ); |
| 257 | } elseif ( $settings['gradient'] && $background_image ) { |
| 258 | $css->add_property( 'background-image', $background_image ); |
| 259 | } |
| 260 | |
| 261 | if ( ( $settings['bgImage'] && 'pseudo-element' === $settings['bgOptions']['selector'] ) || $settings['zindex'] ) { |
| 262 | $css->add_property( 'position', 'relative' ); |
| 263 | } |
| 264 | |
| 265 | if ( $settings['bgImage'] && 'pseudo-element' === $settings['bgOptions']['selector'] ) { |
| 266 | $css->add_property( 'overflow', 'hidden' ); |
| 267 | } |
| 268 | |
| 269 | if ( $settings['zindex'] ) { |
| 270 | $css->add_property( 'z-index', $settings['zindex'] ); |
| 271 | } |
| 272 | |
| 273 | $css->add_property( 'border-radius', generateblocks_get_shorthand_css( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'], $settings['borderRadiusUnit'] ) ); |
| 274 | $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) ); |
| 275 | |
| 276 | if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) { |
| 277 | $css->add_property( 'border-style', 'solid' ); |
| 278 | } |
| 279 | |
| 280 | $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) ); |
| 281 | $css->add_property( 'min-height', $settings['minHeight'], $settings['minHeightUnit'] ); |
| 282 | |
| 283 | // Set flags so we don't duplicate this CSS in media queries. |
| 284 | $usingMinHeightFlex = false; |
| 285 | $usingMinHeightInnerWidth = false; |
| 286 | |
| 287 | if ( $settings['minHeight'] && $settings['verticalAlignment'] && ! $settings['isGrid'] ) { |
| 288 | $css->add_property( 'display', '-webkit-box' ); |
| 289 | $css->add_property( 'display', '-ms-flexbox' ); |
| 290 | $css->add_property( 'display', 'flex' ); |
| 291 | $css->add_property( '-ms-flex-direction', 'row' ); |
| 292 | $css->add_property( 'flex-direction', 'row' ); |
| 293 | $css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignment'] ) ); |
| 294 | $css->add_property( 'align-items', $settings['verticalAlignment'] ); |
| 295 | |
| 296 | $usingMinHeightFlex = true; |
| 297 | } |
| 298 | |
| 299 | $css->add_property( 'text-align', $settings['alignment'] ); |
| 300 | |
| 301 | $css->set_selector( '.gb-container.gb-container-' . $id . ':before' ); |
| 302 | |
| 303 | if ( $settings['bgImage'] && 'pseudo-element' === $settings['bgOptions']['selector'] ) { |
| 304 | $css->add_property( 'content', '""' ); |
| 305 | $css->add_property( 'background-image', 'url(' . $settings['bgImage']['image']['url'] . ')' ); |
| 306 | $css->add_property( 'background-repeat', $settings['bgOptions']['repeat'] ); |
| 307 | $css->add_property( 'background-position', $settings['bgOptions']['position'] ); |
| 308 | $css->add_property( 'background-size', $settings['bgOptions']['size'] ); |
| 309 | $css->add_property( 'background-attachment', $settings['bgOptions']['attachment'] ); |
| 310 | $css->add_property( 'z-index', '0' ); |
| 311 | $css->add_property( 'position', 'absolute' ); |
| 312 | $css->add_property( 'top', '0' ); |
| 313 | $css->add_property( 'right', '0' ); |
| 314 | $css->add_property( 'bottom', '0' ); |
| 315 | $css->add_property( 'left', '0' ); |
| 316 | $css->add_property( 'transition', 'inherit' ); |
| 317 | |
| 318 | if ( isset( $settings['bgOptions']['opacity'] ) && 1 !== $settings['bgOptions']['opacity'] ) { |
| 319 | $css->add_property( 'opacity', $settings['bgOptions']['opacity'] ); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | $css->set_selector( '.gb-container.gb-container-' . $id . ' > .gb-inside-container' ); |
| 324 | $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) ); |
| 325 | |
| 326 | if ( 'contained' === $settings['innerContainer'] && ! $settings['isGrid'] ) { |
| 327 | $css->add_property( 'max-width', absint( $settings['containerWidth'] ), 'px' ); |
| 328 | $css->add_property( 'margin-left', 'auto' ); |
| 329 | $css->add_property( 'margin-right', 'auto' ); |
| 330 | } |
| 331 | |
| 332 | if ( $usingMinHeightFlex ) { |
| 333 | $css->add_property( 'width', '100%' ); |
| 334 | |
| 335 | $usingMinHeightInnerWidth = true; |
| 336 | } |
| 337 | |
| 338 | if ( $settings['bgImage'] && 'pseudo-element' === $settings['bgOptions']['selector'] ) { |
| 339 | $css->add_property( 'z-index', '1' ); |
| 340 | $css->add_property( 'position', 'relative' ); |
| 341 | } |
| 342 | |
| 343 | $css->set_selector( '.gb-container.gb-container-' . $id . ' a, .gb-container.gb-container-' . $id . ' a:visited' ); |
| 344 | $css->add_property( 'color', $settings['linkColor'] ); |
| 345 | |
| 346 | $css->set_selector( '.gb-container.gb-container-' . $id . ' a:hover' ); |
| 347 | $css->add_property( 'color', $settings['linkColorHover'] ); |
| 348 | |
| 349 | if ( $settings['isGrid'] ) { |
| 350 | $css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id ); |
| 351 | $css->add_property( 'width', $settings['width'], '%' ); |
| 352 | } |
| 353 | |
| 354 | if ( $settings['removeVerticalGap'] ) { |
| 355 | $css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id ); |
| 356 | $css->add_property( 'padding-bottom', '0' ); |
| 357 | } |
| 358 | |
| 359 | $css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' ); |
| 360 | $css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['verticalAlignment'] ) ); |
| 361 | $css->add_property( 'justify-content', $settings['verticalAlignment'] ); |
| 362 | |
| 363 | $tablet_css->set_selector( '.gb-container.gb-container-' . $id ); |
| 364 | $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] ); |
| 365 | $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] ); |
| 366 | $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] ); |
| 367 | $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' ); |
| 368 | |
| 369 | if ( $settings['borderSizeTopTablet'] || $settings['borderSizeRightTablet'] || $settings['borderSizeBottomTablet'] || $settings['borderSizeLeftTablet'] ) { |
| 370 | $tablet_css->add_property( 'border-style', 'solid' ); |
| 371 | } |
| 372 | |
| 373 | $tablet_css->add_property( 'min-height', $settings['minHeightTablet'], $settings['minHeightUnitTablet'] ); |
| 374 | |
| 375 | if ( ! $settings['isGrid'] ) { |
| 376 | if ( ! $usingMinHeightFlex && $settings['minHeightTablet'] && 'inherit' !== $settings['verticalAlignmentTablet'] ) { |
| 377 | $tablet_css->add_property( 'display', '-webkit-box' ); |
| 378 | $tablet_css->add_property( 'display', '-ms-flexbox' ); |
| 379 | $tablet_css->add_property( 'display', 'flex' ); |
| 380 | $tablet_css->add_property( '-ms-flex-direction', 'row' ); |
| 381 | $tablet_css->add_property( 'flex-direction', 'row' ); |
| 382 | |
| 383 | $usingMinHeightFlex = true; |
| 384 | } |
| 385 | |
| 386 | if ( $usingMinHeightFlex && 'inherit' !== $settings['verticalAlignmentTablet'] ) { |
| 387 | $tablet_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentTablet'] ) ); |
| 388 | $tablet_css->add_property( 'align-items', $settings['verticalAlignmentTablet'] ); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] ); |
| 393 | |
| 394 | $tablet_css->set_selector( '.gb-container.gb-container-' . $id . ' > .gb-inside-container' ); |
| 395 | $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] ); |
| 396 | |
| 397 | $usingMinHeightInnerWidthBoxSizing = false; |
| 398 | |
| 399 | if ( ! $settings['isGrid'] ) { |
| 400 | // Needs 100% width if it's a flex item. |
| 401 | if ( ! $usingMinHeightInnerWidth && $settings['minHeightTablet'] && 'inherit' !== $settings['verticalAlignmentTablet'] ) { |
| 402 | $tablet_css->add_property( 'width', '100%' ); |
| 403 | |
| 404 | $usingMinHeightInnerWidth = true; |
| 405 | } elseif ( $usingMinHeightInnerWidth ) { |
| 406 | if ( 'contained' === $settings['innerContainer'] && ! $settings['isGrid'] ) { |
| 407 | $tablet_css->add_property( 'box-sizing', 'border-box' ); |
| 408 | |
| 409 | $usingMinHeightInnerWidthBoxSizing = true; |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | $tablet_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id ); |
| 415 | $tablet_css->add_property( 'width', $settings['widthTablet'], '%' ); |
| 416 | |
| 417 | if ( $settings['isGrid'] ) { |
| 418 | $tablet_css->add_property( '-ms-flex-order', $settings['orderTablet'] ); |
| 419 | $tablet_css->add_property( 'order', $settings['orderTablet'] ); |
| 420 | } |
| 421 | |
| 422 | if ( $settings['removeVerticalGapTablet'] ) { |
| 423 | if ( ! $settings['removeVerticalGap'] ) { |
| 424 | $tablet_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id ); |
| 425 | $tablet_css->add_property( 'padding-bottom', '0' ); |
| 426 | } |
| 427 | } elseif ( $settings['removeVerticalGap'] ) { |
| 428 | // Removed vertical gap on desktop, so we need to add it back here. |
| 429 | $vertical_gap_added = false; |
| 430 | |
| 431 | if ( ! empty( $grid_settings ) ) { |
| 432 | $tablet_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id ); |
| 433 | |
| 434 | if ( isset( $grid_settings['verticalGapTablet'] ) || isset( $grid_settings['verticalGap'] ) ) { |
| 435 | if ( ! empty( $grid_settings['verticalGapTablet'] ) ) { |
| 436 | $tablet_css->add_property( 'padding-bottom', $grid_settings['verticalGapTablet'], 'px' ); |
| 437 | $vertical_gap_added = true; |
| 438 | } elseif ( ! empty( $grid_settings['verticalGap'] ) ) { |
| 439 | $tablet_css->add_property( 'padding-bottom', $grid_settings['verticalGap'], 'px' ); |
| 440 | $vertical_gap_added = true; |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | $tablet_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' ); |
| 447 | |
| 448 | if ( 'inherit' !== $settings['verticalAlignmentTablet'] ) { |
| 449 | $tablet_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['verticalAlignmentTablet'] ) ); |
| 450 | $tablet_css->add_property( 'justify-content', $settings['verticalAlignmentTablet'] ); |
| 451 | } |
| 452 | |
| 453 | $mobile_css->set_selector( '.gb-container.gb-container-' . $id ); |
| 454 | $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] ); |
| 455 | $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] ); |
| 456 | $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftMobile'], $settings['borderRadiusTopRightMobile'], $settings['borderRadiusBottomRightMobile'], $settings['borderRadiusBottomLeftMobile'] ), $settings['borderRadiusUnit'] ); |
| 457 | $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' ); |
| 458 | |
| 459 | if ( $settings['borderSizeTopMobile'] || $settings['borderSizeRightMobile'] || $settings['borderSizeBottomMobile'] || $settings['borderSizeLeftMobile'] ) { |
| 460 | $mobile_css->add_property( 'border-style', 'solid' ); |
| 461 | } |
| 462 | |
| 463 | $mobile_css->add_property( 'min-height', $settings['minHeightMobile'], $settings['minHeightUnitMobile'] ); |
| 464 | |
| 465 | if ( ! $settings['isGrid'] ) { |
| 466 | if ( ! $usingMinHeightFlex && $settings['minHeightMobile'] && 'inherit' !== $settings['verticalAlignmentMobile'] ) { |
| 467 | $mobile_css->add_property( 'display', '-webkit-box' ); |
| 468 | $mobile_css->add_property( 'display', '-ms-flexbox' ); |
| 469 | $mobile_css->add_property( 'display', 'flex' ); |
| 470 | $mobile_css->add_property( '-ms-flex-direction', 'row' ); |
| 471 | $mobile_css->add_property( 'flex-direction', 'row' ); |
| 472 | |
| 473 | $usingMinHeightFlex = true; |
| 474 | } |
| 475 | |
| 476 | if ( $usingMinHeightFlex && 'inherit' !== $settings['verticalAlignmentMobile'] ) { |
| 477 | $mobile_css->add_property( '-ms-flex-align', generateblocks_get_vendor_prefix( $settings['verticalAlignmentMobile'] ) ); |
| 478 | $mobile_css->add_property( 'align-items', $settings['verticalAlignmentMobile'] ); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] ); |
| 483 | |
| 484 | $mobile_css->set_selector( '.gb-container.gb-container-' . $id . ' > .gb-inside-container' ); |
| 485 | $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] ); |
| 486 | |
| 487 | if ( ! $settings['isGrid'] ) { |
| 488 | // Needs 100% width if it's a flex item. |
| 489 | if ( ! $usingMinHeightInnerWidth && $settings['minHeightMobile'] && 'inherit' !== $settings['verticalAlignmentMobile'] ) { |
| 490 | $mobile_css->add_property( 'width', '100%' ); |
| 491 | } elseif ( $usingMinHeightInnerWidth && ! $usingMinHeightInnerWidthBoxSizing ) { |
| 492 | if ( 'contained' === $settings['innerContainer'] && ! $settings['isGrid'] ) { |
| 493 | $mobile_css->add_property( 'box-sizing', 'border-box' ); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | $mobile_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id ); |
| 499 | |
| 500 | if ( 100 !== $settings['widthMobile'] ) { |
| 501 | $mobile_css->add_property( 'width', $settings['widthMobile'], '%' ); |
| 502 | } |
| 503 | |
| 504 | if ( $settings['isGrid'] ) { |
| 505 | $mobile_css->add_property( '-ms-flex-order', $settings['orderMobile'] ); |
| 506 | $mobile_css->add_property( 'order', $settings['orderMobile'] ); |
| 507 | } |
| 508 | |
| 509 | if ( $settings['removeVerticalGapMobile'] ) { |
| 510 | if ( ! $settings['removeVerticalGapTablet'] ) { |
| 511 | $mobile_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id ); |
| 512 | $mobile_css->add_property( 'padding-bottom', '0' ); |
| 513 | } |
| 514 | } elseif ( $settings['removeVerticalGapTablet'] || $settings['removeVerticalGap'] ) { |
| 515 | // Removed vertical gap on tablet or desktop, so we need to add it back here. |
| 516 | if ( ! empty( $grid_settings ) ) { |
| 517 | $mobile_css->set_selector( '.gb-grid-wrapper > div.gb-grid-column-' . $id ); |
| 518 | |
| 519 | if ( empty( $vertical_gap_added ) && ( isset( $grid_settings['verticalGapMobile'] ) || isset( $grid_settings['verticalGapTablet'] ) || isset( $grid_settings['verticalGap'] ) ) ) { |
| 520 | if ( ! empty( $grid_settings['verticalGapMobile'] ) ) { |
| 521 | $mobile_css->add_property( 'padding-bottom', $grid_settings['verticalGapMobile'], 'px' ); |
| 522 | } elseif ( ! empty( $grid_settings['verticalGapTablet'] ) ) { |
| 523 | $mobile_css->add_property( 'padding-bottom', $grid_settings['verticalGapTablet'], 'px' ); |
| 524 | } elseif ( ! empty( $grid_settings['verticalGap'] ) ) { |
| 525 | $mobile_css->add_property( 'padding-bottom', $grid_settings['verticalGap'], 'px' ); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | $vertical_gap_added = false; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | $mobile_css->set_selector( '.gb-grid-wrapper > .gb-grid-column-' . $id . ' > .gb-container' ); |
| 534 | |
| 535 | if ( 'inherit' !== $settings['verticalAlignmentMobile'] ) { |
| 536 | $mobile_css->add_property( '-ms-flex-pack', generateblocks_get_vendor_prefix( $settings['verticalAlignmentMobile'] ) ); |
| 537 | $mobile_css->add_property( 'justify-content', $settings['verticalAlignmentMobile'] ); |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * Do generateblocks_block_css_data hook |
| 542 | * |
| 543 | * @since 1.0 |
| 544 | * |
| 545 | * @param object $css Our desktop/main CSS data. |
| 546 | * @param object $tablet_css Our tablet CSS data. |
| 547 | * @param object $mobile_css Our mobile CSS data. |
| 548 | * @param string $name The name of our block. |
| 549 | * @param array $settings The settings for the current block. |
| 550 | */ |
| 551 | do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings ); |
| 552 | } |
| 553 | |
| 554 | if ( $css->css_output() ) { |
| 555 | $main_css_data[] = $css->css_output(); |
| 556 | } |
| 557 | |
| 558 | if ( $tablet_css->css_output() ) { |
| 559 | $tablet_css_data[] = $tablet_css->css_output(); |
| 560 | } |
| 561 | |
| 562 | if ( $mobile_css->css_output() ) { |
| 563 | $mobile_css_data[] = $mobile_css->css_output(); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Get our Button Container block CSS. |
| 569 | * |
| 570 | * @since 0.1 |
| 571 | */ |
| 572 | if ( 'button-container' === $name ) { |
| 573 | if ( empty( $blockData ) ) { |
| 574 | continue; |
| 575 | } |
| 576 | |
| 577 | $blocks_exist = true; |
| 578 | |
| 579 | $css = new GenerateBlocks_Dynamic_CSS(); |
| 580 | $tablet_css = new GenerateBlocks_Dynamic_CSS(); |
| 581 | $mobile_css = new GenerateBlocks_Dynamic_CSS(); |
| 582 | |
| 583 | $css->set_selector( '.gb-button-wrapper' ); |
| 584 | $css->add_property( 'display', 'flex' ); |
| 585 | $css->add_property( 'flex-wrap', 'wrap' ); |
| 586 | $css->add_property( 'align-items', 'flex-start' ); |
| 587 | $css->add_property( 'justify-content', 'flex-start' ); |
| 588 | $css->add_property( 'clear', 'both' ); |
| 589 | |
| 590 | foreach ( $blockData as $atts ) { |
| 591 | if ( ! isset( $atts['uniqueId'] ) ) { |
| 592 | continue; |
| 593 | } |
| 594 | |
| 595 | $defaults = generateblocks_get_block_defaults(); |
| 596 | |
| 597 | $settings = wp_parse_args( |
| 598 | $atts, |
| 599 | $defaults['buttonContainer'] |
| 600 | ); |
| 601 | |
| 602 | $id = $atts['uniqueId']; |
| 603 | |
| 604 | $css->set_selector( '.gb-button-wrapper-' . $id ); |
| 605 | $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) ); |
| 606 | $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) ); |
| 607 | |
| 608 | if ( $settings['stack'] ) { |
| 609 | $css->add_property( '-ms-flex-direction', 'column' ); |
| 610 | $css->add_property( 'flex-direction', 'column' ); |
| 611 | $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignment'] ) ); |
| 612 | } |
| 613 | |
| 614 | if ( $settings['fillHorizontalSpace'] ) { |
| 615 | $css->set_selector( '.gb-button-wrapper-' . $id . ' > a' ); |
| 616 | $css->add_property( '-webkit-box-flex', '1' ); |
| 617 | $css->add_property( '-ms-flex', '1' ); |
| 618 | $css->add_property( 'flex', '1' ); |
| 619 | } |
| 620 | |
| 621 | if ( $settings['stack'] && $settings['fillHorizontalSpace'] ) { |
| 622 | $css->add_property( 'width', '100%' ); |
| 623 | $css->add_property( 'box-sizing', 'border-box' ); |
| 624 | } |
| 625 | |
| 626 | $tablet_css->set_selector( '.gb-button-wrapper-' . $id ); |
| 627 | $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] ); |
| 628 | $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) ); |
| 629 | |
| 630 | if ( $settings['stackTablet'] ) { |
| 631 | $tablet_css->add_property( '-ms-flex-direction', 'column' ); |
| 632 | $tablet_css->add_property( 'flex-direction', 'column' ); |
| 633 | $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) ); |
| 634 | } |
| 635 | |
| 636 | if ( $settings['fillHorizontalSpaceTablet'] ) { |
| 637 | $tablet_css->set_selector( '.gb-button-wrapper-' . $id . ' > a' ); |
| 638 | $tablet_css->add_property( '-webkit-box-flex', '1' ); |
| 639 | $tablet_css->add_property( '-ms-flex', '1' ); |
| 640 | $tablet_css->add_property( 'flex', '1' ); |
| 641 | } |
| 642 | |
| 643 | if ( $settings['stackTablet'] && $settings['fillHorizontalSpaceTablet'] ) { |
| 644 | $tablet_css->add_property( 'width', '100%' ); |
| 645 | $tablet_css->add_property( 'box-sizing', 'border-box' ); |
| 646 | } |
| 647 | |
| 648 | $mobile_css->set_selector( '.gb-button-wrapper-' . $id ); |
| 649 | $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] ); |
| 650 | $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) ); |
| 651 | |
| 652 | if ( $settings['stackMobile'] ) { |
| 653 | $mobile_css->add_property( '-ms-flex-direction', 'column' ); |
| 654 | $mobile_css->add_property( 'flex-direction', 'column' ); |
| 655 | $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) ); |
| 656 | } |
| 657 | |
| 658 | if ( $settings['fillHorizontalSpaceMobile'] ) { |
| 659 | $mobile_css->set_selector( '.gb-button-wrapper-' . $id . ' > a' ); |
| 660 | $mobile_css->add_property( '-webkit-box-flex', '1' ); |
| 661 | $mobile_css->add_property( '-ms-flex', '1' ); |
| 662 | $mobile_css->add_property( 'flex', '1' ); |
| 663 | } |
| 664 | |
| 665 | if ( $settings['stackMobile'] && $settings['fillHorizontalSpaceMobile'] ) { |
| 666 | $mobile_css->add_property( 'width', '100%' ); |
| 667 | $mobile_css->add_property( 'box-sizing', 'border-box' ); |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Do generateblocks_block_css_data hook |
| 672 | * |
| 673 | * @since 1.0 |
| 674 | * |
| 675 | * @param object $css Our desktop/main CSS data. |
| 676 | * @param object $tablet_css Our tablet CSS data. |
| 677 | * @param object $mobile_css Our mobile CSS data. |
| 678 | * @param string $name The name of our block. |
| 679 | * @param array $settings The settings for the current block. |
| 680 | */ |
| 681 | do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings ); |
| 682 | } |
| 683 | |
| 684 | if ( $css->css_output() ) { |
| 685 | $main_css_data[] = $css->css_output(); |
| 686 | } |
| 687 | |
| 688 | if ( $tablet_css->css_output() ) { |
| 689 | $tablet_css_data[] = $tablet_css->css_output(); |
| 690 | } |
| 691 | |
| 692 | if ( $mobile_css->css_output() ) { |
| 693 | $mobile_css_data[] = $mobile_css->css_output(); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | /** |
| 698 | * Get our Button block CSS. |
| 699 | * |
| 700 | * @since 0.1 |
| 701 | */ |
| 702 | if ( 'button' === $name ) { |
| 703 | if ( empty( $blockData ) ) { |
| 704 | continue; |
| 705 | } |
| 706 | |
| 707 | $blocks_exist = true; |
| 708 | |
| 709 | $css = new GenerateBlocks_Dynamic_CSS(); |
| 710 | $tablet_css = new GenerateBlocks_Dynamic_CSS(); |
| 711 | $mobile_css = new GenerateBlocks_Dynamic_CSS(); |
| 712 | |
| 713 | if ( ! $icon_css_added ) { |
| 714 | $css->set_selector( '.gb-icon' ); |
| 715 | $css->add_property( 'display', '-webkit-inline-box' ); |
| 716 | $css->add_property( 'display', '-ms-inline-flexbox' ); |
| 717 | $css->add_property( 'display', 'inline-flex' ); |
| 718 | $css->add_property( 'line-height', '0' ); |
| 719 | |
| 720 | $css->set_selector( '.gb-icon svg' ); |
| 721 | $css->add_property( 'height', '1em' ); |
| 722 | $css->add_property( 'width', '1em' ); |
| 723 | $css->add_property( 'fill', 'currentColor' ); |
| 724 | |
| 725 | $icon_css_added = true; |
| 726 | } |
| 727 | |
| 728 | $css->set_selector( '.gb-button-wrapper a.gb-button' ); |
| 729 | $css->add_property( 'display', '-webkit-inline-box' ); |
| 730 | $css->add_property( 'display', '-ms-inline-flexbox' ); |
| 731 | $css->add_property( 'display', 'inline-flex' ); |
| 732 | $css->add_property( 'align-items', 'center' ); |
| 733 | $css->add_property( 'justify-content', 'center' ); |
| 734 | $css->add_property( 'text-align', 'center' ); |
| 735 | $css->add_property( 'text-decoration', 'none' ); |
| 736 | $css->add_property( 'transition', '.2s background-color ease-in-out, .2s color ease-in-out, .2s border-color ease-in-out, .2s opacity ease-in-out, .2s box-shadow ease-in-out' ); |
| 737 | |
| 738 | $css->set_selector( '.gb-button-wrapper .gb-button .gb-icon' ); |
| 739 | $css->add_property( 'align-items', 'center' ); |
| 740 | |
| 741 | foreach ( $blockData as $atts ) { |
| 742 | if ( ! isset( $atts['uniqueId'] ) ) { |
| 743 | continue; |
| 744 | } |
| 745 | |
| 746 | $defaults = generateblocks_get_block_defaults(); |
| 747 | |
| 748 | $settings = wp_parse_args( |
| 749 | $atts, |
| 750 | $defaults['button'] |
| 751 | ); |
| 752 | |
| 753 | $id = $atts['uniqueId']; |
| 754 | |
| 755 | // Back-compatibility for when icon held a value. |
| 756 | if ( $settings['icon'] ) { |
| 757 | $settings['hasIcon'] = true; |
| 758 | } |
| 759 | |
| 760 | $fontFamily = $settings['fontFamily']; |
| 761 | |
| 762 | if ( $fontFamily && $settings['fontFamilyFallback'] ) { |
| 763 | $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback']; |
| 764 | } |
| 765 | |
| 766 | $gradientColorStopOneValue = ''; |
| 767 | $gradientColorStopTwoValue = ''; |
| 768 | |
| 769 | if ( $settings['gradient'] ) { |
| 770 | if ( $settings['gradientColorOne'] && '' !== $settings['gradientColorStopOne'] ) { |
| 771 | $gradientColorStopOneValue = ' ' . $settings['gradientColorStopOne'] . '%'; |
| 772 | } |
| 773 | |
| 774 | if ( $settings['gradientColorTwo'] && '' !== $settings['gradientColorStopTwo'] ) { |
| 775 | $gradientColorStopTwoValue = ' ' . $settings['gradientColorStopTwo'] . '%'; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | $css->set_selector( '.gb-button-wrapper a.gb-button-' . $id . ',.gb-button-wrapper a.gb-button-' . $id . ':visited' ); |
| 780 | $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) ); |
| 781 | $css->add_property( 'color', $settings['textColor'] ); |
| 782 | |
| 783 | if ( $settings['gradient'] ) { |
| 784 | $css->add_property( 'background-image', 'linear-gradient(' . $settings['gradientDirection'] . 'deg, ' . generateblocks_hex2rgba( $settings['gradientColorOne'], $settings['gradientColorOneOpacity'] ) . $gradientColorStopOneValue . ', ' . generateblocks_hex2rgba( $settings['gradientColorTwo'], $settings['gradientColorTwoOpacity'] ) . $gradientColorStopTwoValue . ')' ); |
| 785 | } |
| 786 | |
| 787 | $css->add_property( 'font-family', $fontFamily ); |
| 788 | $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] ); |
| 789 | $css->add_property( 'font-weight', $settings['fontWeight'] ); |
| 790 | $css->add_property( 'text-transform', $settings['textTransform'] ); |
| 791 | $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' ); |
| 792 | $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) ); |
| 793 | $css->add_property( 'border-radius', generateblocks_get_shorthand_css( $settings['borderRadiusTopLeft'], $settings['borderRadiusTopRight'], $settings['borderRadiusBottomRight'], $settings['borderRadiusBottomLeft'], $settings['borderRadiusUnit'] ) ); |
| 794 | $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) ); |
| 795 | $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) ); |
| 796 | |
| 797 | if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) { |
| 798 | $css->add_property( 'border-style', 'solid' ); |
| 799 | } |
| 800 | |
| 801 | $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) ); |
| 802 | $css->add_property( 'text-transform', $settings['textTransform'] ); |
| 803 | |
| 804 | if ( $settings['hasIcon'] ) { |
| 805 | $css->add_property( 'display', '-webkit-inline-box' ); |
| 806 | $css->add_property( 'display', '-ms-inline-flexbox' ); |
| 807 | $css->add_property( 'display', 'inline-flex' ); |
| 808 | $css->add_property( 'align-items', 'center' ); |
| 809 | } |
| 810 | |
| 811 | $css->set_selector( '.gb-button-wrapper a.gb-button-' . $id . ':hover,.gb-button-wrapper a.gb-button-' . $id . ':active,.gb-button-wrapper a.gb-button-' . $id . ':focus' ); |
| 812 | $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColorHover'], $settings['backgroundColorHoverOpacity'] ) ); |
| 813 | $css->add_property( 'color', $settings['textColorHover'] ); |
| 814 | $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColorHover'], $settings['borderColorHoverOpacity'] ) ); |
| 815 | |
| 816 | if ( $settings['hasIcon'] ) { |
| 817 | $css->set_selector( 'a.gb-button-' . $id . ' .gb-icon' ); |
| 818 | $css->add_property( 'font-size', $settings['iconSize'], $settings['iconSizeUnit'] ); |
| 819 | |
| 820 | if ( ! $settings['removeText'] ) { |
| 821 | $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'], $settings['iconPaddingUnit'] ) ); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | $tablet_css->set_selector( '.gb-button-wrapper a.gb-button-' . $id ); |
| 826 | $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] ); |
| 827 | $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' ); |
| 828 | $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] ); |
| 829 | $tablet_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] ); |
| 830 | $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] ); |
| 831 | $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' ); |
| 832 | |
| 833 | if ( $settings['hasIcon'] ) { |
| 834 | $tablet_css->set_selector( 'a.gb-button-' . $id . ' .gb-icon' ); |
| 835 | $tablet_css->add_property( 'font-size', $settings['iconSizeTablet'], $settings['iconSizeUnit'] ); |
| 836 | |
| 837 | if ( ! $settings['removeText'] ) { |
| 838 | $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] ); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | $mobile_css->set_selector( '.gb-button-wrapper a.gb-button-' . $id ); |
| 843 | $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] ); |
| 844 | $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' ); |
| 845 | $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] ); |
| 846 | $mobile_css->add_property( 'border-radius', array( $settings['borderRadiusTopLeftTablet'], $settings['borderRadiusTopRightTablet'], $settings['borderRadiusBottomRightTablet'], $settings['borderRadiusBottomLeftTablet'] ), $settings['borderRadiusUnit'] ); |
| 847 | $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] ); |
| 848 | $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' ); |
| 849 | |
| 850 | if ( $settings['hasIcon'] ) { |
| 851 | $mobile_css->set_selector( 'a.gb-button-' . $id . ' .gb-icon' ); |
| 852 | $mobile_css->add_property( 'font-size', $settings['iconSizeMobile'], $settings['iconSizeUnit'] ); |
| 853 | |
| 854 | if ( ! $settings['removeText'] ) { |
| 855 | $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] ); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * Do generateblocks_block_css_data hook |
| 861 | * |
| 862 | * @since 1.0 |
| 863 | * |
| 864 | * @param object $css Our desktop/main CSS data. |
| 865 | * @param object $tablet_css Our tablet CSS data. |
| 866 | * @param object $mobile_css Our mobile CSS data. |
| 867 | * @param string $name The name of our block. |
| 868 | * @param array $settings The settings for the current block. |
| 869 | */ |
| 870 | do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings ); |
| 871 | } |
| 872 | |
| 873 | if ( $css->css_output() ) { |
| 874 | $main_css_data[] = $css->css_output(); |
| 875 | } |
| 876 | |
| 877 | if ( $tablet_css->css_output() ) { |
| 878 | $tablet_css_data[] = $tablet_css->css_output(); |
| 879 | } |
| 880 | |
| 881 | if ( $mobile_css->css_output() ) { |
| 882 | $mobile_css_data[] = $mobile_css->css_output(); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Get our Headline block CSS. |
| 888 | * |
| 889 | * @since 0.1 |
| 890 | */ |
| 891 | if ( 'headline' === $name ) { |
| 892 | if ( empty( $blockData ) ) { |
| 893 | continue; |
| 894 | } |
| 895 | |
| 896 | $blocks_exist = true; |
| 897 | |
| 898 | $css = new GenerateBlocks_Dynamic_CSS(); |
| 899 | $tablet_css = new GenerateBlocks_Dynamic_CSS(); |
| 900 | $mobile_css = new GenerateBlocks_Dynamic_CSS(); |
| 901 | |
| 902 | if ( ! $icon_css_added ) { |
| 903 | $css->set_selector( '.gb-icon' ); |
| 904 | $css->add_property( 'display', '-webkit-inline-box' ); |
| 905 | $css->add_property( 'display', '-ms-inline-flexbox' ); |
| 906 | $css->add_property( 'display', 'inline-flex' ); |
| 907 | $css->add_property( 'line-height', '0' ); |
| 908 | |
| 909 | $css->set_selector( '.gb-icon svg' ); |
| 910 | $css->add_property( 'height', '1em' ); |
| 911 | $css->add_property( 'width', '1em' ); |
| 912 | $css->add_property( 'fill', 'currentColor' ); |
| 913 | |
| 914 | $icon_css_added = true; |
| 915 | } |
| 916 | |
| 917 | $css->set_selector( '.gb-highlight' ); |
| 918 | $css->add_property( 'background', 'none' ); |
| 919 | $css->add_property( 'color', 'unset' ); |
| 920 | |
| 921 | $css->set_selector( '.gb-headline-wrapper' ); |
| 922 | $css->add_property( 'display', '-ms-flexbox' ); |
| 923 | $css->add_property( 'display', 'flex' ); |
| 924 | |
| 925 | $css->set_selector( '.gb-headline-wrapper > .gb-headline' ); |
| 926 | $css->add_property( 'margin', '0' ); |
| 927 | $css->add_property( 'padding', '0' ); |
| 928 | |
| 929 | foreach ( $blockData as $atts ) { |
| 930 | if ( ! isset( $atts['uniqueId'] ) ) { |
| 931 | continue; |
| 932 | } |
| 933 | |
| 934 | $defaults = generateblocks_get_block_defaults(); |
| 935 | |
| 936 | $settings = wp_parse_args( |
| 937 | $atts, |
| 938 | $defaults['headline'] |
| 939 | ); |
| 940 | |
| 941 | $id = $atts['uniqueId']; |
| 942 | |
| 943 | // Back-compatibility for when icon held a value. |
| 944 | if ( $settings['icon'] ) { |
| 945 | $settings['hasIcon'] = true; |
| 946 | } |
| 947 | |
| 948 | $fontFamily = $settings['fontFamily']; |
| 949 | |
| 950 | if ( $fontFamily && $settings['fontFamilyFallback'] ) { |
| 951 | $fontFamily = $fontFamily . ', ' . $settings['fontFamilyFallback']; |
| 952 | } |
| 953 | |
| 954 | $css->set_selector( '.gb-headline-' . $id ); |
| 955 | $css->add_property( 'font-family', $fontFamily ); |
| 956 | $css->add_property( 'text-align', $settings['alignment'] ); |
| 957 | |
| 958 | $css->add_property( 'color', $settings['textColor'] ); |
| 959 | |
| 960 | if ( ! $settings['hasIcon'] ) { |
| 961 | $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) ); |
| 962 | |
| 963 | if ( $settings['inlineWidth'] ) { |
| 964 | $css->add_property( 'display', 'inline-block' ); |
| 965 | } |
| 966 | |
| 967 | $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) ); |
| 968 | |
| 969 | if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) { |
| 970 | $css->add_property( 'border-style', 'solid' ); |
| 971 | } |
| 972 | |
| 973 | $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) ); |
| 974 | } |
| 975 | |
| 976 | $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] ); |
| 977 | $css->add_property( 'font-weight', $settings['fontWeight'] ); |
| 978 | $css->add_property( 'text-transform', $settings['textTransform'] ); |
| 979 | $css->add_property( 'line-height', $settings['lineHeight'], $settings['lineHeightUnit'] ); |
| 980 | $css->add_property( 'letter-spacing', $settings['letterSpacing'], 'em' ); |
| 981 | |
| 982 | if ( ! $settings['hasIcon'] ) { |
| 983 | $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) ); |
| 984 | $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) ); |
| 985 | |
| 986 | if ( function_exists( 'generate_get_default_fonts' ) && '' === $settings['marginBottom'] ) { |
| 987 | $defaultBlockStyles = generateblocks_get_default_styles(); |
| 988 | |
| 989 | if ( isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) { |
| 990 | $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] ); |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | $css->set_selector( '.gb-headline-' . $id . ' a, .gb-headline-' . $id . ' a:visited' ); |
| 996 | $css->add_property( 'color', $settings['linkColor'] ); |
| 997 | |
| 998 | $css->set_selector( '.gb-headline-' . $id . ' a:hover' ); |
| 999 | $css->add_property( 'color', $settings['linkColorHover'] ); |
| 1000 | |
| 1001 | if ( $settings['hasIcon'] ) { |
| 1002 | $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' ); |
| 1003 | |
| 1004 | if ( ! $settings['removeText'] ) { |
| 1005 | $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['iconPaddingTop'], $settings['iconPaddingRight'], $settings['iconPaddingBottom'], $settings['iconPaddingLeft'], $settings['iconPaddingUnit'] ) ); |
| 1006 | } |
| 1007 | |
| 1008 | $css->add_property( 'color', generateblocks_hex2rgba( $settings['iconColor'], $settings['iconColorOpacity'] ) ); |
| 1009 | |
| 1010 | if ( 'above' === $settings['iconLocation'] ) { |
| 1011 | $css->add_property( 'display', 'inline' ); |
| 1012 | } |
| 1013 | |
| 1014 | $css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' ); |
| 1015 | $css->add_property( 'width', $settings['iconSize'], $settings['iconSizeUnit'] ); |
| 1016 | $css->add_property( 'height', $settings['iconSize'], $settings['iconSizeUnit'] ); |
| 1017 | |
| 1018 | $css->set_selector( '.gb-headline-wrapper-' . $id ); |
| 1019 | $css->add_property( 'padding', generateblocks_get_shorthand_css( $settings['paddingTop'], $settings['paddingRight'], $settings['paddingBottom'], $settings['paddingLeft'], $settings['paddingUnit'] ) ); |
| 1020 | $css->add_property( 'margin', generateblocks_get_shorthand_css( $settings['marginTop'], $settings['marginRight'], $settings['marginBottom'], $settings['marginLeft'], $settings['marginUnit'] ) ); |
| 1021 | |
| 1022 | $defaultBlockStyles = generateblocks_get_default_styles(); |
| 1023 | |
| 1024 | if ( '' === $settings['marginBottom'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'] ) ) { |
| 1025 | $css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottom'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] ); |
| 1026 | } |
| 1027 | |
| 1028 | if ( '' === $settings['fontSize'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'] ) ) { |
| 1029 | $css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSize'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] ); |
| 1030 | } else { |
| 1031 | $css->add_property( 'font-size', $settings['fontSize'], $settings['fontSizeUnit'] ); |
| 1032 | } |
| 1033 | |
| 1034 | if ( 'above' === $settings['iconLocation'] ) { |
| 1035 | $css->add_property( 'text-align', $settings['alignment'] ); |
| 1036 | } else { |
| 1037 | $css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignment'] ) ); |
| 1038 | } |
| 1039 | |
| 1040 | if ( $settings['inlineWidth'] ) { |
| 1041 | $css->add_property( 'display', '-webkit-inline-box' ); |
| 1042 | $css->add_property( 'display', '-ms-inline-flexbox' ); |
| 1043 | $css->add_property( 'display', 'inline-flex' ); |
| 1044 | } |
| 1045 | |
| 1046 | if ( 'inline' === $settings['iconLocation'] ) { |
| 1047 | $css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignment'] ) ); |
| 1048 | } |
| 1049 | |
| 1050 | $css->add_property( 'background-color', generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ) ); |
| 1051 | $css->add_property( 'color', $settings['textColor'] ); |
| 1052 | $css->add_property( 'border-width', generateblocks_get_shorthand_css( $settings['borderSizeTop'], $settings['borderSizeRight'], $settings['borderSizeBottom'], $settings['borderSizeLeft'], 'px' ) ); |
| 1053 | |
| 1054 | if ( $settings['borderSizeTop'] || $settings['borderSizeRight'] || $settings['borderSizeBottom'] || $settings['borderSizeLeft'] ) { |
| 1055 | $css->add_property( 'border-style', 'solid' ); |
| 1056 | } |
| 1057 | |
| 1058 | $css->add_property( 'border-color', generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) ); |
| 1059 | |
| 1060 | if ( 'above' === $settings['iconLocation'] ) { |
| 1061 | $css->add_property( '-ms-flex-direction', 'column' ); |
| 1062 | $css->add_property( 'flex-direction', 'column' ); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | if ( $settings['highlightTextColor'] ) { |
| 1067 | $css->set_selector( '.gb-headline-' . $id . ' .gb-highlight' ); |
| 1068 | $css->add_property( 'color', $settings['highlightTextColor'] ); |
| 1069 | } |
| 1070 | |
| 1071 | $tablet_css->set_selector( '.gb-headline-' . $id ); |
| 1072 | $tablet_css->add_property( 'text-align', $settings['alignmentTablet'] ); |
| 1073 | $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] ); |
| 1074 | $tablet_css->add_property( 'line-height', $settings['lineHeightTablet'], $settings['lineHeightUnit'] ); |
| 1075 | $tablet_css->add_property( 'letter-spacing', $settings['letterSpacingTablet'], 'em' ); |
| 1076 | |
| 1077 | if ( ! $settings['hasIcon'] ) { |
| 1078 | $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] ); |
| 1079 | $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] ); |
| 1080 | $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' ); |
| 1081 | |
| 1082 | if ( $settings['inlineWidthTablet'] ) { |
| 1083 | $tablet_css->add_property( 'display', '-webkit-inline-box' ); |
| 1084 | $tablet_css->add_property( 'display', '-ms-inline-flexbox' ); |
| 1085 | $tablet_css->add_property( 'display', 'inline-flex' ); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | if ( $settings['hasIcon'] ) { |
| 1090 | $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' ); |
| 1091 | |
| 1092 | if ( ! $settings['removeText'] ) { |
| 1093 | $tablet_css->add_property( 'padding', array( $settings['iconPaddingTopTablet'], $settings['iconPaddingRightTablet'], $settings['iconPaddingBottomTablet'], $settings['iconPaddingLeftTablet'] ), $settings['iconPaddingUnit'] ); |
| 1094 | } |
| 1095 | |
| 1096 | if ( 'above' === $settings['iconLocationTablet'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationTablet'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 1097 | $tablet_css->add_property( '-ms-flex-item-align', generateblocks_get_vendor_prefix( $settings['alignmentTablet'] ) ); |
| 1098 | $tablet_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) ); |
| 1099 | } |
| 1100 | |
| 1101 | $tablet_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' ); |
| 1102 | $tablet_css->add_property( 'width', $settings['iconSizeTablet'], $settings['iconSizeUnit'] ); |
| 1103 | $tablet_css->add_property( 'height', $settings['iconSizeTablet'], $settings['iconSizeUnit'] ); |
| 1104 | |
| 1105 | $tablet_css->set_selector( '.gb-headline-wrapper-' . $id ); |
| 1106 | $tablet_css->add_property( 'margin', array( $settings['marginTopTablet'], $settings['marginRightTablet'], $settings['marginBottomTablet'], $settings['marginLeftTablet'] ), $settings['marginUnit'] ); |
| 1107 | $tablet_css->add_property( 'padding', array( $settings['paddingTopTablet'], $settings['paddingRightTablet'], $settings['paddingBottomTablet'], $settings['paddingLeftTablet'] ), $settings['paddingUnit'] ); |
| 1108 | $tablet_css->add_property( 'border-width', array( $settings['borderSizeTopTablet'], $settings['borderSizeRightTablet'], $settings['borderSizeBottomTablet'], $settings['borderSizeLeftTablet'] ), 'px' ); |
| 1109 | $tablet_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentTablet'] ) ); |
| 1110 | |
| 1111 | $defaultBlockStyles = generateblocks_get_default_styles(); |
| 1112 | |
| 1113 | if ( '' === $settings['marginBottomTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'] ) ) { |
| 1114 | $tablet_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] ); |
| 1115 | } |
| 1116 | |
| 1117 | if ( '' === $settings['fontSizeTablet'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'] ) ) { |
| 1118 | $tablet_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeTablet'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] ); |
| 1119 | } else { |
| 1120 | $tablet_css->add_property( 'font-size', $settings['fontSizeTablet'], $settings['fontSizeUnit'] ); |
| 1121 | } |
| 1122 | |
| 1123 | if ( $settings['inlineWidthTablet'] ) { |
| 1124 | $tablet_css->add_property( 'display', '-webkit-inline-box' ); |
| 1125 | $tablet_css->add_property( 'display', '-ms-inline-flexbox' ); |
| 1126 | $tablet_css->add_property( 'display', 'inline-flex' ); |
| 1127 | } |
| 1128 | |
| 1129 | if ( 'inline' === $settings['iconLocationTablet'] ) { |
| 1130 | $tablet_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentTablet'] ) ); |
| 1131 | } |
| 1132 | |
| 1133 | if ( 'above' === $settings['iconLocationTablet'] ) { |
| 1134 | $tablet_css->add_property( '-ms-flex-direction', 'column' ); |
| 1135 | $tablet_css->add_property( 'flex-direction', 'column' ); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | $mobile_css->set_selector( '.gb-headline-' . $id ); |
| 1140 | $mobile_css->add_property( 'text-align', $settings['alignmentMobile'] ); |
| 1141 | $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] ); |
| 1142 | $mobile_css->add_property( 'line-height', $settings['lineHeightMobile'], $settings['lineHeightUnit'] ); |
| 1143 | $mobile_css->add_property( 'letter-spacing', $settings['letterSpacingMobile'], 'em' ); |
| 1144 | |
| 1145 | if ( ! $settings['hasIcon'] ) { |
| 1146 | $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] ); |
| 1147 | $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] ); |
| 1148 | $mobile_css->add_property( 'border-width', array( $settings['borderSizeTopMobile'], $settings['borderSizeRightMobile'], $settings['borderSizeBottomMobile'], $settings['borderSizeLeftMobile'] ), 'px' ); |
| 1149 | |
| 1150 | if ( $settings['inlineWidthMobile'] ) { |
| 1151 | $mobile_css->add_property( 'display', '-webkit-inline-box' ); |
| 1152 | $mobile_css->add_property( 'display', '-ms-inline-flexbox' ); |
| 1153 | $mobile_css->add_property( 'display', 'inline-flex' ); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | if ( $settings['hasIcon'] ) { |
| 1158 | $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon' ); |
| 1159 | |
| 1160 | if ( ! $settings['removeText'] ) { |
| 1161 | $mobile_css->add_property( 'padding', array( $settings['iconPaddingTopMobile'], $settings['iconPaddingRightMobile'], $settings['iconPaddingBottomMobile'], $settings['iconPaddingLeftMobile'] ), $settings['iconPaddingUnit'] ); |
| 1162 | } |
| 1163 | |
| 1164 | if ( 'above' === $settings['iconLocationMobile'] || ( 'above' === $settings['iconLocation'] && '' == $settings['iconLocationMobile'] ) || ( 'above' === $settings['iconLocationTablet'] && '' == $settings['iconLocationMobile'] ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 1165 | $mobile_css->add_property( '-ms-flex-item-align', generateblocks_get_vendor_prefix( $settings['alignmentMobile'] ) ); |
| 1166 | $mobile_css->add_property( 'align-self', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) ); |
| 1167 | } |
| 1168 | |
| 1169 | $mobile_css->set_selector( '.gb-headline-wrapper-' . $id . ' .gb-icon svg' ); |
| 1170 | $mobile_css->add_property( 'width', $settings['iconSizeMobile'], $settings['iconSizeUnit'] ); |
| 1171 | $mobile_css->add_property( 'height', $settings['iconSizeMobile'], $settings['iconSizeUnit'] ); |
| 1172 | |
| 1173 | $mobile_css->set_selector( '.gb-headline-wrapper-' . $id ); |
| 1174 | $mobile_css->add_property( 'margin', array( $settings['marginTopMobile'], $settings['marginRightMobile'], $settings['marginBottomMobile'], $settings['marginLeftMobile'] ), $settings['marginUnit'] ); |
| 1175 | $mobile_css->add_property( 'padding', array( $settings['paddingTopMobile'], $settings['paddingRightMobile'], $settings['paddingBottomMobile'], $settings['paddingLeftMobile'] ), $settings['paddingUnit'] ); |
| 1176 | $mobile_css->add_property( 'justify-content', generateblocks_get_flexbox_alignment( $settings['alignmentMobile'] ) ); |
| 1177 | |
| 1178 | $defaultBlockStyles = generateblocks_get_default_styles(); |
| 1179 | |
| 1180 | if ( '' === $settings['marginBottomMobile'] && ! $settings['removeText'] && isset( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) && is_numeric( $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'] ) ) { |
| 1181 | $mobile_css->add_property( 'margin-bottom', $defaultBlockStyles['headline'][ $settings['element'] ]['marginBottomMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['marginUnit'] ); |
| 1182 | } |
| 1183 | |
| 1184 | if ( '' === $settings['fontSizeMobile'] && ! $settings['removeText'] && ! empty( $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'] ) ) { |
| 1185 | $mobile_css->add_property( 'font-size', $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeMobile'], $defaultBlockStyles['headline'][ $settings['element'] ]['fontSizeUnit'] ); |
| 1186 | } else { |
| 1187 | $mobile_css->add_property( 'font-size', $settings['fontSizeMobile'], $settings['fontSizeUnit'] ); |
| 1188 | } |
| 1189 | |
| 1190 | if ( $settings['inlineWidthMobile'] ) { |
| 1191 | $mobile_css->add_property( 'display', '-webkit-inline-box' ); |
| 1192 | $mobile_css->add_property( 'display', '-ms-inline-flexbox' ); |
| 1193 | $mobile_css->add_property( 'display', 'inline-flex' ); |
| 1194 | } |
| 1195 | |
| 1196 | if ( 'inline' === $settings['iconLocationMobile'] ) { |
| 1197 | $mobile_css->add_property( 'align-items', generateblocks_get_flexbox_alignment( $settings['iconVerticalAlignmentMobile'] ) ); |
| 1198 | } |
| 1199 | |
| 1200 | if ( 'above' === $settings['iconLocationMobile'] ) { |
| 1201 | $mobile_css->add_property( '-ms-flex-direction', 'column' ); |
| 1202 | $mobile_css->add_property( 'flex-direction', 'column' ); |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * Do generateblocks_block_css_data hook |
| 1208 | * |
| 1209 | * @since 1.0 |
| 1210 | * |
| 1211 | * @param object $css Our desktop/main CSS data. |
| 1212 | * @param object $tablet_css Our tablet CSS data. |
| 1213 | * @param object $mobile_css Our mobile CSS data. |
| 1214 | * @param string $name The name of our block. |
| 1215 | * @param array $settings The settings for the current block. |
| 1216 | */ |
| 1217 | do_action( 'generateblocks_block_css_data', $css, $tablet_css, $mobile_css, $name, $settings ); |
| 1218 | } |
| 1219 | |
| 1220 | if ( $css->css_output() ) { |
| 1221 | $main_css_data[] = $css->css_output(); |
| 1222 | } |
| 1223 | |
| 1224 | if ( $tablet_css->css_output() ) { |
| 1225 | $tablet_css_data[] = $tablet_css->css_output(); |
| 1226 | } |
| 1227 | |
| 1228 | if ( $mobile_css->css_output() ) { |
| 1229 | $mobile_css_data[] = $mobile_css->css_output(); |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | if ( ! $blocks_exist ) { |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | return apply_filters( |
| 1239 | 'generateblocks_css_device_data', |
| 1240 | array( |
| 1241 | 'main' => $main_css_data, |
| 1242 | 'tablet' => $tablet_css_data, |
| 1243 | 'mobile' => $mobile_css_data, |
| 1244 | ), |
| 1245 | $settings |
| 1246 | ); |
| 1247 | } |
| 1248 | |
| 1249 | /** |
| 1250 | * Turn our CSS array into plain CSS. |
| 1251 | * |
| 1252 | * @since 1.0 |
| 1253 | * |
| 1254 | * @param array $data Our CSS data. |
| 1255 | */ |
| 1256 | function generateblocks_get_parsed_css( $data ) { |
| 1257 | $output = ''; |
| 1258 | |
| 1259 | foreach ( $data as $device => $selectors ) { |
| 1260 | foreach ( $selectors as $selector => $properties ) { |
| 1261 | if ( ! count( $properties ) ) { |
| 1262 | continue; |
| 1263 | } |
| 1264 | |
| 1265 | $temporary_output = $selector . '{'; |
| 1266 | $elements_added = 0; |
| 1267 | |
| 1268 | foreach ( $properties as $key => $value ) { |
| 1269 | if ( empty( $value ) ) { |
| 1270 | continue; |
| 1271 | } |
| 1272 | |
| 1273 | $elements_added++; |
| 1274 | $temporary_output .= $value; |
| 1275 | } |
| 1276 | |
| 1277 | $temporary_output .= '}'; |
| 1278 | |
| 1279 | if ( $elements_added > 0 ) { |
| 1280 | $output .= $temporary_output; |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | return $output; |
| 1286 | } |
| 1287 | |
| 1288 | /** |
| 1289 | * Print our CSS for each block. |
| 1290 | * |
| 1291 | * @since 0.1 |
| 1292 | */ |
| 1293 | function generateblocks_get_frontend_block_css() { |
| 1294 | if ( ! function_exists( 'has_blocks' ) ) { |
| 1295 | return; |
| 1296 | } |
| 1297 | |
| 1298 | $content = generateblocks_get_parsed_content(); |
| 1299 | |
| 1300 | if ( ! $content ) { |
| 1301 | return; |
| 1302 | } |
| 1303 | |
| 1304 | $data = generateblocks_get_dynamic_css( $content ); |
| 1305 | |
| 1306 | if ( ! $data ) { |
| 1307 | return; |
| 1308 | } |
| 1309 | |
| 1310 | $css = ''; |
| 1311 | |
| 1312 | $css .= generateblocks_get_parsed_css( $data['main'] ); |
| 1313 | |
| 1314 | if ( ! empty( $data['tablet'] ) ) { |
| 1315 | $css .= sprintf( |
| 1316 | '@media %1$s {%2$s}', |
| 1317 | generateblocks_get_media_query( 'tablet' ), |
| 1318 | generateblocks_get_parsed_css( $data['tablet'] ) |
| 1319 | ); |
| 1320 | } |
| 1321 | |
| 1322 | array_unshift( |
| 1323 | $data['mobile'], |
| 1324 | array( |
| 1325 | '.gb-grid-wrapper > .gb-grid-column' => array( |
| 1326 | 'width: 100%;', |
| 1327 | ), |
| 1328 | ) |
| 1329 | ); |
| 1330 | |
| 1331 | if ( ! empty( $data['mobile'] ) ) { |
| 1332 | $css .= sprintf( |
| 1333 | '@media %1$s {%2$s}', |
| 1334 | generateblocks_get_media_query( 'mobile' ), |
| 1335 | generateblocks_get_parsed_css( $data['mobile'] ) |
| 1336 | ); |
| 1337 | } |
| 1338 | |
| 1339 | return apply_filters( 'generateblocks_css_output', $css ); |
| 1340 | } |
| 1341 |