summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/category_autocomplete.js.coffee
blob: 490032dc7820b1952b4dfb8a3cec5a3d1dff8e11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$.widget( "custom.catcomplete",  $.ui.autocomplete,
  _create: ->
    @_super();
    @widget().menu("option", "items", "> :not(.ui-autocomplete-category)")

  _renderMenu: (ul, items) ->
    currentCategory = ''
    $.each items, (index, item) =>
      if item.category isnt currentCategory
        ul.append("<li class='ui-autocomplete-category'>#{item.category}</li>")
        currentCategory = item.category

      li = @_renderItemData(ul, item)

      if item.category?
        li.attr('aria-label', item.category + " : " + item.label)
  )