| @@ -6,34 +6,104 @@ | ||
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | 7 | exit( 'This script cannot be accessed directly.' ); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | -use RadiusTheme\SB\Modules\Compare\CompareInstaller; | |
| 10 | +use RadiusTheme\SB\Helpers\Fns; | |
| 11 | 11 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 12 | 12 | |
| 13 | 13 | final class QuickView { |
| 14 | + /** | |
| 15 | + * @var array | |
| 16 | + */ | |
| 17 | + private $cache = []; | |
| 14 | 18 | |
| 15 | 19 | /** |
| 16 | 20 | * @var array |
| 17 | 21 | */ |
| 18 | 22 | public $settings = []; |
| 19 | - | |
| 20 | - //protected $module_id = 'quick_view'; | |
| 21 | - | |
| 23 | + /** | |
| 24 | + * @var array|mixed | |
| 25 | + */ | |
| 26 | + private array $options; | |
| 27 | + /** | |
| 28 | + * Options | |
| 29 | + */ | |
| 22 | 30 | use SingletonTrait; |
| 23 | 31 | |
| 24 | - function __construct() { | |
| 25 | - | |
| 32 | + private function __construct() { | |
| 26 | 33 | QuickViewFrontEnd::instance(); |
| 27 | - | |
| 34 | + $this->options = Fns::get_options( 'modules', 'quick_view' ); | |
| 35 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_scripts' ], 99 ); | |
| 28 | 36 | do_action( 'rtsb/module/quick_view/loaded' ); |
| 29 | 37 | } |
| 30 | 38 | |
| 31 | 39 | /** |
| 32 | - * Do stuff upon plugin activation | |
| 33 | - * | |
| 34 | 40 | * @return void |
| 35 | 41 | */ |
| 36 | - public function activate() { | |
| 37 | - ( new CompareInstaller() )->run(); | |
| 42 | + public function enqueue_public_scripts() { | |
| 43 | + $cache_key = 'quick_view_style_cache'; | |
| 44 | + $width = ! empty( $this->options['modal_width'] ) ? $this->options['modal_width'] : '950'; | |
| 45 | + wp_localize_script( | |
| 46 | + 'rtsb-public', | |
| 47 | + 'QvModalParams', | |
| 48 | + [ | |
| 49 | + 'modal_width' => absint( $width ), | |
| 50 | + ] | |
| 51 | + ); | |
| 52 | + | |
| 53 | + if ( isset( $this->cache[ $cache_key ] ) && ! empty( $this->cache[ $cache_key ] ) ) { | |
| 54 | + wp_add_inline_style( 'rtsb-frontend', $this->cache[ $cache_key ] ); | |
| 55 | + return; | |
| 56 | + } | |
| 57 | + | |
| 58 | + $height = $this->options['modal_height'] ?? false; | |
| 59 | + $wrapper_padding = $this->options['modal_wrapper_padding'] ?? '0'; | |
| 60 | + $bg_color = $this->options['modal_bg_color'] ?? false; | |
| 61 | + $box_shadow = $this->options['modal_box_shadow_color'] ?? false; | |
| 62 | + $overly_color = $this->options['modal_overly_color'] ?? false; | |
| 63 | + | |
| 64 | + ob_start(); | |
| 65 | + | |
| 66 | + if ( $height ) { ?> | |
| 67 | + .rtsb-ui-modal .rtsb-modal-content{ | |
| 68 | + height: <?php echo esc_attr( $height ); ?>; | |
| 69 | + } | |
| 70 | + <?php | |
| 71 | + } | |
| 72 | + | |
| 73 | + if ( '' !== $wrapper_padding ) { | |
| 74 | + ?> | |
| 75 | + .rtsb-ui-modal .rtsb-modal-wrapper.quick-view-modal .rtsb-modal-content .rtsb-modal-body{ | |
| 76 | + padding: <?php echo esc_attr( $wrapper_padding ); ?>; | |
| 77 | + } | |
| 78 | + <?php | |
| 79 | + } | |
| 80 | + if ( $bg_color ) { | |
| 81 | + ?> | |
| 82 | + .rtsb-ui-modal .rtsb-modal-wrapper .rtsb-modal-content{ | |
| 83 | + background-color: <?php echo esc_attr( $bg_color ); ?>; | |
| 84 | + } | |
| 85 | + <?php | |
| 86 | + } | |
| 87 | + if ( $box_shadow ) { | |
| 88 | + ?> | |
| 89 | + .rtsb-ui-modal .rtsb-modal-content{ | |
| 90 | + box-shadow: 0 0 10px <?php echo esc_attr( $box_shadow ); ?>; | |
| 91 | + } | |
| 92 | + <?php | |
| 93 | + } | |
| 94 | + | |
| 95 | + if ( $overly_color ) { | |
| 96 | + ?> | |
| 97 | + .rtsb-ui-modal .rtsb-mask-wrapper{ | |
| 98 | + background-color: <?php echo esc_attr( $overly_color ); ?>; | |
| 99 | + } | |
| 100 | + <?php | |
| 101 | + } | |
| 102 | + | |
| 103 | + $dynamic_css = ob_get_clean(); | |
| 104 | + $this->cache[ $cache_key ] = $dynamic_css; | |
| 105 | + if ( ! empty( $dynamic_css ) ) { | |
| 106 | + wp_add_inline_style( 'rtsb-frontend', $dynamic_css ); | |
| 107 | + } | |
| 38 | 108 | } |
| 39 | -} | |
| 109 | +} | |