Sha256: 057f2e368b8c9f77a696ba876bfd375f6a75dd47b02d41f8684d4ece32759d9b

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

(function() {
  var variantTemplate = HandlebarsTemplates["variants/autocomplete"];

  var formatVariantResult = function(variant) {
    return variantTemplate({
      variant: variant
    });
  };

  $.fn.variantAutocomplete = function(searchOptions) {
    if (searchOptions == null) {
      searchOptions = {};
    }
    this.select2({
      placeholder: Spree.translations.variant_placeholder,
      minimumInputLength: 3,
      initSelection: function(element, callback) {
        Spree.ajax({
          url: Spree.routes.variants_api + "/" + element.val(),
          success: callback
        });
      },
      ajax: {
        url: Spree.routes.variants_api,
        datatype: "json",
        quietMillis: 500,
        data: function(term, page) {
          var searchData = {
            q: {
              product_name_or_sku_cont: term
            },
          };
          return _.extend(searchData, searchOptions);
        },

        results: function(data, page) {
          window.variants = data["variants"];
          return {
            results: data["variants"]
          };
        }
      },

      formatResult: formatVariantResult,
      formatSelection: function(variant, container, escapeMarkup) {
        if (variant.options_text) {
          return Select2.util.escapeMarkup(variant.name + " (" + variant.options_text + ")");
        } else {
          return Select2.util.escapeMarkup(variant.name);
        }
      }
    });
  };
})();

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
solidus_backend_devise_token_auth-2.8.0.alpha.14 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.13 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.12 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.11 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.10 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.9 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.8 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.7 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.6 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.5 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.4 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.3 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend_devise_token_auth-2.8.0.alpha.2 app/assets/javascripts/spree/backend/variant_autocomplete.js