| @@ -1,117 +1,135 @@ | ||
| 1 | -<?php | |
| 2 | -namespace Easyel\EasyElements\Widgets; | |
| 3 | -use Elementor\Controls_Manager; | |
| 4 | -use Elementor\Widget_Base; | |
| 5 | - | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 7 | - exit; | |
| 8 | -} | |
| 9 | - | |
| 10 | -class Easyel_Scroll_To_Top_Widget extends \Elementor\Widget_Base { | |
| 11 | - | |
| 12 | - | |
| 13 | - public function get_name() { | |
| 14 | - return 'eel-scroll-to-top'; | |
| 15 | - } | |
| 16 | - | |
| 17 | - public function get_title() { | |
| 18 | - return __( 'Scroll Top', 'easy-elements' ); | |
| 19 | - } | |
| 20 | - | |
| 21 | - public function get_icon() { | |
| 22 | - return 'easyicon easyelIcon-scroll-top'; | |
| 23 | - } | |
| 24 | - | |
| 25 | - public function get_categories() { | |
| 26 | - return [ 'easyelements_category' ]; | |
| 27 | - } | |
| 28 | - | |
| 29 | - public function get_keywords() { | |
| 30 | - return [ 'scroll', 'top', 'back', 'to', 'text' ]; | |
| 31 | - } | |
| 32 | - | |
| 33 | - public function get_style_depends() { | |
| 34 | - return [ | |
| 35 | - 'eel-scroll-to-top', | |
| 36 | - ]; | |
| 37 | - } | |
| 38 | - | |
| 39 | - public function get_script_depends() { | |
| 40 | - return [ | |
| 41 | - 'eel-scroll-to-top', | |
| 42 | - ]; | |
| 43 | - } | |
| 44 | - | |
| 45 | - protected function register_controls() { | |
| 46 | - // Example: Style section for button | |
| 47 | - $this->start_controls_section( | |
| 48 | - 'section_scroll_setting', | |
| 49 | - [ | |
| 50 | - 'label' => __( 'Scroll Button', 'easy-elements' ), | |
| 51 | - 'tab' => Controls_Manager::TAB_CONTENT, | |
| 52 | - ] | |
| 53 | - ); | |
| 54 | - | |
| 55 | - $this->add_control( | |
| 56 | - 'scroll_btn_icon', | |
| 57 | - [ | |
| 58 | - 'label' => __( 'Icon', 'easy-elements' ), | |
| 59 | - 'type' => Controls_Manager::ICONS, | |
| 60 | - ] | |
| 61 | - ); | |
| 62 | - $this->end_controls_section(); | |
| 63 | - | |
| 64 | - $this->start_controls_section( | |
| 65 | - 'section_scroll_style', | |
| 66 | - [ | |
| 67 | - 'label' => __( 'Scroll Button', 'easy-elements' ), | |
| 68 | - 'tab' => Controls_Manager::TAB_STYLE, | |
| 69 | - ] | |
| 70 | - ); | |
| 71 | - | |
| 72 | - $this->add_control( | |
| 73 | - 'scroll_btn_color', | |
| 74 | - [ | |
| 75 | - 'label' => __( 'Color', 'easy-elements' ), | |
| 76 | - 'type' => Controls_Manager::COLOR, | |
| 77 | - 'selectors' => [ | |
| 78 | - '{{WRAPPER}} #easyel-top-to-bottom i' => 'color: {{VALUE}};', | |
| 79 | - '{{WRAPPER}} #easyel-top-to-bottom svg, {{WRAPPER}} #easyel-top-to-bottom svg path' => 'fill: {{VALUE}};', | |
| 80 | - ], | |
| 81 | - ] | |
| 82 | - ); | |
| 83 | - | |
| 84 | - $this->add_control( | |
| 85 | - 'scroll_btn_bg', | |
| 86 | - [ | |
| 87 | - 'label' => __( 'Background Color', 'easy-elements' ), | |
| 88 | - 'type' => Controls_Manager::COLOR, | |
| 89 | - 'selectors' => [ | |
| 90 | - '{{WRAPPER}} #easyel-top-to-bottom' => 'background-color: {{VALUE}};', | |
| 91 | - ], | |
| 92 | - ] | |
| 93 | - ); | |
| 94 | - | |
| 95 | - $this->end_controls_section(); | |
| 96 | - } | |
| 97 | - | |
| 98 | - protected function render() { | |
| 99 | - $settings = $this->get_settings_for_display(); | |
| 100 | - ?> | |
| 101 | - <div id="easyel-top-to-bottom"> | |
| 102 | - <?php | |
| 103 | - if ( ! empty( $settings['scroll_btn_icon']['value'] ) ) { | |
| 104 | - \Elementor\Icons_Manager::render_icon( | |
| 105 | - $settings['scroll_btn_icon'], | |
| 106 | - [ 'aria-hidden' => 'true' ] | |
| 107 | - ); | |
| 108 | - } else { | |
| 109 | - ?> | |
| 110 | - <i class="unicon-arrow-up"></i> | |
| 111 | - <?php | |
| 112 | - } | |
| 113 | - ?> | |
| 114 | - </div> | |
| 115 | - <?php | |
| 116 | - } | |
| 117 | -} | |
| 1 | +<?php | |
| 2 | +use Elementor\Controls_Manager; | |
| 3 | +use Elementor\Widget_Base; | |
| 4 | + | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 9 | +class Easyel_Scroll_To_Top_Widget extends \Elementor\Widget_Base { | |
| 10 | + | |
| 11 | + public function get_style_depends() { | |
| 12 | + $handle = 'eel-scroll-style'; | |
| 13 | + $css_path = plugin_dir_path( __FILE__ ) . 'css/scroll.css'; | |
| 14 | + | |
| 15 | + if ( ! wp_style_is( $handle, 'registered' ) && file_exists( $css_path ) ) { | |
| 16 | + wp_register_style( | |
| 17 | + $handle, | |
| 18 | + plugins_url( 'css/scroll.css', __FILE__ ), | |
| 19 | + [], | |
| 20 | + defined( 'WP_DEBUG' ) && WP_DEBUG ? filemtime( $css_path ) : EASYELEMENTS_VER | |
| 21 | + ); | |
| 22 | + } | |
| 23 | + return [ $handle ]; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public function get_script_depends() { | |
| 27 | + $handle = 'eel-scroll-script'; | |
| 28 | + $js_path = plugin_dir_path( __FILE__ ) . 'js/scroll.js'; | |
| 29 | + | |
| 30 | + if ( ! wp_script_is( $handle, 'registered' ) && file_exists( $js_path ) ) { | |
| 31 | + wp_register_script( | |
| 32 | + $handle, | |
| 33 | + plugins_url( 'js/scroll.js', __FILE__ ), | |
| 34 | + [ 'jquery' ], | |
| 35 | + defined( 'WP_DEBUG' ) && WP_DEBUG ? filemtime( $js_path ) : EASYELEMENTS_VER, | |
| 36 | + true | |
| 37 | + ); | |
| 38 | + } | |
| 39 | + return [ $handle ]; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public function get_name() { | |
| 43 | + return 'eel-scroll-to-top'; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public function get_title() { | |
| 47 | + return __( 'Scroll Top', 'easy-elements' ); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public function get_icon() { | |
| 51 | + return 'easyicon easyelIcon-scroll-top'; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public function get_categories() { | |
| 55 | + return [ 'easyelements_category' ]; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public function get_keywords() { | |
| 59 | + return [ 'scroll', 'top', 'back', 'to', 'text' ]; | |
| 60 | + } | |
| 61 | + | |
| 62 | + protected function register_controls() { | |
| 63 | + // Example: Style section for button | |
| 64 | + $this->start_controls_section( | |
| 65 | + 'section_scroll_setting', | |
| 66 | + [ | |
| 67 | + 'label' => __( 'Scroll Button', 'easy-elements' ), | |
| 68 | + 'tab' => Controls_Manager::TAB_CONTENT, | |
| 69 | + ] | |
| 70 | + ); | |
| 71 | + | |
| 72 | + $this->add_control( | |
| 73 | + 'scroll_btn_icon', | |
| 74 | + [ | |
| 75 | + 'label' => __( 'Icon', 'easy-elements' ), | |
| 76 | + 'type' => Controls_Manager::ICONS, | |
| 77 | + ] | |
| 78 | + ); | |
| 79 | + $this->end_controls_section(); | |
| 80 | + | |
| 81 | + $this->start_controls_section( | |
| 82 | + 'section_scroll_style', | |
| 83 | + [ | |
| 84 | + 'label' => __( 'Scroll Button', 'easy-elements' ), | |
| 85 | + 'tab' => Controls_Manager::TAB_STYLE, | |
| 86 | + ] | |
| 87 | + ); | |
| 88 | + | |
| 89 | + $this->add_control( | |
| 90 | + 'scroll_btn_color', | |
| 91 | + [ | |
| 92 | + 'label' => __( 'Color', 'easy-elements' ), | |
| 93 | + 'type' => Controls_Manager::COLOR, | |
| 94 | + 'selectors' => [ | |
| 95 | + '{{WRAPPER}} #easyel-top-to-bottom i' => 'color: {{VALUE}};', | |
| 96 | + '{{WRAPPER}} #easyel-top-to-bottom svg, {{WRAPPER}} #easyel-top-to-bottom svg path' => 'fill: {{VALUE}};', | |
| 97 | + ], | |
| 98 | + ] | |
| 99 | + ); | |
| 100 | + | |
| 101 | + $this->add_control( | |
| 102 | + 'scroll_btn_bg', | |
| 103 | + [ | |
| 104 | + 'label' => __( 'Background Color', 'easy-elements' ), | |
| 105 | + 'type' => Controls_Manager::COLOR, | |
| 106 | + 'selectors' => [ | |
| 107 | + '{{WRAPPER}} #easyel-top-to-bottom' => 'background-color: {{VALUE}};', | |
| 108 | + ], | |
| 109 | + ] | |
| 110 | + ); | |
| 111 | + | |
| 112 | + $this->end_controls_section(); | |
| 113 | + } | |
| 114 | + | |
| 115 | + protected function render() { | |
| 116 | + $settings = $this->get_settings_for_display(); | |
| 117 | + ?> | |
| 118 | + <div id="easyel-top-to-bottom"> | |
| 119 | + <?php | |
| 120 | + if ( ! empty( $settings['scroll_btn_icon']['value'] ) ) { | |
| 121 | + \Elementor\Icons_Manager::render_icon( | |
| 122 | + $settings['scroll_btn_icon'], | |
| 123 | + [ 'aria-hidden' => 'true' ] | |
| 124 | + ); | |
| 125 | + } else { | |
| 126 | + ?> | |
| 127 | + <i class="unicon-arrow-up"></i> | |
| 128 | + <?php | |
| 129 | + } | |
| 130 | + ?> | |
| 131 | + </div> | |
| 132 | + <?php | |
| 133 | + } | |
| 134 | +} | |
| 135 | +?> | |