Skip to content

Instantly share code, notes, and snippets.

@qizhihere
Last active August 29, 2015 14:24
Show Gist options
  • Save qizhihere/c8cbfa130051e1b5d163 to your computer and use it in GitHub Desktop.
Save qizhihere/c8cbfa130051e1b5d163 to your computer and use it in GitHub Desktop.
show delay prompt for search bar
function delayPrompt(event, elem, cb) {
var value = elem.prop('value');
this.lastKeyUp = event.timeStamp;
setTimeout(function() {
/* check input interval */
if (this.lastKeyUp - event.timeStamp !== 0) {
return;
}
if (value && value.trim() && value != this.lastVal) {
/* send search request and do prompt */
cb(value);
this.lastVal = value;
}
}, 400);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment