Permalink
Browse files

Merge pull request #159 from mmozuras/search-results

Improve erratic search results
  • Loading branch information...
bry4n committed Jul 5, 2012
2 parents 53bade4 + 5299450 commit 28ce239160f5a6572539fec8067910480cdf3078
Showing with 20 additions and 9 deletions.
  1. +20 −9 app/assets/javascripts/site.js
@@ -97,7 +97,7 @@ var Search = {
observeTextEntry: function() {
$('form#search input').keyup(function(e) {
- Search.runSearch(e.which);
+ Search.runSearch();
});
$('form#search input').keydown(function(e) {
@@ -131,17 +131,28 @@ var Search = {
});
},
- runSearch: function(lastLetter) {
- Search.searching = true;
+ runSearch: function() {
var term = $('#search-text').val();
if(term.length < 2) { return false };
- if(term != Search.currentSearch) {
- Search.currentSearch = term;
- $.get("/search", {search: term}, function(results) {
- $("#search-results").html(results);
- }, 'html');
- };
+ if(!Search.searching) {
+ Search.searching = true;
+
+ if(term != Search.currentSearch) {
+ Search.currentSearch = term;
+ $.get("/search", {search: term}, function(results) {
+ $("#search-results").html(results);
+ Search.searching = false;
+ }, 'html');
+ };
+ }
+ else {
+ clearTimeout(Search.timeout);
+ Search.timeout = setTimeout(function() {
+ Search.searching = false;
+ Search.runSearch();
+ }, 300);
+ }
},
selectResultOption: function() {

0 comments on commit 28ce239

Please sign in to comment.