define ["./dom", "./ajax", "underscore", "jquery", "./utils", "./typeahead"],
(dom, ajax, _, $, {extendURL}) ->
init = (spec) ->
$field = $ document.getElementById spec.id
engine = new Bloodhound
datumTokenizer: Bloodhound.tokenizers.whitespace
queryTokenizer: Bloodhound.tokenizers.whitespace
limit: spec.limit
remote:
url: spec.url
replace: (uri, query) -> extendURL uri, "t:input": query
filter: (response) -> response.matches
engine.initialize()
dataset =
name: spec.id
displayKey: _.identity
source: engine.ttAdapter()
$field.typeahead
minLength: spec.minChars
dataset