As we do in the rest of the application. Note we cannot add a rule enforcing double quotes because CoffeeScript Lint does not have such rule.
26 lines
567 B
CoffeeScript
26 lines
567 B
CoffeeScript
App.Suggest =
|
|
|
|
initialize: ->
|
|
|
|
$("[data-js-suggest-result]").each ->
|
|
|
|
$this = $(this)
|
|
|
|
callback = ->
|
|
$.ajax
|
|
url: $this.data("js-url")
|
|
data: { search: $this.val() },
|
|
type: "GET",
|
|
dataType: "html"
|
|
success: (stHtml) ->
|
|
js_suggest_selector = $this.data("js-suggest")
|
|
$(js_suggest_selector).html(stHtml)
|
|
|
|
timer = null
|
|
|
|
$this.on "keyup", ->
|
|
window.clearTimeout(timer)
|
|
timer = window.setTimeout(callback, 1000)
|
|
|
|
$this.on "change", callback
|