theme-elements
6 months ago
accordion.php
6 months ago
audio.php
6 months ago
before-after.php
6 months ago
button.php
6 months ago
carousel-navigation.php
6 months ago
circle-chart.php
6 months ago
contact-box.php
6 months ago
contact-form.php
6 months ago
custom-list.php
6 months ago
divider.php
6 months ago
gallery.php
6 months ago
gmap.php
2 days ago
heading-modern.php
5 months ago
icon.php
6 months ago
image.php
6 months ago
mailchimp.php
6 months ago
modern-button.php
6 months ago
products-grid.php
6 months ago
quote.php
6 months ago
recent-comments.php
6 months ago
recent-posts-grid-carousel.php
1 month ago
recent-posts-land-style.php
6 months ago
recent-posts-masonry.php
6 months ago
recent-posts-tiles-carousel.php
6 months ago
recent-posts-tiles.php
6 months ago
recent-posts-timeline.php
6 months ago
recent-products.php
6 months ago
responsive-table.php
6 months ago
search.php
6 months ago
staff.php
6 months ago
svg.php
6 months ago
tabs.php
6 months ago
testimonial.php
6 months ago
text.php
6 months ago
touch-slider.php
6 months ago
video.php
6 months ago
before-after.php
325 lines
| 1 | <?php |
| 2 | namespace Auxin\Plugin\CoreElements\Elementor\Elements; |
| 3 | |
| 4 | use Elementor\Plugin; |
| 5 | use Elementor\Widget_Base; |
| 6 | use Elementor\Controls_Manager; |
| 7 | use Elementor\Group_Control_Image_Size; |
| 8 | |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; // Exit if accessed directly. |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Elementor 'BeforeAfter' widget. |
| 16 | * |
| 17 | * Elementor widget that displays an 'BeforeAfter' with lightbox. |
| 18 | * |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | class BeforeAfter extends Widget_Base { |
| 22 | |
| 23 | /** |
| 24 | * Get widget name. |
| 25 | * |
| 26 | * Retrieve 'BeforeAfter' widget name. |
| 27 | * |
| 28 | * @since 1.0.0 |
| 29 | * @access public |
| 30 | * |
| 31 | * @return string Widget name. |
| 32 | */ |
| 33 | public function get_name() { |
| 34 | return 'aux-before-after'; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Get widget title. |
| 39 | * |
| 40 | * Retrieve 'BeforeAfter' widget title. |
| 41 | * |
| 42 | * @since 1.0.0 |
| 43 | * @access public |
| 44 | * |
| 45 | * @return string Widget title. |
| 46 | */ |
| 47 | public function get_title() { |
| 48 | return __( 'Before After Slider', 'auxin-elements' ); |
| 49 | } |
| 50 | |
| 51 | public function has_widget_inner_wrapper(): bool { |
| 52 | return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /** |
| 57 | * Get widget icon. |
| 58 | * |
| 59 | * Retrieve 'BeforeAfter' widget icon. |
| 60 | * |
| 61 | * @since 1.0.0 |
| 62 | * @access public |
| 63 | * |
| 64 | * @return string Widget icon. |
| 65 | */ |
| 66 | public function get_icon() { |
| 67 | return 'eicon-image-before-after auxin-badge'; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get widget categories. |
| 72 | * |
| 73 | * Retrieve 'BeforeAfter' widget icon. |
| 74 | * |
| 75 | * @since 1.0.0 |
| 76 | * @access public |
| 77 | * |
| 78 | * @return string Widget icon. |
| 79 | */ |
| 80 | public function get_categories() { |
| 81 | return array( 'auxin-core' ); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Register 'BeforeAfter' widget controls. |
| 86 | * |
| 87 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 88 | * |
| 89 | * @since 1.0.0 |
| 90 | * @access protected |
| 91 | */ |
| 92 | protected function register_controls() { |
| 93 | |
| 94 | /*-----------------------------------------------------------------------------------*/ |
| 95 | /* images_section |
| 96 | /*-----------------------------------------------------------------------------------*/ |
| 97 | |
| 98 | $this->start_controls_section( |
| 99 | 'images_section', |
| 100 | array( |
| 101 | 'label' => __( 'Images', 'auxin-elements' ), |
| 102 | ) |
| 103 | ); |
| 104 | |
| 105 | $this->add_control( |
| 106 | 'before_image', |
| 107 | array( |
| 108 | 'label' => __('Before image','auxin-elements' ), |
| 109 | 'type' => Controls_Manager::MEDIA, |
| 110 | 'show_label' => false |
| 111 | ) |
| 112 | ); |
| 113 | |
| 114 | $this->add_group_control( |
| 115 | Group_Control_Image_Size::get_type(), |
| 116 | array( |
| 117 | 'name' => 'before', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`. |
| 118 | 'exclude' => array( 'custom' ), |
| 119 | 'separator' => 'none', |
| 120 | 'default' => 'large', |
| 121 | ) |
| 122 | ); |
| 123 | |
| 124 | $this->add_control( |
| 125 | 'after_image', |
| 126 | array( |
| 127 | 'label' => __('After image','auxin-elements' ), |
| 128 | 'type' => Controls_Manager::MEDIA, |
| 129 | 'show_label' => false |
| 130 | ) |
| 131 | ); |
| 132 | |
| 133 | $this->add_group_control( |
| 134 | Group_Control_Image_Size::get_type(), |
| 135 | array( |
| 136 | 'name' => 'after', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`. |
| 137 | 'exclude' => array( 'custom' ), |
| 138 | 'separator' => 'none', |
| 139 | 'default' => 'large', |
| 140 | ) |
| 141 | ); |
| 142 | |
| 143 | $this->end_controls_section(); |
| 144 | |
| 145 | /*-----------------------------------------------------------------------------------*/ |
| 146 | /* style_section |
| 147 | /*-----------------------------------------------------------------------------------*/ |
| 148 | |
| 149 | $this->start_controls_section( |
| 150 | 'style_section', |
| 151 | array( |
| 152 | 'label' => __( 'Style', 'auxin-elements' ), |
| 153 | 'tab' => Controls_Manager::TAB_STYLE |
| 154 | ) |
| 155 | ); |
| 156 | |
| 157 | $this->add_control( |
| 158 | 'default_offset', |
| 159 | array( |
| 160 | 'label' => __( 'Start offset','auxin-elements' ), |
| 161 | 'description' => __( 'How much of the before image is visible when the page loads.', 'auxin-elements' ), |
| 162 | 'type' => Controls_Manager::SLIDER, |
| 163 | 'size_units' => array('px'), |
| 164 | 'default' => array( |
| 165 | 'size' => 50 |
| 166 | ), |
| 167 | 'range' => array( |
| 168 | 'px' => array( |
| 169 | 'min' => 1, |
| 170 | 'max' => 100, |
| 171 | 'step' => 1 |
| 172 | ) |
| 173 | ) |
| 174 | ) |
| 175 | ); |
| 176 | |
| 177 | $this->add_control( |
| 178 | 'width', |
| 179 | array( |
| 180 | 'label' => __('Width','auxin-elements' ), |
| 181 | 'type' => Controls_Manager::SLIDER, |
| 182 | 'size_units' => array('px'), |
| 183 | 'range' => array( |
| 184 | 'px' => array( |
| 185 | 'min' => 1, |
| 186 | 'max' => 1400, |
| 187 | 'step' => 1, |
| 188 | ) |
| 189 | ), |
| 190 | 'selectors' => array( |
| 191 | '{{WRAPPER}} .aux-before-after' => 'max-width: {{SIZE}}{{UNIT}};', |
| 192 | ), |
| 193 | ) |
| 194 | ); |
| 195 | |
| 196 | $this->add_control( |
| 197 | 'height', |
| 198 | array( |
| 199 | 'label' => __('Height','auxin-elements' ), |
| 200 | 'type' => Controls_Manager::SLIDER, |
| 201 | 'size_units' => array('px'), |
| 202 | 'range' => array( |
| 203 | 'px' => array( |
| 204 | 'min' => 1, |
| 205 | 'max' => 1400, |
| 206 | 'step' => 1, |
| 207 | ) |
| 208 | ), |
| 209 | 'selectors' => array( |
| 210 | '{{WRAPPER}} .aux-before-after' => 'max-height: {{SIZE}}{{UNIT}};', |
| 211 | ), |
| 212 | ) |
| 213 | ); |
| 214 | |
| 215 | $this->end_controls_section(); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Render image box widget output on the frontend. |
| 220 | * |
| 221 | * Written in PHP and used to generate the final HTML. |
| 222 | * |
| 223 | * @since 1.0.0 |
| 224 | * @access protected |
| 225 | */ |
| 226 | protected function render() { |
| 227 | |
| 228 | $settings = $this->get_settings_for_display(); |
| 229 | $before_image = ''; |
| 230 | $after_image = ''; |
| 231 | |
| 232 | if( ! empty( $settings['before_image'] ) ) { |
| 233 | $before_image = Group_Control_Image_Size::get_attachment_image_html( $settings, 'before', 'before_image' ); |
| 234 | } |
| 235 | |
| 236 | if( ! empty( $settings['after_image'] ) ) { |
| 237 | $after_image = Group_Control_Image_Size::get_attachment_image_html( $settings, 'after', 'after_image' ); |
| 238 | } |
| 239 | |
| 240 | $this->add_render_attribute( |
| 241 | 'wrapper', |
| 242 | [ |
| 243 | 'class' => [ 'aux-before-after' ], |
| 244 | 'data-offset' => ( (int) $settings['default_offset']['size'] ) / 100 |
| 245 | ] |
| 246 | ); |
| 247 | |
| 248 | if ( Plugin::instance()->editor->is_edit_mode() ) { |
| 249 | $this->add_render_attribute( 'wrapper', [ |
| 250 | 'class' => 'elementor-clickable', |
| 251 | ] ); |
| 252 | } |
| 253 | |
| 254 | if( ! empty( $settings['after_image'] ) ) { |
| 255 | echo sprintf( '<div class="widget-container aux-widget-before-after"><div %s >%s %s</div></div>', |
| 256 | $this->get_render_attribute_string( 'wrapper' ), |
| 257 | wp_kses_post( $before_image ), |
| 258 | wp_kses_post( $after_image ) |
| 259 | ) ; |
| 260 | } else { |
| 261 | echo sprintf( '<div class="widget-container aux-widget-before-after"><div %s >%s</div></div>', |
| 262 | $this->get_render_attribute_string( 'wrapper' ), |
| 263 | wp_kses_post( $before_image ) |
| 264 | ); |
| 265 | } |
| 266 | |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Render image box widget output in the editor. |
| 271 | * |
| 272 | * Written as a Backbone JavaScript template and used to generate the live preview. |
| 273 | * |
| 274 | * @since 1.0.0 |
| 275 | * @access protected |
| 276 | */ |
| 277 | protected function content_template() { |
| 278 | ?> |
| 279 | <# |
| 280 | |
| 281 | var images = ''; |
| 282 | |
| 283 | if ( settings.before_image ) { |
| 284 | var before_image = { |
| 285 | id: settings.before_image.id, |
| 286 | url: settings.before_image.url, |
| 287 | size: settings.before_size, |
| 288 | dimension: settings.before_custom_dimension, |
| 289 | model: view.getEditModel() |
| 290 | }; |
| 291 | var before_image_url = elementor.imagesManager.getImageUrl( before_image ); |
| 292 | images += '<img src="' + before_image_url + '" />'; |
| 293 | } |
| 294 | |
| 295 | if ( settings.after_image ) { |
| 296 | var after_image = { |
| 297 | id: settings.after_image.id, |
| 298 | url: settings.after_image.url, |
| 299 | size: settings.after_size, |
| 300 | dimension: settings.after_custom_dimension, |
| 301 | model: view.getEditModel() |
| 302 | }; |
| 303 | var after_image_url = elementor.imagesManager.getImageUrl( after_image ); |
| 304 | images += '<img src="' + after_image_url + '" />'; |
| 305 | } |
| 306 | |
| 307 | view.addRenderAttribute( |
| 308 | 'wrapper', |
| 309 | { |
| 310 | 'class' : [ 'aux-before-after' ], |
| 311 | 'data-offset': Number( settings.default_offset.size )/100 |
| 312 | } |
| 313 | ); |
| 314 | |
| 315 | #> |
| 316 | <div class="widget-container aux-widget-before-after"> |
| 317 | <div {{{ view.getRenderAttributeString( 'wrapper' ) }}}> |
| 318 | {{{ images }}} |
| 319 | <div> |
| 320 | </div> |
| 321 | <?php |
| 322 | } |
| 323 | |
| 324 | } |
| 325 |