Permalink
Browse files

fix some search bugs

  • Loading branch information...
schacon committed May 4, 2012
1 parent 5e5a1db commit 6a93c628e769c8148ec86b12bde3da219b7aa6f3
Showing with 21 additions and 14 deletions.
  1. +0 −3 TODO.txt
  2. +21 −10 app/assets/javascripts/site.js
  3. +0 −1 app/controllers/site_controller.rb
View
@@ -8,12 +8,9 @@ Initial Launch (3.0):
* Search improvements
- "git add"
- - backspacing
- - enter partial search
* Misc
- reindex command - drops index and re-does everything
- - generate all book languages
- regenerate all reference pages
- /git-fetch/1.7.3.2 looks wrong
- user-manual not present
@@ -71,6 +71,7 @@ var BrowserFallbacks = {
var Search = {
searching: false,
+ currentSearch: '',
selectedIndex: 0,
init: function() {
@@ -88,8 +89,11 @@ var Search = {
},
observeTextEntry: function() {
+ $('form#search input').keyup(function(e) {
+ Search.runSearch(e.which);
+ });
+
$('form#search input').keydown(function(e) {
- Search.searching = true;
if ($('#search-results').not(':visible') && e.which != 27) {
$('#search-results').fadeIn(0.2);
Search.highlight(Search.selectedIndex);
@@ -110,24 +114,31 @@ var Search = {
e.preventDefault();
Search.resultsNav("down");
break;
- default:
- // execute search with current text
- Search.runSearch(e.which);
- break;
};
});
},
runSearch: function(lastLetter) {
- var term = $('#search-text').val() + String.fromCharCode(lastLetter);
- $.get("/search", {search: term}, function(results) {
- $("#search-results").html(results);
- });
+ Search.searching = true;
+ var term = $('#search-text').val();
+ if(term.length < 3) { return false };
+
+ if(term != Search.currentSearch) {
+ Search.currentSearch = term;
+ $.get("/search", {search: term}, function(results) {
+ $("#search-results").html(results);
+ });
+ };
},
selectResultOption: function() {
var link = $('#search-results a')[Search.selectedIndex];
- window.location.href = $(link).attr('href');
+ var url = $(link).attr('href');
+ if(!link) {
+ var term = $('#search-text').val();
+ url = "/search/results?search=" + term;
+ }
+ window.location.href = url;
selectedIndex = 0;
},
@@ -1,4 +1,3 @@
-require 'pp'
class SiteController < ApplicationController
layout "layout"

0 comments on commit 6a93c62

Please sign in to comment.