Sha256: b8d116de361d4d16ae070708661d70ac58bca2658e14438dcc78cc351477fefb

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

$ ->

  input = null

  $('.auto-complete input').blur ->
    unless input != null and input[0] == $(this)[0]
      parent = $(this).parent('.auto-complete')
      parent.children('.select-list').hide()
      
  $('.auto-complete input').focus ->
    generate_list(this)

  $('.auto-complete').on('click', 'li.select-li', ->
    $(this).parents('.auto-complete').children('input').val($(this).html())
    $(this).parents('.select-list').hide()
    )

  $('.select-list').hover(
    ->
      input = $(this).parents('.auto-complete').children('input')
    ->
      input = null
  )

  $('.auto-complete input').keyup ->
    generate_list(this)


  generate_list = (obj) ->
    val = $(obj).val()
    parent = $(obj).parent('.auto-complete')
    list = parent.children('.select-list') 
    ul = list.find("ul")
    if ( val.length != 0 )
      ar = parent.data("list")
      if ( ar.length > 0 )
        ul.html("")
        n = 0
        $.each(ar, ->
           if (this.toLowerCase().indexOf(val.toLowerCase()) >= 0)
            n++
            ul.append("<li class='select-li'>"+this+"</li>")
          )
          if n > 0
            list.show()
          else
            list.hide()
      else
        list.hide()
    else
      list.hide()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_auto_complete-0.0.1 vendor/assets/javascripts/simple_auto_complete/index.js.coffee