XylotrechusZ
<?php
/**
* Elementor RS Button Widget.
*
* Elementor widget that inserts an embbedable content into the page, from any given URL.
*
* @since 1.0.0
*/
use Elementor\Group_Control_Css_Filter;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Typography;
use Elementor\Core\Schemes\Typography;
use Elementor\Group_Control_Border;
use Elementor\Core\Schemes\Color;
use Elementor\Group_Control_Background;
use Elementor\register_controls;
defined( 'ABSPATH' ) || die();
class Rsaddon_pro_Button_Widget extends \Elementor\Widget_Base {
/**
* Get widget name.
*
* Retrieve counter widget name.
*
* @since 1.0.0
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'rs-button';
}
/**
* Get widget title.
*
* Retrieve counter widget title.
*
* @since 1.0.0
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return esc_html__( 'RS Button', 'rsaddon' );
}
/**
* Get widget icon.
*
* Retrieve counter widget icon.
*
* @since 1.0.0
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'glyph-icon flaticon-menu';
}
/**
* Retrieve the list of scripts the counter widget depended on.
*
* Used to set scripts dependencies required to run the widget.
*
* @since 1.3.0
* @access public
*
* @return array Widget scripts dependencies.
*/
public function get_categories() {
return [ 'rsaddon_category' ];
}
/**
* Get widget keywords.
*
* Retrieve the list of keywords the widget belongs to.
*
* @since 2.1.0
* @access public
*
* @return array Widget keywords.
*/
public function get_keywords() {
return [ 'button' ];
}
/**
* Register counter widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
* @access protected
*/
protected function register_controls() {
$this->start_controls_section(
'section_button',
[
'label' => esc_html__( 'Content', 'rsaddon' ),
]
);
$this->add_control(
'button_style',
[
'label' => esc_html__( 'Select Button Style', 'rsaddon' ),
'type' => Controls_Manager::SELECT,
'default' => 'style1',
'options' => [
'style1' => esc_html__( 'Style 1', 'rsaddon'),
'style2' => esc_html__( 'Style 2', 'rsaddon'),
],
]
);
$this->add_control(
'btn_text',
[
'label' => esc_html__( 'Button Text', 'rsaddon' ),
'type' => Controls_Manager::TEXT,
'label_block' => true,
'default' => 'Sample',
'placeholder' => esc_html__( 'Button Text', 'rsaddon' ),
'separator' => 'before',
]
);
$this->add_control(
'btn_link',
[
'label' => esc_html__( ' Button Link', 'rsaddon' ),
'type' => Controls_Manager::URL,
'label_block' => true,
]
);
$this->add_responsive_control(
'align',
[
'label' => esc_html__( 'Alignment', 'rsaddon' ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => esc_html__( 'Left', 'rsaddon' ),
'icon' => 'fa fa-align-left',
],
'center' => [
'title' => esc_html__( 'Center', 'rsaddon' ),
'icon' => 'fa fa-align-center',
],
'right' => [
'title' => esc_html__( 'Right', 'rsaddon' ),
'icon' => 'fa fa-align-right',
],
'justify' => [
'title' => esc_html__( 'Justify', 'rsaddon' ),
'icon' => 'fa fa-align-justify',
],
],
'toggle' => true,
'selectors' => [
'{{WRAPPER}} .rs-view-btn.rs-view-btn2, {{WRAPPER}} .rs-btn' => 'text-align: {{VALUE}}'
]
]
);
$this->add_control(
'icon',
[
'label' => esc_html__( 'Icon', 'rsaddon' ),
'type' => Controls_Manager::HEADING,
]
);
$this->add_control(
'show_icon',
[
'label' => esc_html__( 'Show Icon', 'rsaddon' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'rsaddon' ),
'label_off' => esc_html__( 'Hide', 'rsaddon' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'btn_icon',
[
'label' => esc_html__( 'Icon', 'rsaddon' ),
'type' => Controls_Manager::ICON,
'options' => rsaddon_pro_get_icons(),
'default' => 'fa fa-angle-right',
'separator' => 'before',
'condition' => [
'show_icon' => 'yes',
],
]
);
$this->add_control(
'btn_icon_spacing',
[
'label' => esc_html__( 'Icon Spacing', 'rsaddon' ),
'type' => Controls_Manager::SLIDER,
'default' => [
'size' => 10
],
'condition' => [
'services_btn_icon!' => '',
],
'selectors' => [
'{{WRAPPER}} .rs-btn i' => 'margin-left: {{SIZE}}{{UNIT}};',
],
'condition' => [
'show_icon' => 'yes',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'_section_style_button',
[
'label' => esc_html__( 'Button', 'rsaddon' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->start_controls_tabs( '_tabs_button' );
$this->start_controls_tab(
'style_normal_tab',
[
'label' => esc_html__( 'Normal', 'rsaddon' ),
]
);
$this->add_control(
'btn_text_color',
[
'label' => esc_html__( 'Text Color', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .rs-view-btn a, {{WRAPPER}} .rs-btn a' => 'color: {{VALUE}};',
],
]
);
$this->add_responsive_control(
'link_padding',
[
'label' => esc_html__( 'Padding', 'rsaddon' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .rs-btn a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'btn_typography',
'selector' => '{{WRAPPER}} .rs-view-btn a, {{WRAPPER}} .rs-btn a',
'scheme' => Typography::TYPOGRAPHY_4,
]
);
$this->add_group_control(
Group_Control_Background::get_type(),
[
'name' => 'background_normal',
'label' => esc_html__( 'Background', 'rsaddon' ),
'types' => [ 'classic', 'gradient' ],
'selector' => '{{WRAPPER}} .rs-btn a',
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'button_border',
'selector' => '{{WRAPPER}} .rs-btn a',
]
);
$this->add_control(
'button_border_radius',
[
'label' => esc_html__( 'Border Radius', 'rsaddon' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .rs-btn a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Box_Shadow::get_type(),
[
'name' => 'button_box_shadow',
'selector' => '{{WRAPPER}} .rs-btn a',
]
);
$this->add_control(
'btn_border_color',
[
'label' => esc_html__( 'Button Border Color', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack .rs_btn__text span::after, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack .rs_btn__text span::before, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack .rs_btn__text::after, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack .rs_btn__text::before, {{WRAPPER}} .rs-btn.rs-btnblack .rs_btn__text::before, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack:hover .rs_btn__text span::after, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack:hover .rs_btn__text::after, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack:hover .rs_btn__text span::before, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack:hover .rs_btn__text::before, {{WRAPPER}} .rs-view-btn .rs-btn.rs-btnblack::before' => 'background-color: {{VALUE}};',
],
'condition' => [
'button_style' => 'style2',
],
]
);
$this->end_controls_tab();
$this->start_controls_tab(
'style_hover_tab',
[
'label' => esc_html__( 'Hover', 'rsaddon' ),
]
);
$this->add_control(
'btn_text_hover_color',
[
'label' => esc_html__( 'Text Color', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .rs-view-btn a, {{WRAPPER}} .rs-btn a:hover' => 'color: {{VALUE}};',
],
]
);
$this->add_responsive_control(
'link_hover_padding',
[
'label' => esc_html__( 'Padding', 'rsaddon' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .rs-btn a:hover' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'btn_hover_typography',
'selector' => '{{WRAPPER}} .rs-btn a:hover',
'scheme' => Typography::TYPOGRAPHY_4,
]
);
$this->add_group_control(
Group_Control_Background::get_type(),
[
'name' => 'background',
'label' => esc_html__( 'Background', 'rsaddon' ),
'types' => [ 'classic', 'gradient' ],
'selector' => '{{WRAPPER}} .rs-btn a:hover',
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'button_hover_border',
'selector' => '{{WRAPPER}} .rs-btn a:hover',
]
);
$this->add_control(
'button_hover_border_radius',
[
'label' => esc_html__( 'Border Radius', 'rsaddon' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .rs-btn a:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Box_Shadow::get_type(),
[
'name' => 'button_hover_box_shadow',
'selector' => '{{WRAPPER}} .rs-btn a:hover',
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->end_controls_section();
$this->start_controls_section(
'_section_style_icon',
[
'label' => esc_html__( 'Icon', 'rsaddon' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'icon_text_color',
[
'label' => esc_html__( 'Color', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .rs-btn a i' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'icon_hover_color',
[
'label' => esc_html__( 'Hover Color', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .rs-btn a:hover i' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'icon_background', [
'label' => esc_html__( 'Background', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => ['{{WRAPPER}} .rs-btn a i' => 'background: {{VALUE}};',],
]
);
$this->add_control(
'icon_hover_background', [
'label' => esc_html__( 'Hover Background', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => ['{{WRAPPER}} .rs-btn a:hover i'=> 'background: {{VALUE}};',],
]
);
$this->add_responsive_control(
'icon_padding',
[
'label' => esc_html__( 'Padding', 'rsaddon' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} .rs-btn a i' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'icon_button_border',
'selector' => '{{WRAPPER}} .rs-btn i',
]
);
$this->add_control(
'icon_border_radius',
[
'label' => esc_html__( 'Border Radius', 'rsaddon' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .rs-btn a i' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'icon_hover_border_color',
[
'label' => esc_html__( 'Icon Hover Border Color', 'rsaddon' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .rs-btn a.rs_button:hover i' => 'border-color: {{VALUE}};',
],
]
);
$this->end_controls_section();
}
/**
* Render counter widget output in the editor.
*
* Written as a Backbone JavaScript template and used to generate the live preview.
*
* @since 1.0.0
* @access protected
*/
/**
* Render counter widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
* @access protected
*/
protected function render() {
$settings = $this->get_settings_for_display();
$this->add_inline_editing_attributes( 'btn_text', 'basic' );
$this->add_render_attribute( 'btn_text', 'class', 'btn_text' );
?>
<?php if('style2' == $settings['button_style']){ ?>
<div class="rs-view-btn rs-view-btn2"> <a class="rs-btn rs-btnblack" href="<?php echo esc_url($settings['btn_link']['url']);?>">
<span class="rs_btn__text">
<span class="btn_text"><?php echo esc_html($settings['btn_text']);?></span>
</span> </a>
</div>
<?php } else{ ?>
<div class="rs-btn">
<?php $target = $settings['btn_link']['is_external'] ? 'target=_blank' : '';?>
<a class="rs_button" href="<?php echo esc_url($settings['btn_link']['url']);?>" <?php echo esc_attr($target);?>>
<span <?php echo wp_kses_post($this->print_render_attribute_string('btn_text'));?>><?php echo esc_html($settings['btn_text']);?></span>
<?php if(!empty($settings['btn_icon'])) : ?>
<i class="fa <?php echo esc_html($settings['btn_icon']);?>"></i>
<?php endif; ?>
</a>
</div>
<?php } ?>
<?php
}
}