PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.7
Easy Elements for Elementor – Addons & Website Templates v1.3.7
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / includes / Extensions / ProgressBar / ReadingProgressBar.php

ReadingProgressBar.php in Easy Elements for Elementor – Addons & Website Templates 1.3.7, at includes/Extensions/ProgressBar/ReadingProgressBar.php

125 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Extensions\ProgressBar;
3 /**
4 * Easy ReadingProgressBar
5 *
6 * @package EasyElements
7 */
8
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 use \Elementor\Controls_Manager;
14
15 class ReadingProgressBar {
16
17 protected bool $should_render = false;
18
19 /**
20 * Holds the singleton instance
21 *
22 * @var Easy_readingprogressbar|null
23 */
24 private static $instance = null;
25
26 /**
27 * Constructor
28 */
29 private function __construct() {
30
31 $tab_slug = 'extensions';
32 $extensions_settings = get_option('easy_element_' . $tab_slug, [] );
33
34 $enable_reading_progress_bar = isset( $extensions_settings['enable_reading_progress_bar'] ) ? $extensions_settings['enable_reading_progress_bar'] : 0;
35
36 if( (int) $enable_reading_progress_bar !== 1 ) {
37 return;
38 }
39
40 add_action( 'wp_footer', [ $this, 'easyel_render_progressbar_html'] );
41 add_action( 'wp_enqueue_scripts', [ $this, "easy_progressbar_scripts" ] );
42
43 }
44
45 /**
46 * Get instance
47 */
48 public static function get_instance() : self {
49 if ( null === self::$instance ) {
50 self::$instance = new self();
51 }
52 return self::$instance;
53 }
54
55 public function easy_progressbar_scripts() {
56
57 if ( ! $this->should_display_progressbar() ) {
58 return;
59 }
60
61 wp_enqueue_style(
62 'easy-progress-bar',
63 EASYELEMENTS_DIR_URL . 'includes/Extensions/ProgressBar/assets/css/progress-bar.css',
64 [],
65 EASYELEMENTS_VER
66 );
67
68 $settings = get_option( 'easyel_reading_progressbar_settings', [] );
69 $height = !empty( $settings['reading_progressbar_height'] ) ? absint( $settings['reading_progressbar_height'] ) : 5;
70 $color = !empty( $settings['reading_progressbar_color'] ) ? $settings['reading_progressbar_color'] : '#7400c1';
71 $position = isset( $settings['reading_progressbar_position'] ) ? $settings['reading_progressbar_position'] : 'top';
72 $pos_css = ( $position === 'bottom' ) ? 'bottom:0; top:auto;' : 'top:0; bottom:auto;';
73
74 $custom_css = "
75 .easyel-progress-wrapper { height: {$height}px; {$pos_css} }
76 .easyel-reading-progress-bar { height: {$height}px; --easyel-progress-color: {$color}; }
77 ";
78
79 wp_add_inline_style( 'easy-progress-bar', $custom_css );
80
81 if ( ! did_action( 'elementor/loaded' ) ) {
82 return;
83 }
84
85 wp_enqueue_script(
86 'easyel-editor-script',
87 EASYELEMENTS_DIR_URL . 'includes/Extensions/ProgressBar/assets/js/progress-bar.js',
88 [ 'jquery' ],
89 EASYELEMENTS_VER,
90 true
91 );
92 }
93
94 private function should_display_progressbar() {
95 $settings = get_option( 'easyel_reading_progressbar_settings', [] );
96 if ( empty( $settings ) ) {
97 return false;
98 }
99
100 $display_on = isset( $settings['reading_progressbar_display'] ) ? (array) $settings['reading_progressbar_display'] : [];
101
102 $should_show = in_array( 'global', $display_on );
103
104 return apply_filters( 'easyel/reading_progressbar_should_show', $should_show, $settings, $display_on );
105 }
106
107 public function easyel_render_progressbar_html() {
108
109 if ( $this->should_display_progressbar() ) {
110 $this->render_progressbar_html();
111 }
112 }
113
114 private function render_progressbar_html() {
115
116 echo '<div class="easyel-progress-wrapper">
117 <progress id="easyel-reading-progress-bar"
118 class="easyel-reading-progress-bar"
119 value="0"
120 max="100"></progress>
121 </div>';
122 }
123
124 }
125