balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

progress.php (10360B)


      1 <?php
      2 namespace Elementor;
      3 
      4 if ( ! defined( 'ABSPATH' ) ) {
      5 	exit; // Exit if accessed directly.
      6 }
      7 
      8 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
      9 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
     10 
     11 /**
     12  * Elementor progress widget.
     13  *
     14  * Elementor widget that displays an escalating progress bar.
     15  *
     16  * @since 1.0.0
     17  */
     18 class Widget_Progress extends Widget_Base {
     19 
     20 	/**
     21 	 * Get widget name.
     22 	 *
     23 	 * Retrieve progress widget name.
     24 	 *
     25 	 * @since 1.0.0
     26 	 * @access public
     27 	 *
     28 	 * @return string Widget name.
     29 	 */
     30 	public function get_name() {
     31 		return 'progress';
     32 	}
     33 
     34 	/**
     35 	 * Get widget title.
     36 	 *
     37 	 * Retrieve progress widget title.
     38 	 *
     39 	 * @since 1.0.0
     40 	 * @access public
     41 	 *
     42 	 * @return string Widget title.
     43 	 */
     44 	public function get_title() {
     45 		return esc_html__( 'Progress Bar', 'elementor' );
     46 	}
     47 
     48 	/**
     49 	 * Get widget icon.
     50 	 *
     51 	 * Retrieve progress widget icon.
     52 	 *
     53 	 * @since 1.0.0
     54 	 * @access public
     55 	 *
     56 	 * @return string Widget icon.
     57 	 */
     58 	public function get_icon() {
     59 		return 'eicon-skill-bar';
     60 	}
     61 
     62 	/**
     63 	 * Get widget keywords.
     64 	 *
     65 	 * Retrieve the list of keywords the widget belongs to.
     66 	 *
     67 	 * @since 2.1.0
     68 	 * @access public
     69 	 *
     70 	 * @return array Widget keywords.
     71 	 */
     72 	public function get_keywords() {
     73 		return [ 'progress', 'bar' ];
     74 	}
     75 
     76 	/**
     77 	 * Register progress widget controls.
     78 	 *
     79 	 * Adds different input fields to allow the user to change and customize the widget settings.
     80 	 *
     81 	 * @since 3.1.0
     82 	 * @access protected
     83 	 */
     84 	protected function register_controls() {
     85 		$this->start_controls_section(
     86 			'section_progress',
     87 			[
     88 				'label' => esc_html__( 'Progress Bar', 'elementor' ),
     89 			]
     90 		);
     91 
     92 		$this->add_control(
     93 			'title',
     94 			[
     95 				'label' => esc_html__( 'Title', 'elementor' ),
     96 				'type' => Controls_Manager::TEXT,
     97 				'dynamic' => [
     98 					'active' => true,
     99 				],
    100 				'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
    101 				'default' => esc_html__( 'My Skill', 'elementor' ),
    102 				'label_block' => true,
    103 			]
    104 		);
    105 
    106 		$this->add_control(
    107 			'progress_type',
    108 			[
    109 				'label' => esc_html__( 'Type', 'elementor' ),
    110 				'type' => Controls_Manager::SELECT,
    111 				'default' => '',
    112 				'options' => [
    113 					'' => esc_html__( 'Default', 'elementor' ),
    114 					'info' => esc_html__( 'Info', 'elementor' ),
    115 					'success' => esc_html__( 'Success', 'elementor' ),
    116 					'warning' => esc_html__( 'Warning', 'elementor' ),
    117 					'danger' => esc_html__( 'Danger', 'elementor' ),
    118 				],
    119 			]
    120 		);
    121 
    122 		$this->add_control(
    123 			'percent',
    124 			[
    125 				'label' => esc_html__( 'Percentage', 'elementor' ),
    126 				'type' => Controls_Manager::SLIDER,
    127 				'default' => [
    128 					'size' => 50,
    129 					'unit' => '%',
    130 				],
    131 				'dynamic' => [
    132 					'active' => true,
    133 				],
    134 			]
    135 		);
    136 
    137 		$this->add_control(
    138 			'display_percentage',
    139 			[
    140 				'label' => esc_html__( 'Display Percentage', 'elementor' ),
    141 				'type' => Controls_Manager::SELECT,
    142 				'default' => 'show',
    143 				'options' => [
    144 					'show' => esc_html__( 'Show', 'elementor' ),
    145 					'hide' => esc_html__( 'Hide', 'elementor' ),
    146 				],
    147 			]
    148 		);
    149 
    150 		$this->add_control(
    151 			'inner_text',
    152 			[
    153 				'label' => esc_html__( 'Inner Text', 'elementor' ),
    154 				'type' => Controls_Manager::TEXT,
    155 				'dynamic' => [
    156 					'active' => true,
    157 				],
    158 				'placeholder' => esc_html__( 'e.g. Web Designer', 'elementor' ),
    159 				'default' => esc_html__( 'Web Designer', 'elementor' ),
    160 				'label_block' => true,
    161 			]
    162 		);
    163 
    164 		$this->add_control(
    165 			'view',
    166 			[
    167 				'label' => esc_html__( 'View', 'elementor' ),
    168 				'type' => Controls_Manager::HIDDEN,
    169 				'default' => 'traditional',
    170 			]
    171 		);
    172 
    173 		$this->end_controls_section();
    174 
    175 		$this->start_controls_section(
    176 			'section_progress_style',
    177 			[
    178 				'label' => esc_html__( 'Progress Bar', 'elementor' ),
    179 				'tab' => Controls_Manager::TAB_STYLE,
    180 			]
    181 		);
    182 
    183 		$this->add_control(
    184 			'bar_color',
    185 			[
    186 				'label' => esc_html__( 'Color', 'elementor' ),
    187 				'type' => Controls_Manager::COLOR,
    188 				'global' => [
    189 					'default' => Global_Colors::COLOR_PRIMARY,
    190 				],
    191 				'selectors' => [
    192 					'{{WRAPPER}} .elementor-progress-wrapper .elementor-progress-bar' => 'background-color: {{VALUE}};',
    193 				],
    194 			]
    195 		);
    196 
    197 		$this->add_control(
    198 			'bar_bg_color',
    199 			[
    200 				'label' => esc_html__( 'Background Color', 'elementor' ),
    201 				'type' => Controls_Manager::COLOR,
    202 				'selectors' => [
    203 					'{{WRAPPER}} .elementor-progress-wrapper' => 'background-color: {{VALUE}};',
    204 				],
    205 			]
    206 		);
    207 
    208 		$this->add_control(
    209 			'bar_height',
    210 			[
    211 				'label' => esc_html__( 'Height', 'elementor' ),
    212 				'type' => Controls_Manager::SLIDER,
    213 				'selectors' => [
    214 					'{{WRAPPER}} .elementor-progress-bar' => 'height: {{SIZE}}{{UNIT}}; line-height: {{SIZE}}{{UNIT}};',
    215 				],
    216 			]
    217 		);
    218 
    219 		$this->add_control(
    220 			'bar_border_radius',
    221 			[
    222 				'label' => esc_html__( 'Border Radius', 'elementor' ),
    223 				'type' => Controls_Manager::SLIDER,
    224 				'size_units' => [ 'px', '%' ],
    225 				'selectors' => [
    226 					'{{WRAPPER}} .elementor-progress-wrapper' => 'border-radius: {{SIZE}}{{UNIT}}; overflow: hidden;',
    227 				],
    228 			]
    229 		);
    230 
    231 		$this->add_control(
    232 			'inner_text_heading',
    233 			[
    234 				'label' => esc_html__( 'Inner Text', 'elementor' ),
    235 				'type' => Controls_Manager::HEADING,
    236 				'separator' => 'before',
    237 			]
    238 		);
    239 
    240 		$this->add_control(
    241 			'bar_inline_color',
    242 			[
    243 				'label' => esc_html__( 'Color', 'elementor' ),
    244 				'type' => Controls_Manager::COLOR,
    245 				'selectors' => [
    246 					'{{WRAPPER}} .elementor-progress-bar' => 'color: {{VALUE}};',
    247 				],
    248 			]
    249 		);
    250 
    251 		$this->add_group_control(
    252 			Group_Control_Typography::get_type(),
    253 			[
    254 				'name' => 'bar_inner_typography',
    255 				'selector' => '{{WRAPPER}} .elementor-progress-bar',
    256 				'exclude' => [
    257 					'line_height',
    258 				],
    259 			]
    260 		);
    261 
    262 		$this->add_group_control(
    263 			Group_Control_Text_Shadow::get_type(),
    264 			[
    265 				'name' => 'bar_inner_shadow',
    266 				'selector' => '{{WRAPPER}} .elementor-progress-bar',
    267 			]
    268 		);
    269 
    270 		$this->end_controls_section();
    271 
    272 		$this->start_controls_section(
    273 			'section_title',
    274 			[
    275 				'label' => esc_html__( 'Title Style', 'elementor' ),
    276 				'tab' => Controls_Manager::TAB_STYLE,
    277 			]
    278 		);
    279 
    280 		$this->add_control(
    281 			'title_color',
    282 			[
    283 				'label' => esc_html__( 'Text Color', 'elementor' ),
    284 				'type' => Controls_Manager::COLOR,
    285 				'selectors' => [
    286 					'{{WRAPPER}} .elementor-title' => 'color: {{VALUE}};',
    287 				],
    288 				'global' => [
    289 					'default' => Global_Colors::COLOR_PRIMARY,
    290 				],
    291 			]
    292 		);
    293 
    294 		$this->add_group_control(
    295 			Group_Control_Typography::get_type(),
    296 			[
    297 				'name' => 'typography',
    298 				'selector' => '{{WRAPPER}} .elementor-title',
    299 				'global' => [
    300 					'default' => Global_Typography::TYPOGRAPHY_TEXT,
    301 				],
    302 			]
    303 		);
    304 
    305 		$this->add_group_control(
    306 			Group_Control_Text_Shadow::get_type(),
    307 			[
    308 				'name' => 'title_shadow',
    309 				'selector' => '{{WRAPPER}} .elementor-title',
    310 			]
    311 		);
    312 
    313 		$this->end_controls_section();
    314 	}
    315 
    316 	/**
    317 	 * Render progress widget output on the frontend.
    318 	 * Make sure value does no exceed 100%.
    319 	 *
    320 	 * Written in PHP and used to generate the final HTML.
    321 	 *
    322 	 * @since 1.0.0
    323 	 * @access protected
    324 	 */
    325 	protected function render() {
    326 		$settings = $this->get_settings_for_display();
    327 
    328 		$progress_percentage = is_numeric( $settings['percent']['size'] ) ? $settings['percent']['size'] : '0';
    329 		if ( 100 < $progress_percentage ) {
    330 			$progress_percentage = 100;
    331 		}
    332 
    333 		$this->add_render_attribute( 'title', [
    334 			'class' => 'elementor-title',
    335 		]);
    336 
    337 		$this->add_inline_editing_attributes( 'title' );
    338 
    339 		$this->add_render_attribute( 'wrapper', [
    340 			'class' => 'elementor-progress-wrapper',
    341 			'role' => 'progressbar',
    342 			'aria-valuemin' => '0',
    343 			'aria-valuemax' => '100',
    344 			'aria-valuenow' => $progress_percentage,
    345 			'aria-valuetext' => $settings['inner_text'],
    346 		] );
    347 
    348 		if ( ! empty( $settings['progress_type'] ) ) {
    349 			$this->add_render_attribute( 'wrapper', 'class', 'progress-' . $settings['progress_type'] );
    350 		}
    351 
    352 		$this->add_render_attribute( 'progress-bar', [
    353 			'class' => 'elementor-progress-bar',
    354 			'data-max' => $progress_percentage,
    355 		] );
    356 
    357 		$this->add_render_attribute( 'inner_text', [
    358 			'class' => 'elementor-progress-text',
    359 		] );
    360 
    361 		$this->add_inline_editing_attributes( 'inner_text' );
    362 
    363 		if ( ! Utils::is_empty( $settings['title'] ) ) { ?>
    364 			<span <?php $this->print_render_attribute_string( 'title' ); ?>><?php $this->print_unescaped_setting( 'title' ); ?></span>
    365 		<?php } ?>
    366 
    367 		<div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
    368 			<div <?php $this->print_render_attribute_string( 'progress-bar' ); ?>>
    369 				<span <?php $this->print_render_attribute_string( 'inner_text' ); ?>><?php $this->print_unescaped_setting( 'inner_text' ); ?></span>
    370 				<?php if ( 'hide' !== $settings['display_percentage'] ) { ?>
    371 					<span class="elementor-progress-percentage"><?php echo $progress_percentage; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>%</span>
    372 				<?php } ?>
    373 			</div>
    374 		</div>
    375 		<?php
    376 	}
    377 
    378 	/**
    379 	 * Render progress widget output in the editor.
    380 	 *
    381 	 * Written as a Backbone JavaScript template and used to generate the live preview.
    382 	 *
    383 	 * @since 2.9.0
    384 	 * @access protected
    385 	 */
    386 	protected function content_template() {
    387 		?>
    388 		<#
    389 		let progress_percentage = 0;
    390 		if ( ! isNaN( settings.percent.size ) ) {
    391 			progress_percentage = 100 < settings.percent.size ? 100 : settings.percent.size;
    392 		}
    393 
    394 		view.addRenderAttribute( 'title', {
    395 			'class': 'elementor-title'
    396 		} );
    397 
    398 		view.addInlineEditingAttributes( 'title' );
    399 
    400 		view.addRenderAttribute( 'progressWrapper', {
    401 			'class': [ 'elementor-progress-wrapper', 'progress-' + settings.progress_type ],
    402 			'role': 'progressbar',
    403 			'aria-valuemin': '0',
    404 			'aria-valuemax': '100',
    405 			'aria-valuenow': progress_percentage,
    406 			'aria-valuetext': settings.inner_text
    407 		} );
    408 
    409 		view.addRenderAttribute( 'inner_text', {
    410 			'class': 'elementor-progress-text'
    411 		} );
    412 
    413 		view.addInlineEditingAttributes( 'inner_text' );
    414 		#>
    415 		<# if ( settings.title ) { #>
    416 			<span {{{ view.getRenderAttributeString( 'title' ) }}}>{{{ settings.title }}}</span><#
    417 		} #>
    418 		<div {{{ view.getRenderAttributeString( 'progressWrapper' ) }}}>
    419 			<div class="elementor-progress-bar" data-max="{{ progress_percentage }}">
    420 				<span {{{ view.getRenderAttributeString( 'inner_text' ) }}}>{{{ settings.inner_text }}}</span>
    421 				<# if ( 'hide' !== settings.display_percentage ) { #>
    422 					<span class="elementor-progress-percentage">{{{ progress_percentage }}}%</span>
    423 				<# } #>
    424 			</div>
    425 		</div>
    426 		<?php
    427 	}
    428 }