Skip to content

Instantly share code, notes, and snippets.

@SergXIIIth
Created March 9, 2011 15:32
Show Gist options
  • Save SergXIIIth/862396 to your computer and use it in GitHub Desktop.
Save SergXIIIth/862396 to your computer and use it in GitHub Desktop.
live search
search = () ->
textboxs = $(".live_filter").add $("[data-live-cnt]")
textboxs.keyup ->
textbox = $(this)
cnt = textbox.attr("data-live-cnt")
cnt = "" unless cnt?
pattern = $.trim textbox.val()
items = $ ".live_item#{cnt}"
if pattern.length < 1
items.show()
return
pattern = new RegExp pattern, "i"
items.each ->
text = $(".live_text#{cnt}", @).map(-> $(@).text()).get().join(" ")
if text.search(pattern) >= 0
$(@).show()
else
$(@).hide()
textboxs.keyup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment