Sha256: e4af4206b359b91cffdfae01572f406b121215fcb699272a2377f8627726ade9
Contents?: true
Size: 1.26 KB
Versions: 3
Compression:
Stored size: 1.26 KB
Contents
IQVOC.autocomplete = (function($) { // `field` is the input field to be augmented // `source` is a function expected to calculate the results - it is invoked with // the respective query string and a callback and expected to invoke that // callback with an array of `{ value, label }` objects // `options` is an object with optional members `displayKey`, `noResultsMsg` and // `onSelect` // TODO: built-in support for loading indicator? function augment(field, source, options) { field = field.jquery ? field : $(field); options = options || {}; options.noResultsMsg = options.noResultsMsg || "no results"; options.displayKey = options.displayKey || "value"; field.typeahead({ minLength: 3, highlight: true }, { source: source, displayKey: options.displayKey, templates: { empty: function() { var el = $("<p />").text(options.noResultsMsg); return $("<div />").append(el).html(); }, suggestion: function(item) { var el = $("<p />").text(item.label); return $("<div />").append(el).html(); } } }).bind("typeahead:selected", function(ev, selected, name) { if(options.onSelect) { options.onSelect.call(this, ev, selected); // TODO: document } }); } return augment; }(jQuery));
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
iqvoc-4.9.0 | app/assets/javascripts/iqvoc/autocomplete.js |
iqvoc-4.8.2 | app/assets/javascripts/iqvoc/autocomplete.js |
iqvoc-4.8.1 | app/assets/javascripts/iqvoc/autocomplete.js |