PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / trunk
Floating Button – Easily Create Sticky, Fixed & Floating Buttons vtrunk
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Publisher / EnqueueStyle.php

EnqueueStyle.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons trunk, at classes/Publisher/EnqueueStyle.php

208 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FloatingButton\Publisher;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use FloatingButton\Optimization\CSSMinifier;
8 use FloatingButton\WOW_Plugin;
9
10 class EnqueueStyle {
11
12 /**
13 * @var mixed
14 */
15 private $id;
16 private $param;
17
18 public function __construct( $result ) {
19 $this->id = $result->id;
20 $this->param = maybe_unserialize( $result->param );
21 }
22
23 public function init(): void {
24 $param = $this->param;
25 $slug = WOW_Plugin::SLUG;
26 $version = WOW_Plugin::info( 'version' );
27 $asset = WOW_Plugin::url() . 'assets/';
28
29 $pre_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
30
31 $url_style = $asset . 'css/frontend' . $pre_suffix . '.css';
32 wp_enqueue_style( $slug, $url_style, null, $version );
33
34 $inline_style = $this->inline();
35 wp_add_inline_style( $slug, $inline_style );
36
37 if ( empty( $param['disable_fontawesome'] ) ) {
38 $url_icons = $asset . 'vendors/fontawesome/css/fontawesome-all' . $pre_suffix . '.css';
39 wp_enqueue_style( $slug . '-fontawesome', $url_icons, null, '6.6' );
40 }
41
42 if ( ! empty( $param['button_animation'] ) ) {
43 $url_animation = $asset . 'css/animation' . $pre_suffix . '.css';
44 wp_enqueue_style( $slug . '-animation', $url_animation, null, $version );
45 }
46
47 }
48
49 public function inline(): string {
50 $css = $this->main_btn();
51 $css .= $this->size();
52 $css .= $this->tooltip_size();
53 $css .= $this->main_btn_anim();
54 $css .= $this->offset();
55 $css .= $this->items();
56 $css .= $this->small_screen();
57 $css .= $this->large_screen();
58 $css .= $this->extra_style();
59
60 return trim( preg_replace( '~\s+~s', ' ', $css ) );
61 }
62
63
64 public function items(): string {
65 $param = $this->param;
66 $css = '';
67 $menus = [ 'menu_1' => 'flBtn-first', 'menu_2' => 'flBtn-second' ];
68 foreach ( $menus as $key => $class ) {
69 $count = isset( $param[ $key ]['item_type'] ) ? count( $param[ $key ]['item_type'] ) : 0;
70 for ( $i = 0; $i < $count; $i ++ ) {
71 $item = $i + 1;
72 $css .= '#floatBtn-' . absint( $this->id ) . ' .' . esc_attr( $class ) . ' li:nth-child(' . absint( $item ) . ') {';
73 $css .= '--flBtn-color: ' . esc_attr( $param[ $key ]['icon_color'][ $i ] ) . ';';
74 $css .= '--flBtn-h-color: ' . esc_attr( $param[ $key ]['icon_hcolor'][ $i ] ) . ';';
75 $css .= '--flBtn-bg: ' . esc_attr( $param[ $key ]['button_color'][ $i ] ) . ';';
76 $css .= '--flBtn-h-bg: ' . esc_attr( $param[ $key ]['button_hcolor'][ $i ] ) . ';';
77 $css .= '}';
78 }
79 }
80
81 return $css;
82 }
83
84 public function main_btn(): string {
85 $param = $this->param;
86
87 return '
88 #floatBtn-' . absint( $this->id ) . ' > a,
89 #floatBtn-' . absint( $this->id ) . ' > .flBtn-label {
90 --flBtn-bg: ' . esc_attr( $param['button_color'] ) . ';
91 --flBtn-color: ' . esc_attr( $param['icon_color'] ) . ';
92 --flBtn-h-color: ' . esc_attr( $param['icon_hcolor'] ) . ';
93 --flBtn-h-bg: ' . esc_attr( $param['button_hcolor'] ) . ';
94 }
95 #floatBtn-' . absint( $this->id ) . ' [data-tooltip] {
96 --flBtn-tooltip-bg: ' . esc_attr( $param['tooltip_background'] ) . ';
97 --flBtn-tooltip-color: ' . esc_attr( $param['tooltip_color'] ) . ';
98 }';
99 }
100
101 public function main_btn_anim(): string {
102 $param = $this->param;
103 $css = '';
104 if ( ! empty( $param['btn_anim_count'] ) ) {
105 $css .= '
106 #floatBtn-' . absint( $this->id ) . '.flBtn-animated {
107 animation-iteration-count: ' . absint( $param['btn_anim_count'] ) . ';
108 }
109 ';
110 }
111
112 if ( ! empty( $param['btn_anim_delay'] ) ) {
113 $css .= '
114 #floatBtn-' . absint( $this->id ) . '.flBtn-animated {
115 animation-delay: ' . absint( $param['btn_anim_delay'] ) . 'ms;
116 }
117 ';
118 }
119
120 return $css;
121
122 }
123
124 public function size(): string {
125 $param = $this->param;
126
127 if ( $param['size'] !== 'flBtn-custom' ) {
128 return '';
129 }
130
131 $css = '
132 #floatBtn-' . absint( $this->id ) . ' {
133 --flBtn-size: ' . absint( $param['ul_size'] ) . 'px;
134 --flBtn-box: ' . absint( $param['ul_box'] ) . 'px;
135 --flBtn-label-size: ' . absint( $param['label_size'] ) . 'px;
136 --flBtn-label-box: ' . absint( $param['label_box'] ) . 'px;
137 }';
138
139
140 return $css;
141 }
142
143 public function tooltip_size(): string {
144 $param = $this->param;
145 $css = '';
146 if ( ! empty( $param['tooltip_size_check'] ) && $param['tooltip_size_check'] === 'custom' ) {
147 $css = '#floatBtn-' . absint( $this->id ) . ' {
148 --flBtn-tooltip-size: ' . absint( $param['tooltip_size'] ) . 'px;
149 --flBtn-tooltip-ul-size: ' . absint( $param['tooltip_ul_size'] ) . 'px;
150 }';
151 }
152 return $css;
153 }
154
155 public function offset(): string {
156 $param = $this->param;
157 $v_offset = ! empty( $param['v_offset'] ) ? $param['v_offset'] . 'px' : '0';
158 $h_offset = ! empty( $param['h_offset'] ) ? $param['h_offset'] . 'px' : '0';
159 $css = '';
160 if ( ! empty( $v_offset ) || ! empty( $h_offset ) ) {
161 $css .= '#floatBtn-' . absint( $this->id ) . ' {
162 --flBtn-v-offset: ' . esc_attr( $v_offset ) . ';
163 --flBtn-h-offset: ' . esc_attr( $h_offset ) . ';
164 }';
165
166 }
167
168 return $css;
169 }
170
171 public function small_screen(): string {
172 if ( empty( $this->param['include_mobile'] ) ) {
173 return '';
174 }
175 $screen = ! empty( $this->param['screen'] ) ? $this->param['screen'] : 480;
176
177 return '
178 @media only screen and (max-width: ' . esc_attr( $screen ) . 'px){
179 #floatBtn-' . absint( $this->id ) . ' {
180 display:none;
181 }
182 }';
183 }
184
185 public function large_screen(): string {
186 if ( empty( $this->param['include_more_screen'] ) ) {
187 return '';
188 }
189 $screen = ! empty( $this->param['screen_more'] ) ? $this->param['screen_more'] : 1200;
190
191 return '
192 @media only screen and (min-width: ' . esc_attr( $screen ) . 'px){
193 #floatBtn-' . absint( $this->id ) . ' {
194 display:none;
195 }
196 }';
197 }
198
199 public function extra_style() {
200 if ( empty( $this->param['extra_style'] ) ) {
201 return '';
202 }
203
204 return $this->param['extra_style'];
205
206 }
207
208 }