Skip to content

Instantly share code, notes, and snippets.

@Abban
Last active December 22, 2015 10:48
Show Gist options
  • Save Abban/6461050 to your computer and use it in GitHub Desktop.
Save Abban/6461050 to your computer and use it in GitHub Desktop.
Simple setTimeout bind for Backbone input fields
window.SearchView = Backbone.View.extend(
{
typingInterval: 1000,
el: '#search',
events:{
'keyup' : 'typed'
},
initialize: function()
{
_.bindAll(this, 'typed', 'search');
},
/**
* When a keyup event fires create a timer that calls the search
*
* @param jQuery Event event
* @return void
*/
typed: function(event)
{
clearTimeout(this.timer);
this.timer = setTimeout(this.search.bind(this, event), this.typingInterval);
},
/**
* Performs the search
*
* @param jQuery Event event
* @return void
*/
search: function(event)
{
window.App.searchTerm = event.target.value;
window.App.refreshEntries();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment