| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Style_Maker |
| 5 |
* Creates the CSS style for Float Menu Pro. |
| 6 |
* |
| 7 |
* @package FloatMenuLite |
| 8 |
* @subpackage Public |
| 9 |
* @author Dmytro Lobov <dev@wow-company.com>, Wow-Company |
| 10 |
* @copyright 2024 Dmytro Lobov |
| 11 |
* @license GPL-2.0+ |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace FloatMenuLite; |
| 15 |
|
| 16 |
defined( 'ABSPATH' ) || exit; |
| 17 |
|
| 18 |
class Style_Maker { |
| 19 |
/** |
| 20 |
* @var mixed |
| 21 |
*/ |
| 22 |
private $id; |
| 23 |
/** |
| 24 |
* @var mixed |
| 25 |
*/ |
| 26 |
private $param; |
| 27 |
|
| 28 |
public function __construct( $id, $param ) { |
| 29 |
$this->id = $id; |
| 30 |
$this->param = $param; |
| 31 |
} |
| 32 |
|
| 33 |
public function init(): string { |
| 34 |
|
| 35 |
$css = $this->main_style(); |
| 36 |
$css .= $this->mobile_size(); |
| 37 |
$css .= $this->items_style(); |
| 38 |
$css .= $this->mobile_rules(); |
| 39 |
|
| 40 |
return trim( preg_replace( '~\s+~', ' ', $css ) ); |
| 41 |
} |
| 42 |
|
| 43 |
private function main_style(): string { |
| 44 |
$param = $this->param; |
| 45 |
$z_index = $param['zindex'] ?? 0; |
| 46 |
$icon_size = $param['iconSize'] ?? 24; |
| 47 |
$label_size = $param['labelSize'] ?? 15; |
| 48 |
|
| 49 |
return ".float-menu-$this->id { |
| 50 |
--fm-icon-size: {$icon_size}px; |
| 51 |
--fm-label-size: {$label_size}px; |
| 52 |
--fm-border-radius: 50%; |
| 53 |
--fm-color: #E86E2C; |
| 54 |
--fm-background: #1b094f; |
| 55 |
--fm-z-index: $z_index; |
| 56 |
}"; |
| 57 |
} |
| 58 |
|
| 59 |
private function mobile_size(): string { |
| 60 |
$param = $this->param; |
| 61 |
$mobile_icon_size = $param['mobiliconSize'] ?? 24; |
| 62 |
$mobile_label_size = $param['mobillabelSize'] ?? 15; |
| 63 |
$mobile_screen = $param['mobilieScreen'] ?? 480; |
| 64 |
|
| 65 |
return "@media only screen and (max-width: {$mobile_screen}px){ |
| 66 |
.float-menu-$this->id { |
| 67 |
--fm-icon-size: {$mobile_icon_size}px; |
| 68 |
--fm-label-size: {$mobile_label_size}px; |
| 69 |
} |
| 70 |
}"; |
| 71 |
} |
| 72 |
|
| 73 |
private function items_style(): string { |
| 74 |
$param = $this->param; |
| 75 |
$css = ''; |
| 76 |
|
| 77 |
if ( empty( $param['menu_1']['item_type'] ) || ! is_array( $param['menu_1']['item_type'] ) ) { |
| 78 |
return $css; |
| 79 |
} |
| 80 |
|
| 81 |
foreach ( $param['menu_1']['item_type'] as $i => $value ) { |
| 82 |
$label_font = $param['menu_1']['item_tooltip_font'][ $i ] ?? 'inherit'; |
| 83 |
$label_style = $param['menu_1']['item_tooltip_style'][ $i ] ?? 'normal'; |
| 84 |
$label_weight = $param['menu_1']['item_tooltip_weight'][ $i ] ?? 'normal'; |
| 85 |
$text_font = $param['menu_1']['item_text_font'][ $i ] ?? 'inherit'; |
| 86 |
$text_size = $param['menu_1']['item_text_size'][ $i ] ?? '16'; |
| 87 |
$text_weight = $param['menu_1']['item_text_weight'][ $i ] ?? 'normal'; |
| 88 |
$color = $param['menu_1']['color'][ $i ] ?? '#ffffff'; |
| 89 |
$bcolor = $param['menu_1']['bcolor'][ $i ] ?? '#184c72'; |
| 90 |
$hcolor = $param['menu_1']['hcolor'][ $i ] ?? $color; |
| 91 |
$hbcolor = $param['menu_1']['hbcolor'][ $i ] ?? $bcolor; |
| 92 |
|
| 93 |
$css .= ".fm-item-$this->id-$i { |
| 94 |
--fm-color: $color; |
| 95 |
--fm-background: $bcolor; |
| 96 |
--fm-label-font: $label_font; |
| 97 |
--fm-label-font-style: $label_style; |
| 98 |
--fm-label-weight: $label_weight; |
| 99 |
--fm-text-font: $text_font; |
| 100 |
--fm-text-size: {$text_size}px; |
| 101 |
--fm-text-weight: $text_weight; |
| 102 |
}"; |
| 103 |
|
| 104 |
$css .= ".fm-item-$this->id-$i:hover { |
| 105 |
--fm-hover-color: $hcolor; |
| 106 |
--fm-hover-background: $hbcolor; |
| 107 |
}"; |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
return $css; |
| 112 |
} |
| 113 |
|
| 114 |
private function mobile_rules(): string { |
| 115 |
$param = $this->param; |
| 116 |
$css = ''; |
| 117 |
|
| 118 |
if ( ! empty( $param['mobile_on'] ) ) { |
| 119 |
$mobile = $param['mobile'] ?? 480; |
| 120 |
$css .= "@media only screen and (max-width: {$mobile}px){ |
| 121 |
.float-menu-$this->id { |
| 122 |
display:none; |
| 123 |
} |
| 124 |
}"; |
| 125 |
} |
| 126 |
|
| 127 |
if ( ! empty( $param['desktop_on'] ) ) { |
| 128 |
$desktop = $param['desktop'] ?? 1024; |
| 129 |
$css .= "@media only screen and (min-width: {$desktop}px){ |
| 130 |
.float-menu-$this->id { |
| 131 |
display:none; |
| 132 |
} |
| 133 |
}"; |
| 134 |
} |
| 135 |
|
| 136 |
return $css; |
| 137 |
} |
| 138 |
} |