Permalink
Browse files

Abort waiting search requests.

  • Loading branch information...
1 parent 1cb1723 commit 1736ee3ca41334389c118dff2dcf9035d4aab600 @mikeal committed Feb 22, 2011
Showing with 9 additions and 3 deletions.
  1. +4 −0 main.js
  2. +4 −2 static/index.html
  3. +1 −1 static/site.js
View
@@ -55,6 +55,10 @@ exports.createServer = function (folders, cb) {
} else {
var foundfiles = [];
body.search = body.search.toLowerCase();
+ if (req.connection.writable === false && req.connection.readable === false) {
+ console.log('aborted')
+ return;
+ }
monitors.forEach(function (monitor) {
for (f in monitor.files) {
if (f.toLowerCase().slice(f.lastIndexOf('/')).indexOf(body.search) !== -1) {
View
@@ -16,12 +16,14 @@
<input type="text" id="search"></input>
<script>
var current = '';
+ var prev;
$("input#search").keyup(function () {
+ if (prev) prev.abort();
var search = $(this).val();
if (search === current) return;
if (search === '') return;
current = search;
- request({url:'/', type:'POST', data:{search:search}}, function (e, results) {
+ prev = request({url:'/', type:'POST', data:{search:search}}, function (e, results) {
if (current !== search) return;
$('div#results').html('');
results.forEach(function (r) {
@@ -32,7 +34,7 @@
var filename = $(this).parent().text();
filename = filename.slice(0, filename.length - 4);
request({url:'/open', type:'POST', data:{filename:filename}}, function (e, resp) {
- if (e) console.log(e);
+ if (e) console.log(e);
})
})
})
View
@@ -12,7 +12,7 @@ var request = function (options, callback) {
if (!options.dataType) options.processData = false;
if (!options.dataType) options.contentType = 'application/json';
if (!options.dataType) options.dataType = 'json';
- $.ajax(options)
+ return $.ajax(options)
}
$.expr[":"].exactly = function(obj, index, meta, stack){

0 comments on commit 1736ee3

Please sign in to comment.