config.php
220 lines
| 1 | <?php |
| 2 | namespace ShopPress\Elementor\Widgets; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | use Elementor\Controls_Manager; |
| 7 | use ShopPress\Elementor\ShopPressWidgets; |
| 8 | |
| 9 | class Compare extends ShopPressWidgets { |
| 10 | |
| 11 | public function get_name() { |
| 12 | return 'sp-single-compare'; |
| 13 | } |
| 14 | |
| 15 | public function get_title() { |
| 16 | return __( 'Compare Button', 'shop-press' ); |
| 17 | } |
| 18 | |
| 19 | public function get_icon() { |
| 20 | return 'sp-widget sp-eicon-compare'; |
| 21 | } |
| 22 | |
| 23 | public function get_categories() { |
| 24 | return array( 'sp_woo_single' ); |
| 25 | } |
| 26 | |
| 27 | public function get_script_depends() { |
| 28 | return array( 'sp-compare' ); |
| 29 | } |
| 30 | |
| 31 | public function get_style_depends() { |
| 32 | if ( is_rtl() ) { |
| 33 | return array( 'sp-compare', 'sp-wishlist', 'sp-compare-rtl', 'sp-wishlist-rtl' ); |
| 34 | } else { |
| 35 | return array( 'sp-compare', 'sp-wishlist' ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | public function setup_styling_options() { |
| 40 | $this->register_group_styler( |
| 41 | 'wrapper', |
| 42 | __( 'Wrapper', 'shop-press' ), |
| 43 | array( |
| 44 | 'wrapper' => array( |
| 45 | 'label' => esc_html__( 'Wrapper', 'shop-press' ), |
| 46 | 'type' => 'styler', |
| 47 | 'selector' => '.sp-single-compare', |
| 48 | 'wrapper' => '{{WRAPPER}}', |
| 49 | ), |
| 50 | 'button' => array( |
| 51 | 'label' => esc_html__( 'Button', 'shop-press' ), |
| 52 | 'type' => 'styler', |
| 53 | 'selector' => '.sp-compare-button', |
| 54 | 'wrapper' => '{{WRAPPER}} .sp-single-compare', |
| 55 | ), |
| 56 | ) |
| 57 | ); |
| 58 | |
| 59 | $this->register_group_styler( |
| 60 | 'label', |
| 61 | __( 'Label', 'shop-press' ), |
| 62 | array( |
| 63 | 'label' => array( |
| 64 | 'label' => esc_html__( 'Label', 'shop-press' ), |
| 65 | 'type' => 'styler', |
| 66 | 'selector' => '.sp-compare-label', |
| 67 | 'wrapper' => '{{WRAPPER}} .sp-compare-button', |
| 68 | ), |
| 69 | 'active_label' => array( |
| 70 | 'label' => esc_html__( 'Active Label', 'shop-press' ), |
| 71 | 'type' => 'styler', |
| 72 | 'selector' => '.sp-compare-label', |
| 73 | 'wrapper' => '{{WRAPPER}} .sp-single-compare[data-status="yes"] .sp-compare-button', |
| 74 | ), |
| 75 | ) |
| 76 | ); |
| 77 | |
| 78 | $this->register_group_styler( |
| 79 | 'icon', |
| 80 | __( 'Icon', 'shop-press' ), |
| 81 | array( |
| 82 | 'icon_wrapper' => array( |
| 83 | 'label' => esc_html__( 'Icon Wrapper', 'shop-press' ), |
| 84 | 'type' => 'styler', |
| 85 | 'selector' => '.sp-compare-icon', |
| 86 | 'wrapper' => '{{WRAPPER}} .sp-compare-button', |
| 87 | ), |
| 88 | 'icon' => array( |
| 89 | 'label' => esc_html__( 'Icon', 'shop-press' ), |
| 90 | 'type' => 'styler', |
| 91 | 'selector' => 'i.sp-icon', |
| 92 | 'wrapper' => '{{WRAPPER}} .sp-compare-button .sp-compare-icon', |
| 93 | ), |
| 94 | 'active_icon' => array( |
| 95 | 'label' => esc_html__( 'Active Icon', 'shop-press' ), |
| 96 | 'type' => 'styler', |
| 97 | 'selector' => 'i.sp-icon', |
| 98 | 'wrapper' => '{{WRAPPER}} .sp-single-compare[data-status="yes"] .sp-compare-button .sp-compare-icon', |
| 99 | ), |
| 100 | ) |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | protected function register_controls() { |
| 105 | $this->start_controls_section( |
| 106 | 'section_content', |
| 107 | array( |
| 108 | 'label' => __( 'Settings', 'shop-press' ), |
| 109 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 110 | ) |
| 111 | ); |
| 112 | |
| 113 | $this->add_control( |
| 114 | 'type', |
| 115 | array( |
| 116 | 'label' => __( 'Type', 'shop-press' ), |
| 117 | 'type' => Controls_Manager::SELECT, |
| 118 | 'options' => array( |
| 119 | 'icon' => __( 'Icon', 'shop-press' ), |
| 120 | 'label' => __( 'Label', 'shop-press' ), |
| 121 | 'icon-label' => __( 'Icon + Label', 'shop-press' ), |
| 122 | ), |
| 123 | 'default' => 'icon-label', |
| 124 | ) |
| 125 | ); |
| 126 | |
| 127 | $this->add_control( |
| 128 | 'icon', |
| 129 | array( |
| 130 | 'label' => __( 'Icon', 'shop-press' ), |
| 131 | 'type' => Controls_Manager::ICONS, |
| 132 | 'exclude_inline_options' => array( 'svg' ), |
| 133 | 'condition' => array( |
| 134 | 'type!' => 'label', |
| 135 | ), |
| 136 | ) |
| 137 | ); |
| 138 | |
| 139 | $this->end_controls_section(); |
| 140 | $this->setup_styling_options(); |
| 141 | |
| 142 | do_action( 'shoppress/elementor/widget/register_controls_init', $this ); |
| 143 | } |
| 144 | |
| 145 | protected function render() { |
| 146 | $settings = $this->get_settings_for_display(); |
| 147 | |
| 148 | do_action( 'shoppress/widget/before_render', $settings ); |
| 149 | |
| 150 | $args = array( |
| 151 | 'type' => $settings['type'], |
| 152 | 'icon' => $settings['icon'], |
| 153 | ); |
| 154 | |
| 155 | if ( $this->editor_preview() ) { |
| 156 | |
| 157 | if ( $this->is_editor() ) { |
| 158 | ?> |
| 159 | <script> |
| 160 | (function($){ |
| 161 | shoppress_compare_init($); |
| 162 | })(jQuery); |
| 163 | </script> |
| 164 | <?php |
| 165 | } |
| 166 | sp_load_builder_template( 'single-product/product-compare', $args ); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | protected function content_template() { |
| 171 | $label = sp_get_module_settings( 'compare', 'add_label' ); |
| 172 | ?> |
| 173 | |
| 174 | <# |
| 175 | var iconHTML = elementor.helpers.renderIcon( view, settings.icon, { 'aria-hidden': true }, 'i' , 'object' ); |
| 176 | #> |
| 177 | <div class="sp-single-compare sp-compare-button-wrapper"> |
| 178 | <div class="sp-compare-button"> |
| 179 | <# if ( 'label' === settings.type ) { #> |
| 180 | <span class="sp-compare-label"><?php echo esc_html( $label ); ?></span> |
| 181 | <# } #> |
| 182 | |
| 183 | <# if ( 'icon' === settings.type ) { #> |
| 184 | <span class="sp-compare-icon"> |
| 185 | <# if ( iconHTML.value ) { #> |
| 186 | <# if ( 'svg' === settings.icon.library ) {#> |
| 187 | <i class="sp-icon"> |
| 188 | {{{ iconHTML.value }}} |
| 189 | </i> |
| 190 | <# } else { #> |
| 191 | {{{ iconHTML.value }}} |
| 192 | <# } #> |
| 193 | <# } else { #> |
| 194 | <?php echo wp_kses( sp_get_svg_icon( 'compare' ), sp_allowd_svg_tags() ); ?> |
| 195 | <# } #> |
| 196 | </span> |
| 197 | <# } #> |
| 198 | |
| 199 | <# if ( 'icon-label' === settings.type ) { #> |
| 200 | <span class="sp-compare-icon"> |
| 201 | <# if ( iconHTML.value ) { #> |
| 202 | <# if ( 'svg' === settings.icon.library ) {#> |
| 203 | <i class="sp-icon"> |
| 204 | {{{ iconHTML.value }}} |
| 205 | </i> |
| 206 | <# } else { #> |
| 207 | {{{ iconHTML.value }}} |
| 208 | <# } #> |
| 209 | <# } else { #> |
| 210 | <?php echo wp_kses( sp_get_svg_icon( 'compare' ), sp_allowd_svg_tags() ); ?> |
| 211 | <# } #> |
| 212 | </span> |
| 213 | <span class="sp-compare-label"><?php echo esc_html( $label ); ?></span> |
| 214 | <# } #> |
| 215 | </div> |
| 216 | </div> |
| 217 | <?php |
| 218 | } |
| 219 | } |
| 220 |