Last active
December 22, 2015 10:48
-
-
Save Abban/6461050 to your computer and use it in GitHub Desktop.
Simple setTimeout bind for Backbone input fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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