Join

Allow MyListing Quick Search in Elementor Popup

Don't want to mess with code snippets? Request for this to be a feature of MyListing Pro.

Instructions

  1. Create a new JS code snippet.
  2. Copy the contents of code snippet below.
  3. Paste the contents into your code snippet.
  4. Review any notes that I’ve provided.
  5. Save and enable the code snippet.
  6. Test.

Snippet

jQuery( document ).on( 'elementor/popup/show', ( event, id, instance ) => {
    jQuery(function ($) {
        $('.quick-search-instance').each(function (i, el) {
          var instance = {};
          instance.el = $(this);
          instance.input = instance.el.find('input[name="search_keywords"]');
          instance.default = instance.el.find('.default-results');
          instance.results = instance.el.find('.ajax-results');
          instance.spinner = instance.el.find('.loader-bg');
          instance.view_all = instance.el.find('.all-results');
          instance.no_results = instance.el.find('.no-results');
          instance.last_request = null;
          instance.input.on('input', MyListing.Helpers.debounce(function (e) {
            quicksearch(instance);
          }, 250)).trigger('input');
           if (instance.el.data('focus') === 'always') {
            instance.el.find('.header-search').addClass('is-focused');
          } else {
            instance.el.on('focusin', function () {
              instance.el.find('.header-search').addClass('is-focused');
            }).on('focusout', function () {
              instance.el.find('.header-search').removeClass('is-focused');
            });
          }
        });
         var quicksearch = function quicksearch(instance) {
          instance.spinner.hide();
          instance.results.hide();
          instance.view_all.hide();
          instance.no_results.hide(); // Show default categories if no search term is present.
           if (!(instance.input.val() && instance.input.val().trim())) {
            // If a previous ajax request has been sent, abort it.
            if (instance.last_request) {
              instance.last_request.abort();
            }
             instance.last_request = null;
            instance.default.show();
            return;
          } // Show loading animation.
            instance.default.hide();
          instance.spinner.show(); // Prepare query args.
           var params = $.param({
            action: 'mylisting_quick_search',
            security: CASE27.ajax_nonce,
            s: instance.input.val().trim()
          }); // Retrieve search results.
           $.ajax({
            url: CASE27.mylisting_ajax_url,
            type: 'GET',
            dataType: 'json',
            data: params,
            beforeSend: function beforeSend(request) {
              if (instance.last_request) {
                instance.last_request.abort();
              }
               instance.last_request = request;
            },
            success: function success(response) {
              instance.spinner.hide();
               if (!response.content.trim().length) {
                return instance.no_results.show();
              }
               instance.results.html(response.content).show();
              instance.view_all.show();
            }
          });
        };
    });
});