Sha256: d216e3582913548167b3300f309cf9d365095b60110d7a82a3753ad44ef8a61d
Contents?: true
Size: 1.58 KB
Versions: 21
Compression:
Stored size: 1.58 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, params: { "headers": { 'Authorization': 'Bearer ' + Spree.api_key } }, data: function(term, page) { var searchData = { q: { product_name_or_sku_cont: term }, token: Spree.api_key }; 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
21 entries across 21 versions & 1 rubygems