Sha256: cc65bb33d8aeb26116f58d09804f9444388f8e1250c2cafa604f8d87c9682db0
Contents?: true
Size: 1.21 KB
Versions: 57
Compression:
Stored size: 1.21 KB
Contents
$.fn.tagAutocomplete = function () { 'use strict' function formatTag (tag) { return Select2.util.escapeMarkup(tag.name) } this.select2({ placeholder: Spree.translations.tags_placeholder, minimumInputLength: 1, tokenSeparators: [','], multiple: true, tags: true, initSelection: function (element, callback) { var data = $(element.val().split(',')).map(function () { return { name: this, id: this } }) callback(data) }, ajax: { url: Spree.routes.tags_api, datatype: 'json', cache: true, data: function (term) { return { q: term, token: Spree.api_key } }, results: function (data) { return { results: data.tags.map(function (tag) { return { name: tag.name, id: tag.name } }) } } }, createSearchChoice: function (term, data) { if ($(data).filter(function () { return this.name.localeCompare(term) === 0 }).length === 0) { return { id: term, name: term } } }, formatResult: formatTag, formatSelection: formatTag }) } $(document).ready(function () { $('.tag_picker').tagAutocomplete() })
Version data entries
57 entries across 57 versions & 1 rubygems