Skip to content

Instantly share code, notes, and snippets.

@shanemcd
Last active December 11, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanemcd/4524573 to your computer and use it in GitHub Desktop.
Save shanemcd/4524573 to your computer and use it in GitHub Desktop.
class Instruments2.Views.FilterQuestionSets extends Backbone.View
template: JST['folders/filter']
id: "filter-question-sets"
className: "clearfix"
events:
"keyup input[type=text]": "filter"
render: ->
@$el.html(@template())
filter: (e) ->
query = $(this.el).find("input").val()
if query == ""
$(".question-set-in-list").show()
#some ghetto caching
unless @question_sets
@question_sets = $(".question-set-in-list")
# Loop over the question sets and show / hide
@question_sets.each ->
name = $(this).find("a").html()
expression = new RegExp(query,"gi")
match = name.match(expression)
if match == null
$(this).hide()
else
$(this).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment