Sha256: 609fe1ae875f073c9f2d136e3cff9af8510b37d93d2fcda7a673411ea0f38cb6

Contents?: true

Size: 1.34 KB

Versions: 24

Compression:

Stored size: 1.34 KB

Contents

export default class {
  connect() {
    $('[data-autocomplete-tag="true"]').each(function(_i, el) {
      var $el = $(el);
      // By default tags input binds on page ready to [data-role=tagsinput],
      // however, that doesn't work with Turbolinks. So we init manually:
      $el.tagsinput();

      var tags = new Bloodhound({
        datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.name); },
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        limit: 100,
        prefetch: {
          url: $el.data('autocomplete-url'),
          ttl: 1,
          filter: function(list) {
            // Let the dom know that the response has been returned
            $el.attr('data-autocomplete-fetched', true);
            return $.map(list, function(tag) { return { name: tag }; });
          }
        }
      });

      tags.initialize();

      $el.tagsinput('input').typeahead({highlight: true, hint: false}, {
        name: 'tags',
        displayKey: 'name',
        source: tags.ttAdapter()
      }).bind('typeahead:selected', $.proxy(function (obj, datum) {
        $el.tagsinput('add', datum.name);
        $el.tagsinput('input').typeahead('val', '');
      })).bind('blur', function() {
        $el.tagsinput('add', $el.tagsinput('input').typeahead('val'));
        $el.tagsinput('input').typeahead('val', '');
      })
    })
  }
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.3.5 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.3.4 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.3.3 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.3.2 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.3.1 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.3.0 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.2.0 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.1.2 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.1.1 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.1.0 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.0.3 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.0.2 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.0.1 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-4.0.0 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-3.6.0.beta10 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-3.6.0.beta9 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-3.6.0.beta8 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-3.6.0.beta7 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js
blacklight-spotlight-3.6.0.beta6 app/javascript/spotlight/admin/exhibit_tag_autocomplete.js