| 1 |
<?php |
| 2 |
namespace UltimatePostKit\Modules\ReadingProgress\Widgets; |
| 3 |
|
| 4 |
use UltimatePostKit\Base\Module_Base; |
| 5 |
use Elementor\Controls_Manager; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 8 |
|
| 9 |
/** |
| 10 |
* Class News Ticker |
| 11 |
*/ |
| 12 |
class Reading_Progress extends Module_Base { |
| 13 |
|
| 14 |
public function get_name() { |
| 15 |
return 'upk-reading-progress'; |
| 16 |
} |
| 17 |
|
| 18 |
public function get_title() { |
| 19 |
return BDTUPK . esc_html__( 'Reading Progress Bar', 'ultimate-post-kit' ); |
| 20 |
} |
| 21 |
|
| 22 |
public function get_icon() { |
| 23 |
return 'upk-widget-icon upk-icon-reading-progress'; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_categories() { |
| 27 |
return [ 'ultimate-post-kit' ]; |
| 28 |
} |
| 29 |
|
| 30 |
public function get_keywords() { |
| 31 |
return [ 'bar', 'scroll', 'animate', 'line', 'scrolline', 'pop', 'reading progress' ]; |
| 32 |
} |
| 33 |
|
| 34 |
public function get_script_depends() { |
| 35 |
if ( $this->upk_is_edit_mode() ) { |
| 36 |
return [ 'upk-all-scripts' ]; |
| 37 |
} else { |
| 38 |
return [ 'scrolline', 'upk-reading-progress' ]; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
public function get_custom_help_url() { |
| 43 |
return 'https://youtu.be/9N_2WDXUjo0'; |
| 44 |
} |
| 45 |
|
| 46 |
public function has_widget_inner_wrapper(): bool { |
| 47 |
return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
protected function register_controls() { |
| 52 |
$this->start_controls_section( |
| 53 |
'section_style_reading_progress', |
| 54 |
[ |
| 55 |
'label' => esc_html__( 'Reading Progress', 'ultimate-post-kit' ), |
| 56 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 57 |
] |
| 58 |
); |
| 59 |
|
| 60 |
$this->add_control( |
| 61 |
'direction', |
| 62 |
[ |
| 63 |
'label' => esc_html__( 'Direction', 'ultimate-post-kit' ), |
| 64 |
'type' => Controls_Manager::SELECT, |
| 65 |
'default' => 'horizontal', |
| 66 |
'options' => [ |
| 67 |
'horizontal' => esc_html__( 'Horizontal', 'ultimate-post-kit' ), |
| 68 |
'vertical' => esc_html__( 'Vertical', 'ultimate-post-kit' ), |
| 69 |
], |
| 70 |
'render_type' => 'template' |
| 71 |
] |
| 72 |
); |
| 73 |
|
| 74 |
$this->add_control( |
| 75 |
'horizontal_position', |
| 76 |
[ |
| 77 |
'label' => esc_html__( 'Position', 'ultimate-post-kit' ), |
| 78 |
'type' => Controls_Manager::SELECT, |
| 79 |
'default' => 'top', |
| 80 |
'options' => [ |
| 81 |
'top' => esc_html__( 'Top', 'ultimate-post-kit' ), |
| 82 |
'bottom' => esc_html__( 'Bottom', 'ultimate-post-kit' ), |
| 83 |
], |
| 84 |
'condition' => [ |
| 85 |
'direction' => 'horizontal' |
| 86 |
], |
| 87 |
'render_type' => 'template' |
| 88 |
] |
| 89 |
); |
| 90 |
|
| 91 |
$this->add_control( |
| 92 |
'vertical_position', |
| 93 |
[ |
| 94 |
'label' => esc_html__( 'Position', 'ultimate-post-kit' ), |
| 95 |
'type' => Controls_Manager::SELECT, |
| 96 |
'default' => 'right', |
| 97 |
'options' => [ |
| 98 |
'left' => esc_html__( 'Left', 'ultimate-post-kit' ), |
| 99 |
'right' => esc_html__( 'Right', 'ultimate-post-kit' ), |
| 100 |
], |
| 101 |
'condition' => [ |
| 102 |
'direction' => 'vertical' |
| 103 |
], |
| 104 |
'render_type' => 'template' |
| 105 |
] |
| 106 |
); |
| 107 |
|
| 108 |
$this->add_control( |
| 109 |
'back_color', |
| 110 |
[ |
| 111 |
'label' => esc_html__('Back Color', 'ultimate-post-kit'), |
| 112 |
'type' => Controls_Manager::COLOR, |
| 113 |
'render_type' => 'template' |
| 114 |
] |
| 115 |
); |
| 116 |
|
| 117 |
$this->add_control( |
| 118 |
'front_color', |
| 119 |
[ |
| 120 |
'label' => esc_html__('Front Color', 'ultimate-post-kit'), |
| 121 |
'type' => Controls_Manager::COLOR, |
| 122 |
'render_type' => 'template' |
| 123 |
] |
| 124 |
); |
| 125 |
|
| 126 |
$this->add_control( |
| 127 |
'weight', |
| 128 |
[ |
| 129 |
'label' => esc_html__( 'Weight', 'ultimate-post-kit' ), |
| 130 |
'type' => Controls_Manager::SLIDER, |
| 131 |
'render_type' => 'template' |
| 132 |
] |
| 133 |
); |
| 134 |
|
| 135 |
$this->add_control( |
| 136 |
'opacity', |
| 137 |
[ |
| 138 |
'label' => esc_html__( 'Opacity', 'ultimate-post-kit' ), |
| 139 |
'type' => Controls_Manager::SLIDER, |
| 140 |
'range' => [ |
| 141 |
'px' => [ |
| 142 |
'min' => 0, |
| 143 |
'max' => 1, |
| 144 |
'step' => 0.1, |
| 145 |
], |
| 146 |
], |
| 147 |
] |
| 148 |
); |
| 149 |
|
| 150 |
$this->add_control( |
| 151 |
'zindex', |
| 152 |
[ |
| 153 |
'label' => esc_html__( 'Z-index', 'ultimate-post-kit' ), |
| 154 |
'type' => Controls_Manager::TEXT, |
| 155 |
'label_block' => false |
| 156 |
] |
| 157 |
); |
| 158 |
|
| 159 |
$this->add_control( |
| 160 |
'reverse', |
| 161 |
[ |
| 162 |
'label' => esc_html__( 'Reverse', 'ultimate-post-kit' ), |
| 163 |
'type' => Controls_Manager::SWITCHER, |
| 164 |
'render_type' => 'template' |
| 165 |
] |
| 166 |
); |
| 167 |
|
| 168 |
$this->end_controls_section(); |
| 169 |
} |
| 170 |
|
| 171 |
protected function render() { |
| 172 |
$id = 'upk-reading-progress-' . $this->get_id(); |
| 173 |
$settings = $this->get_settings_for_display(); |
| 174 |
|
| 175 |
$position = $settings['direction'] == 'horizontal' ? $settings['horizontal_position'] : $settings['vertical_position']; |
| 176 |
|
| 177 |
$this->add_render_attribute( |
| 178 |
[ |
| 179 |
'reading-progress-settings' => [ |
| 180 |
'id' => $id, |
| 181 |
'class' => 'upk-reading-progress', |
| 182 |
'data-settings' => [ |
| 183 |
wp_json_encode(array_filter([ |
| 184 |
"direction" => $settings['direction'], |
| 185 |
"position" => $position, |
| 186 |
"backColor" => $settings['back_color'], |
| 187 |
"frontColor" => $settings['front_color'], |
| 188 |
"weight" => $settings['weight']['size'], |
| 189 |
"opacity" => $settings['opacity']['size'], |
| 190 |
"zindex" => $settings['zindex'], |
| 191 |
"reverse" => ($settings["reverse"] == 'yes') ? true: false, |
| 192 |
])) |
| 193 |
], |
| 194 |
] |
| 195 |
] |
| 196 |
); |
| 197 |
|
| 198 |
?> |
| 199 |
<div <?php $this->print_render_attribute_string( 'reading-progress-settings' ); ?>></div> |
| 200 |
<?php |
| 201 |
} |
| 202 |
} |
| 203 |
|