| 1 |
<?php |
| 2 |
|
| 3 |
namespace MasterAddons\Addons; |
| 4 |
|
| 5 |
use MasterAddons\Inc\Classes\Base\Master_Widget; |
| 6 |
use \Elementor\Controls_Manager; |
| 7 |
use \Elementor\Group_Control_Typography; |
| 8 |
|
| 9 |
use MasterAddons\Inc\Classes\Helper; |
| 10 |
use MasterAddons\Inc\Admin\Config; |
| 11 |
|
| 12 |
if (!defined('ABSPATH')) exit; // If this file is called directly, abort. |
| 13 |
|
| 14 |
class Progress_Bar extends Master_Widget |
| 15 |
{ |
| 16 |
use \MasterAddons\Inc\Traits\Widget_Notice; |
| 17 |
use \MasterAddons\Inc\Traits\Widget_Assets_Trait; |
| 18 |
|
| 19 |
public function get_name() |
| 20 |
{ |
| 21 |
return 'ma-progressbar'; |
| 22 |
} |
| 23 |
|
| 24 |
public function get_title() |
| 25 |
{ |
| 26 |
return esc_html__('Progressbar', 'master-addons' ); |
| 27 |
} |
| 28 |
|
| 29 |
public function get_icon() |
| 30 |
{ |
| 31 |
return 'jltma-icon ' . Config::get_addon_icon($this->get_name()); |
| 32 |
} |
| 33 |
|
| 34 |
protected function register_controls() |
| 35 |
{ |
| 36 |
|
| 37 |
// Progressbar Content Section |
| 38 |
$this->start_controls_section( |
| 39 |
'ma_el_progress_bar_section_content', |
| 40 |
[ |
| 41 |
'label' => __('Content', 'master-addons' ), |
| 42 |
] |
| 43 |
); |
| 44 |
|
| 45 |
$this->add_control( |
| 46 |
'ma_el_progress_bar_title', |
| 47 |
[ |
| 48 |
'label' => __('Title', 'master-addons' ), |
| 49 |
'type' => Controls_Manager::TEXT, |
| 50 |
'default' => __('Progress Bar', 'master-addons' ), |
| 51 |
'separator' => 'before', |
| 52 |
] |
| 53 |
); |
| 54 |
|
| 55 |
$this->add_control( |
| 56 |
'ma_el_progress_bar_value', |
| 57 |
[ |
| 58 |
'label' => __('Value', 'master-addons' ), |
| 59 |
'type' => Controls_Manager::NUMBER, |
| 60 |
'min' => 0, |
| 61 |
'max' => 100, |
| 62 |
'step' => 1, |
| 63 |
'default' => 60, |
| 64 |
] |
| 65 |
); |
| 66 |
|
| 67 |
$this->end_controls_section(); |
| 68 |
|
| 69 |
// Progressbar Style Section |
| 70 |
$this->start_controls_section( |
| 71 |
'ma_el_section_progress_bar_styles_preset', |
| 72 |
[ |
| 73 |
'label' => __('General Styles', 'master-addons' ), |
| 74 |
'tab' => Controls_Manager::TAB_STYLE |
| 75 |
] |
| 76 |
); |
| 77 |
|
| 78 |
$this->add_control( |
| 79 |
'ma_el_progress_bar_preset', |
| 80 |
[ |
| 81 |
'label' => __('Style Presets', 'master-addons' ), |
| 82 |
'type' => Controls_Manager::SELECT, |
| 83 |
'options' => [ |
| 84 |
'line' => __('Line', 'master-addons' ), |
| 85 |
'line-bubble' => __('Line Bubble', 'master-addons' ), |
| 86 |
'circle' => __('Circle', 'master-addons' ), |
| 87 |
'fan' => __('Fan', 'master-addons' ) |
| 88 |
], |
| 89 |
'default' => 'line', |
| 90 |
] |
| 91 |
); |
| 92 |
|
| 93 |
$this->add_control( |
| 94 |
'ma_el_progress_bar_bubble_color', |
| 95 |
[ |
| 96 |
'label' => __('Bubble Color', 'master-addons' ), |
| 97 |
'type' => Controls_Manager::COLOR, |
| 98 |
'default' => '#61ce70', |
| 99 |
'selectors' => [ |
| 100 |
'{{WRAPPER}} [class*="jltma-progress-bar-"].line-bubble .ldBar-label' => 'background: {{VALUE}};', |
| 101 |
], |
| 102 |
'condition' => [ |
| 103 |
'ma_el_progress_bar_preset' => 'line-bubble' |
| 104 |
] |
| 105 |
|
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$this->add_control( |
| 110 |
'ma_el_progress_bar_bubble_position', |
| 111 |
[ |
| 112 |
'label' => __('Bubble Position', 'master-addons' ), |
| 113 |
'type' => Controls_Manager::SLIDER, |
| 114 |
'unit' => '', |
| 115 |
'size' => '', |
| 116 |
'selectors' => [ |
| 117 |
'{{WRAPPER}} [class*="jltma-progress-bar-"].line-bubble .ldBar-label' => 'top: {{SIZE}}{{UNIT}} !important;', |
| 118 |
], |
| 119 |
'condition' => [ |
| 120 |
'ma_el_progress_bar_preset' => 'line-bubble' |
| 121 |
] |
| 122 |
|
| 123 |
] |
| 124 |
); |
| 125 |
|
| 126 |
$this->end_controls_section(); |
| 127 |
|
| 128 |
$this->start_controls_section( |
| 129 |
'ma_el_progress_bar_title_styles', |
| 130 |
[ |
| 131 |
'label' => __('Title', 'master-addons' ), |
| 132 |
'tab' => Controls_Manager::TAB_STYLE |
| 133 |
] |
| 134 |
); |
| 135 |
|
| 136 |
$this->add_control( |
| 137 |
'ma_el_progress_bar_title_color', |
| 138 |
[ |
| 139 |
'label' => __('Title Color', 'master-addons' ), |
| 140 |
'type' => Controls_Manager::COLOR, |
| 141 |
'default' => '#000', |
| 142 |
'selectors' => [ |
| 143 |
'{{WRAPPER}} .jltma-progress-bar-title' => 'color: {{VALUE}};', |
| 144 |
], |
| 145 |
] |
| 146 |
); |
| 147 |
|
| 148 |
$this->add_group_control( |
| 149 |
Group_Control_Typography::get_type(), |
| 150 |
[ |
| 151 |
'name' => 'title_typography', |
| 152 |
'selector' => '{{WRAPPER}} .jltma-progress-bar-title', |
| 153 |
] |
| 154 |
); |
| 155 |
|
| 156 |
$this->end_controls_section(); |
| 157 |
|
| 158 |
$this->start_controls_section( |
| 159 |
'ma_el_progress_bar_front_style', |
| 160 |
[ |
| 161 |
'label' => __('Front Bar', 'master-addons' ), |
| 162 |
'tab' => Controls_Manager::TAB_STYLE |
| 163 |
] |
| 164 |
); |
| 165 |
|
| 166 |
$this->add_control( |
| 167 |
'ma_el_progress_bar_stroke_color', |
| 168 |
[ |
| 169 |
'label' => __('Color', 'master-addons' ), |
| 170 |
'type' => Controls_Manager::COLOR, |
| 171 |
'default' => '#704aff' |
| 172 |
] |
| 173 |
); |
| 174 |
|
| 175 |
$this->add_control( |
| 176 |
'ma_el_progress_bar_stroke_width', |
| 177 |
[ |
| 178 |
'label' => __('Width', 'master-addons' ), |
| 179 |
'type' => Controls_Manager::NUMBER, |
| 180 |
'min' => 0, |
| 181 |
'max' => 100, |
| 182 |
'step' => 1, |
| 183 |
'default' => 5, |
| 184 |
] |
| 185 |
); |
| 186 |
|
| 187 |
$this->end_controls_section(); |
| 188 |
|
| 189 |
$this->start_controls_section( |
| 190 |
'ma_el_progress_bar_back_style', |
| 191 |
[ |
| 192 |
'label' => __('Back Bar', 'master-addons' ), |
| 193 |
'tab' => Controls_Manager::TAB_STYLE |
| 194 |
] |
| 195 |
); |
| 196 |
|
| 197 |
$this->add_control( |
| 198 |
'ma_el_progress_bar_trail_color', |
| 199 |
[ |
| 200 |
'label' => __('Color', 'master-addons' ), |
| 201 |
'type' => Controls_Manager::COLOR, |
| 202 |
'default' => '#ddd' |
| 203 |
] |
| 204 |
); |
| 205 |
|
| 206 |
$this->add_control( |
| 207 |
'ma_el_progress_bar_trail_width', |
| 208 |
[ |
| 209 |
'label' => __('Width', 'master-addons' ), |
| 210 |
'type' => Controls_Manager::NUMBER, |
| 211 |
'min' => 0, |
| 212 |
'max' => 100, |
| 213 |
'step' => 1, |
| 214 |
'default' => 5, |
| 215 |
] |
| 216 |
); |
| 217 |
|
| 218 |
$this->end_controls_section(); |
| 219 |
|
| 220 |
$this->start_controls_section( |
| 221 |
'ma_el_progress_bar_value_styles', |
| 222 |
[ |
| 223 |
'label' => __('Value', 'master-addons' ), |
| 224 |
'tab' => Controls_Manager::TAB_STYLE |
| 225 |
] |
| 226 |
); |
| 227 |
|
| 228 |
$this->add_control( |
| 229 |
'ma_el_progress_bar_value_color', |
| 230 |
[ |
| 231 |
'label' => __('Color', 'master-addons' ), |
| 232 |
'type' => Controls_Manager::COLOR, |
| 233 |
'default' => '#000', |
| 234 |
'selectors' => [ |
| 235 |
'{{WRAPPER}} [class*="jltma-progress-bar-"] .ldBar-label' => 'color: {{VALUE}};', |
| 236 |
], |
| 237 |
] |
| 238 |
); |
| 239 |
|
| 240 |
$this->add_group_control( |
| 241 |
Group_Control_Typography::get_type(), |
| 242 |
[ |
| 243 |
'name' => 'value_typography', |
| 244 |
'selector' => '{{WRAPPER}} .ldBar-label', |
| 245 |
] |
| 246 |
); |
| 247 |
|
| 248 |
$this->end_controls_section(); |
| 249 |
|
| 250 |
// Help Docs section (links from config.php) |
| 251 |
$this->jltma_help_docs(); |
| 252 |
|
| 253 |
$this->upgrade_to_pro_message(); |
| 254 |
|
| 255 |
} |
| 256 |
|
| 257 |
protected function render() |
| 258 |
{ |
| 259 |
$settings = $this->get_settings_for_display(); |
| 260 |
|
| 261 |
$this->add_render_attribute( |
| 262 |
'ma-el-progress-bar', |
| 263 |
[ |
| 264 |
'class' => [$settings['ma_el_progress_bar_preset'], 'jltma-progress-bar jltma-progress-bar-' . $this->get_id()], |
| 265 |
'data-id' => $this->get_id(), |
| 266 |
'data-type' => $settings['ma_el_progress_bar_preset'], |
| 267 |
'data-progress-bar-value' => $settings['ma_el_progress_bar_value'], |
| 268 |
'data-stroke-color' => $settings['ma_el_progress_bar_stroke_color'], |
| 269 |
'data-progress-bar-stroke-width' => $settings['ma_el_progress_bar_stroke_width'], |
| 270 |
'data-stroke-trail-color' => $settings['ma_el_progress_bar_trail_color'], |
| 271 |
'data-progress-bar-stroke-trail-width' => $settings['ma_el_progress_bar_trail_width'], |
| 272 |
] |
| 273 |
); |
| 274 |
|
| 275 |
if ($settings['ma_el_progress_bar_preset'] == 'line' || $settings['ma_el_progress_bar_preset'] == 'line-bubble') { |
| 276 |
$this->add_render_attribute( |
| 277 |
'ma-el-progress-bar', |
| 278 |
[ |
| 279 |
'data-preset' => 'line', |
| 280 |
'style' => 'width: 100%; height: 50px' |
| 281 |
] |
| 282 |
); |
| 283 |
} |
| 284 |
|
| 285 |
if ($settings['ma_el_progress_bar_preset'] == 'circle') { |
| 286 |
$this->add_render_attribute( |
| 287 |
'ma-el-progress-bar', |
| 288 |
[ |
| 289 |
'data-preset' => 'circle', |
| 290 |
'style' => 'width: 100%; height: 100%' |
| 291 |
] |
| 292 |
); |
| 293 |
} |
| 294 |
|
| 295 |
if ($settings['ma_el_progress_bar_preset'] == 'fan') { |
| 296 |
$this->add_render_attribute( |
| 297 |
'ma-el-progress-bar', |
| 298 |
[ |
| 299 |
'data-preset' => 'fan', |
| 300 |
'style' => 'width: 100%; height: 100%' |
| 301 |
] |
| 302 |
); |
| 303 |
} |
| 304 |
?> |
| 305 |
|
| 306 |
<div <?php echo $this->get_render_attribute_string('ma-el-progress-bar'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor render attribute string is safe ?> data-progress-bar> |
| 307 |
<?php if(!empty($settings['ma_el_progress_bar_title'])){?> |
| 308 |
<h6 class="jltma-progress-bar-title"> |
| 309 |
<?php echo esc_html($this->parse_text_editor($settings['ma_el_progress_bar_title'])); ?> |
| 310 |
</h6> |
| 311 |
<?php } ?> |
| 312 |
</div> |
| 313 |
|
| 314 |
<?php |
| 315 |
} |
| 316 |
} |
| 317 |
|