PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
ablocks / includes / blocks / scroll-to-top / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.14.0, at includes/blocks/scroll-to-top/block.php

173 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
32 );
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .ablocks-scroll-to-top-button-text',
35 $this->get_button_text_css( $attributes ),
36 $this->get_button_text_css( $attributes, 'Tablet' ),
37 $this->get_button_text_css( $attributes, 'Mobile' ),
38 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_text_css( $attributes, $device ); } )
39 );
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .ablocks-scroll-to-top-button-text:hover',
42 $this->get_button_text_hover_css( $attributes ),
43 $this->get_button_text_hover_css( $attributes, 'Tablet' ),
44 $this->get_button_text_hover_css( $attributes, 'Mobile' ),
45 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_text_hover_css( $attributes, $device ); } )
46 );
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .ablocks-icon-wrap',
49 Icon::get_wrapper_css( $attributes ),
50 Icon::get_wrapper_css( $attributes, 'Tablet' ),
51 Icon::get_wrapper_css( $attributes, 'Mobile' ),
52 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
53 );
54 $css_generator->add_class_styles(
55 '{{WRAPPER}} .ablocks-icon-wrap:hover',
56 Icon::get_wrapper_hover_css( $attributes ),
57 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
58 Icon::get_wrapper_hover_css( $attributes, 'Mobile' ),
59 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_hover_css( $attributes, $device ); } )
60 );
61
62 $css_generator->add_class_styles(
63 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
64 Icon::get_element_image_css( $attributes ),
65 Icon::get_element_image_css( $attributes, 'Tablet' ),
66 Icon::get_element_image_css( $attributes, 'Mobile' ),
67 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } )
68 );
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
71 Icon::get_element_image_hover_css( $attributes ),
72 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
73 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
74 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } )
75 );
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
78 Icon::get_element_css( $attributes ),
79 Icon::get_element_css( $attributes, 'Tablet' ),
80 Icon::get_element_css( $attributes, 'Mobile' ),
81 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_css( $attributes, $device ); } )
82 );
83 $css_generator->add_class_styles(
84 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
85 Icon::get_element_image_hover_css( $attributes ),
86 Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
87 Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
88 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } )
89 );
90
91 return $css_generator->generate_css();
92 }
93
94 public function get_wrapper_css( $attributes, $device = '' ) {
95 $css = [];
96 if ( $attributes['position'] === 'left' || $attributes['position'] === 'right' ) {
97 $css = array_merge(
98 [
99 'position' => 'fixed',
100 'z-index' => '9999',
101 ],
102 Range::get_css([
103 'attributeValue' => $attributes['positionBottom'],
104 'attribute_object_key' => 'value',
105 'isResponsive' => true,
106 'hasUnit' => true,
107 'defaultValue' => 20,
108 'unitDefaultValue' => 'px',
109 'property' => 'bottom',
110 'device' => $device,
111 ])
112 );
113 if ( $attributes['position'] === 'left' ) {
114 $css = array_merge(
115 $css,
116 Range::get_css([
117 'attributeValue' => $attributes['positionLeft'],
118 'attribute_object_key' => 'value',
119 'isResponsive' => true,
120 'hasUnit' => true,
121 'defaultValue' => 20,
122 'unitDefaultValue' => 'px',
123 'property' => 'left',
124 'device' => $device,
125 ])
126 );
127 } elseif ( $attributes['position'] === 'right' ) {
128 $css = array_merge(
129 $css,
130 Range::get_css([
131 'attributeValue' => $attributes['positionRight'],
132 'attribute_object_key' => 'value',
133 'isResponsive' => true,
134 'hasUnit' => true,
135 'defaultValue' => 20,
136 'unitDefaultValue' => 'px',
137 'property' => 'right',
138 'device' => $device,
139 ])
140 );
141 }//end if
142 }//end if
143 return array_merge(
144 $css,
145 Alignment::get_css( $attributes['alignment'], 'justify-content', $device )
146 );
147 }
148
149
150
151 public function get_button_text_css( $attributes, $device = '' ) {
152 $typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array();
153 return array_merge(
154 [ 'color' => Color::get_css( isset( $attributes['buttonTextColor'] ) ? $attributes['buttonTextColor'] : '' ) ],
155 Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ),
156 TextShadow::get_css( $attributes['textShadow'], '', $device ),
157 TextStroke::get_css( $attributes['textStroke'], '', $device ),
158 [ 'background' => Color::get_css( isset( $attributes['buttonTextColorBg'] ) ? $attributes['buttonTextColorBg'] : '' ) ],
159 Border::get_css( $attributes['border'], '', $device ),
160 Dimensions::get_css( isset( $attributes['padding'] ) ? $attributes['padding'] : [], 'padding', $device ),
161 );
162 }
163 public function get_button_text_hover_css( $attributes, $device = '' ) {
164 return array_merge(
165 [ 'color' => Color::get_css( isset( $attributes['buttonTextColorH'] ) ? $attributes['buttonTextColorH'] : '' ) ],
166 [ 'background' => Color::get_css( isset( $attributes['buttonTextColorBgH'] ) ? $attributes['buttonTextColorBgH'] : '' ) ],
167 Border::get_hover_css( $attributes['border'], '', $device )
168 );
169 }
170
171
172 }
173