Skip to content

Commit

Permalink
optimizing things
Browse files Browse the repository at this point in the history
  • Loading branch information
tristen committed May 9, 2012
1 parent d307175 commit e0b5192
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions _includes/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
url: 'search.json',
dataType: 'json',
success: function(r) {
data = _(r).chain()
.compact()
.map(function(r) {
r.words = (r.title.toLowerCase() + ' ' + (r.tags.toString()).toLowerCase()).match(/(\w+)/g);
return r;
})
.value();
_.delay(function () {tagList(tags)}, 10);
_.each(r, function(result){
$('#results').append(tExamples(result));
Expand Down Expand Up @@ -46,41 +53,20 @@
$('#tag-list').find('a').removeClass('active');
$(this).addClass('active');

var matches = find(tag.toLowerCase().match(/(\w+)/g));
_(matches).each(function(p) {
var filtered = find(tag.toLowerCase().match(/(\w+)/g));
_(filtered).each(function(p) {
$('#results').append(tExamples(p));
});
} else {
$(this).removeClass('active');
$.ajax({
url: 'search.json',
dataType: 'json',
success: function(r) {
_.each(r, function(result){
$('#results').append(tExamples(result));
});
}
});
_.each(data, function(result){
$('#results').append(tExamples(result));
});
}
}
}

var find = function(phrase) {
if (!data) return $.ajax({
url: 'search.json',
dataType: 'json',
success: function(r) {
data = _(r).chain()
.compact()
.map(function(r) {
r.words = (r.title.toLowerCase() + ' ' + (r.tags.toString()).toLowerCase()).match(/(\w+)/g);
return r;
})
.value();
find(phrase);
}
});

var matches = _(data).filter(function(p) {
return _(phrase).filter(function(a) {
return _(p.words).any(function(b) {
Expand All @@ -99,6 +85,9 @@

if (phrase.length >= 2) {
var matches = find(phrase.toLowerCase().match(/(\w+)/g));

$('#tag-list').find('a').removeClass('active');

_(matches).each(function(p) {
$('#results').append(tExamples(p));
});
Expand All @@ -125,7 +114,6 @@
var tSnippets = _.template($('#snippets').html());
var tToc = _.template($('#directory-listing').html());


$.getJSON(request + '?callback=?', function(resp) {

var f = {};
Expand Down

0 comments on commit e0b5192

Please sign in to comment.