Sha256: 389f4ad490113e212d1c8fb2988b4562c0ccf18cc520f38914a78768adbf23c0

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

ready = ->
  $('.autocomplete').keyup (elm) ->
    ajax_url = $(@).data('autocomplete-path')
    return unless ajax_url

    $.ajax
      url: ajax_url
      type: "GET"
      dataType: "json"
      data: str: $(elm.target).val()
      success: (response) ->
        autocomplete_popup(response, elm.target)

autocomplete_popup = (autocomplete_list, object) ->
  popup_id = 'autocomplete_popup'

  # Create or use existing Popup Window
  if $('#' + popup_id).length > 0
    popup_container = $('#' + popup_id)
  else
    popup_container = $("<div id='#{popup_id}'></div>")
    $(object).after(popup_container)

  # Show lists
  html_list = $('<ul/>')
  $.map autocomplete_list, (item) ->
    li = $('<li/>')
      .addClass('ui-menu-item')
      .attr('role', 'menuitem')
      .appendTo(html_list)

    a = $('<a/>')
      .addClass('ui-all')
      .text(item)
      .appendTo(li)

    li.click ->
      $(object).val(item)

      # Destroy popup after select tag
      popup_container.remove()

  popup_container.html(html_list)

$(document).ready(ready)
$(document).on('page:load', ready)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
my_forum-0.0.1.beta2 app/assets/javascripts/my_forum/my_forum.js.coffee