https://github.com/amiel/typingintent
Fire an event after the user has finished typing
https://github.com/amiel/typingintent
Last synced: about 1 year ago
JSON representation
Fire an event after the user has finished typing
- Host: GitHub
- URL: https://github.com/amiel/typingintent
- Owner: amiel
- Created: 2010-10-28T16:10:05.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2015-12-07T17:29:35.000Z (over 10 years ago)
- Last Synced: 2024-10-03T12:33:08.181Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://github.com/amiel/typingIntent
- Size: 2.93 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
Awesome Lists containing this project
README
== Typing Intent jQuery plugin
The typing intent plugin calls a callback after a user stops typing.
It does this by handling keyup and setting a timeout that gets reset on each keyup.
== Examples
$("#q").typingIntent(function(e) {
console.log("User finished typing (for the moment) in", this);
console.log("The original keyup event:", e);
});
=== Ajax examples
Basic search
(function() {
var ajax_request;
$("#q").typingIntent(function() {
ajax_request = $.get("/search.json", { q: this.val() }, function() {
// handle search results
});
}, function() {
// this second function is called immediately on keyup
// we use it to cancel the ajax request if it is still running
// immediately, when the user starts typing again
if (ajax_request) ajax_request.abort();
// this would also be the place to handle key up and down events to navigate through the search results
});
})();
Background form verification
(function() {
var ajax_request;
$("#user_zipcode").typingIntent(function() {
ajax_request = $.get("/users/check_zipcode.json", { zipcode: this.val() }, function(zipcode_data) {
// show zipcode information
});
}, function() {
if (ajax_request) ajax_request.abort();
if (! (/^\d{5}(-\d{4})?/).test(this.val())) {
// returning false will prevent the first function from being run
// we don't need to send the ajax request unless there is a valid zipcode to check
return false;
}
});
})();