Permalink
Browse files

added more checks to onebox input handling

  • Loading branch information...
1 parent db64668 commit 6384e04b479cb0a2494566184f5eabdf59582661 @mrreynolds mrreynolds committed Oct 11, 2012
Showing with 6 additions and 7 deletions.
  1. +6 −7 app/assets/javascripts/iqvoc/onebox.js
View
13 app/assets/javascripts/iqvoc/onebox.js
@@ -32,13 +32,12 @@ return function(selector, options) {
var resultList = $("<ul />").addClass("results").appendTo(container);
input.keyup(function() {
- var delay = 200;
- clearTimeout(delay);
- setTimeout(function() {
- if (input.val() && input.val() != initialValue) {
- getConcepts(input, resultList);
- }
- }, delay);
+ if (input.val().length == 0) {
+ resultList.empty();
+ }
+ else if (input.val().length > 0 && input.val() != initialValue) {
+ setTimeout(function() { getConcepts(input, resultList) }, 200);
@FND
FND Oct 12, 2012

so this just delays the response to each keypress, but it reduce the number of responses (by combining handlers) - so why use setTimeout at all?

+ }
});
};

0 comments on commit 6384e04

Please sign in to comment.