| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\ScrollToTop; |
| 3 |
|
| 4 |
use ABlocks\Controls\Icon; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
use ABlocks\Classes\BlockBaseAbstract; |
| 11 |
use ABlocks\Classes\CssGeneratorV2; |
| 12 |
use ABlocks\Helper; |
| 13 |
use ABlocks\Controls\Typography; |
| 14 |
use ABlocks\Controls\TextShadow; |
| 15 |
use ABlocks\Controls\TextStroke; |
| 16 |
use ABlocks\Controls\Alignment; |
| 17 |
use ABlocks\Controls\Color; |
| 18 |
use ABlocks\Controls\Border; |
| 19 |
use ABlocks\Controls\Dimensions; |
| 20 |
use ABlocks\Controls\Range; |
| 21 |
|
| 22 |
class Block extends BlockBaseAbstract { |
| 23 |
protected $block_name = 'scroll-to-top'; |
| 24 |
public function build_css( $attributes ) { |
| 25 |
$css_generator = new CssGeneratorV2( $attributes, $this->block_name ); |
| 26 |
$css_generator->add_class_styles( |
| 27 |
'{{WRAPPER}}', |
| 28 |
$this->get_wrapper_css( $attributes ), |
| 29 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 30 |
$this->get_wrapper_css( $attributes, 'Mobile' ) |
| 31 |
); |
| 32 |
$css_generator->add_class_styles( |
| 33 |
'{{WRAPPER}} .ablocks-scroll-to-top-button-text', |
| 34 |
$this->get_button_text_css( $attributes ), |
| 35 |
$this->get_button_text_css( $attributes, 'Tablet' ), |
| 36 |
$this->get_button_text_css( $attributes, 'Mobile' ) |
| 37 |
); |
| 38 |
$css_generator->add_class_styles( |
| 39 |
'{{WRAPPER}} .ablocks-scroll-to-top-button-text:hover', |
| 40 |
$this->get_button_text_hover_css( $attributes ), |
| 41 |
$this->get_button_text_hover_css( $attributes, 'Tablet' ), |
| 42 |
$this->get_button_text_hover_css( $attributes, 'Mobile' ) |
| 43 |
); |
| 44 |
$css_generator->add_class_styles( |
| 45 |
'{{WRAPPER}} .ablocks-icon-wrap', |
| 46 |
Icon::get_wrapper_css( $attributes ), |
| 47 |
Icon::get_wrapper_css( $attributes, 'Tablet' ), |
| 48 |
Icon::get_wrapper_css( $attributes, 'Mobile' ) |
| 49 |
); |
| 50 |
$css_generator->add_class_styles( |
| 51 |
'{{WRAPPER}} .ablocks-icon-wrap:hover', |
| 52 |
Icon::get_wrapper_hover_css( $attributes ), |
| 53 |
Icon::get_wrapper_hover_css( $attributes, 'Tablet' ), |
| 54 |
Icon::get_wrapper_hover_css( $attributes, 'Mobile' ) |
| 55 |
); |
| 56 |
|
| 57 |
$css_generator->add_class_styles( |
| 58 |
'{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon', |
| 59 |
Icon::get_element_image_css( $attributes ), |
| 60 |
Icon::get_element_image_css( $attributes, 'Tablet' ), |
| 61 |
Icon::get_element_image_css( $attributes, 'Mobile' ), |
| 62 |
); |
| 63 |
$css_generator->add_class_styles( |
| 64 |
'{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover', |
| 65 |
Icon::get_element_image_hover_css( $attributes ), |
| 66 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 67 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 68 |
); |
| 69 |
$css_generator->add_class_styles( |
| 70 |
'{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon', |
| 71 |
Icon::get_element_css( $attributes ), |
| 72 |
Icon::get_element_css( $attributes, 'Tablet' ), |
| 73 |
Icon::get_element_css( $attributes, 'Mobile' ), |
| 74 |
); |
| 75 |
$css_generator->add_class_styles( |
| 76 |
'{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover', |
| 77 |
Icon::get_element_image_hover_css( $attributes ), |
| 78 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 79 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 80 |
); |
| 81 |
|
| 82 |
return $css_generator->generate_css(); |
| 83 |
} |
| 84 |
|
| 85 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 86 |
$css = []; |
| 87 |
if ( $attributes['position'] === 'left' || $attributes['position'] === 'right' ) { |
| 88 |
$css = array_merge( |
| 89 |
[ |
| 90 |
'position' => 'fixed', |
| 91 |
'z-index' => '9999', |
| 92 |
], |
| 93 |
Range::get_css([ |
| 94 |
'attributeValue' => $attributes['positionBottom'], |
| 95 |
'attribute_object_key' => 'value', |
| 96 |
'isResponsive' => true, |
| 97 |
'hasUnit' => true, |
| 98 |
'defaultValue' => 20, |
| 99 |
'unitDefaultValue' => 'px', |
| 100 |
'property' => 'bottom', |
| 101 |
'device' => $device, |
| 102 |
]) |
| 103 |
); |
| 104 |
if ( $attributes['position'] === 'left' ) { |
| 105 |
$css = array_merge( |
| 106 |
$css, |
| 107 |
Range::get_css([ |
| 108 |
'attributeValue' => $attributes['positionLeft'], |
| 109 |
'attribute_object_key' => 'value', |
| 110 |
'isResponsive' => true, |
| 111 |
'hasUnit' => true, |
| 112 |
'defaultValue' => 20, |
| 113 |
'unitDefaultValue' => 'px', |
| 114 |
'property' => 'left', |
| 115 |
'device' => $device, |
| 116 |
]) |
| 117 |
); |
| 118 |
} elseif ( $attributes['position'] === 'right' ) { |
| 119 |
$css = array_merge( |
| 120 |
$css, |
| 121 |
Range::get_css([ |
| 122 |
'attributeValue' => $attributes['positionRight'], |
| 123 |
'attribute_object_key' => 'value', |
| 124 |
'isResponsive' => true, |
| 125 |
'hasUnit' => true, |
| 126 |
'defaultValue' => 20, |
| 127 |
'unitDefaultValue' => 'px', |
| 128 |
'property' => 'right', |
| 129 |
'device' => $device, |
| 130 |
]) |
| 131 |
); |
| 132 |
}//end if |
| 133 |
}//end if |
| 134 |
return array_merge( |
| 135 |
$css, |
| 136 |
Alignment::get_css( $attributes['alignment'], 'justify-content', $device ) |
| 137 |
); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public function get_button_text_css( $attributes, $device = '' ) { |
| 143 |
$typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array(); |
| 144 |
return array_merge( |
| 145 |
[ 'color' => Color::get_css( isset( $attributes['buttonTextColor'] ) ? $attributes['buttonTextColor'] : '' ) ], |
| 146 |
Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ), |
| 147 |
TextShadow::get_css( $attributes['textShadow'], '', $device ), |
| 148 |
TextStroke::get_css( $attributes['textStroke'], '', $device ), |
| 149 |
[ 'background' => Color::get_css( isset( $attributes['buttonTextColorBg'] ) ? $attributes['buttonTextColorBg'] : '' ) ], |
| 150 |
Border::get_css( $attributes['border'], '', $device ), |
| 151 |
Dimensions::get_css( isset( $attributes['padding'] ) ? $attributes['padding'] : [], 'padding', $device ), |
| 152 |
); |
| 153 |
} |
| 154 |
public function get_button_text_hover_css( $attributes, $device = '' ) { |
| 155 |
return array_merge( |
| 156 |
[ 'color' => Color::get_css( isset( $attributes['buttonTextColorH'] ) ? $attributes['buttonTextColorH'] : '' ) ], |
| 157 |
[ 'background' => Color::get_css( isset( $attributes['buttonTextColorBgH'] ) ? $attributes['buttonTextColorBgH'] : '' ) ], |
| 158 |
Border::get_hover_css( $attributes['border'], '', $device ) |
| 159 |
); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
} |
| 164 |
|