decko-commons/decko

View on GitHub
mod/search/assets/script/search_box.js.coffee

Summary

Maintainability
Test Coverage

$(window).ready ->
  el = $('._search-box')
  box = new decko.searchBox el
  el.data "searchBox", box
  box.init()

class decko.searchBox
  constructor: (el) ->
    @box = el
    @sourcepath = @box.data "completepath"
    @originalpath = @sourcepath
    @config =
      source: @sourcepath
      select: @select

  init: -> @box.autocomplete @config, html: true

  select: (_event, ui) ->
    url = ui.item.url
    window.location = url if url

  form: -> @box.closest "form"
  keyword: -> @keywordBox().val()
  keywordBox: -> @form().find "#query_keyword"