Last active
August 29, 2015 14:24
-
-
Save qizhihere/c8cbfa130051e1b5d163 to your computer and use it in GitHub Desktop.
show delay prompt for search bar
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
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