Skip to content

Commit

Permalink
fix #1 and clean things up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
rmurphey committed Apr 13, 2012
1 parent 970a9b6 commit 9d1a49a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions app/components/results.js
Expand Up @@ -23,6 +23,13 @@ define([
this.itemTpl = _.template(itemTpl); this.itemTpl = _.template(itemTpl);
}, },


reset : function() {
this._filter(
{ currentTarget : this.query('.js-all-filter') },
''
);
},

_filter : function(evt, type) { _filter : function(evt, type) {
$(evt.currentTarget).addClass('active').siblings().removeClass('active'); $(evt.currentTarget).addClass('active').siblings().removeClass('active');
if (type) { if (type) {
Expand Down
2 changes: 1 addition & 1 deletion app/components/searchForm.js
Expand Up @@ -10,7 +10,7 @@ define([ 'app/components/base', 'text!app/templates/searchForm.html' ], function
e.preventDefault(); e.preventDefault();
var term = $.trim(this.query('.js-input').val()); var term = $.trim(this.query('.js-input').val());
if (!term) { return; } if (!term) { return; }
this.trigger('search', term); this.currentSearch.set('term', term);
} }
}); });
}); });
20 changes: 10 additions & 10 deletions app/controllers/search.js
@@ -1,32 +1,32 @@
define([ define([
'models/app', 'models/app',
'data/search',
'components/results', 'components/results',
'components/searchForm', 'components/searchForm',
'components/recentSearches' 'components/recentSearches'
], function(app, SearchData, ResultsComponent, SearchFormComponent, RecentSearchesComponent) { ], function(app, ResultsComponent, SearchFormComponent, RecentSearchesComponent) {
return function(term) { return function(term) {
var mainbar = $('#mainbar').empty(), var mainbar = $('#mainbar').empty(),
sidebar = $('#sidebar').empty(), sidebar = $('#sidebar').empty(),


sf = new SearchFormComponent().render().placeAt(mainbar), sf = new SearchFormComponent({
currentSearch : app.currentSearch
}).render().placeAt(mainbar),


results = new ResultsComponent({ results = new ResultsComponent({
searchData : SearchData searchData : app.searchData
}).render().placeAt(mainbar), }).render().placeAt(mainbar),


recent = new RecentSearchesComponent({ recent = new RecentSearchesComponent({
searches : app.searches, searches : app.searches,
currentSearch : app.currentSearch currentSearch : app.currentSearch
}).render().placeAt(sidebar); }).render().placeAt(sidebar);


sf.on('search', function(term) {
window.Router.navigate('/search/' + term, true);
});

app.currentSearch.on('change', function(s) { app.currentSearch.on('change', function(s) {
SearchData.term = s.get('term'); var term = s.get('term');
SearchData.fetch(); window.Router.navigate('/search/' + term, true);
app.searchData.term = s.get('term');
app.searchData.fetch();
results.reset();
}); });


update(term); update(term);
Expand Down
5 changes: 2 additions & 3 deletions app/data/search.js
@@ -1,10 +1,9 @@
define([ define([
'use!backbone' 'use!backbone'
], function(B) { ], function(B) {
var SearchResults = B.Collection.extend({ var SearchData = B.Collection.extend({
fetch : function() { fetch : function() {
var fetch = _.bind(B.Collection.prototype.fetch, this); var fetch = _.bind(B.Collection.prototype.fetch, this);

fetch().then(_.bind(this.trigger, this, 'change')); fetch().then(_.bind(this.trigger, this, 'change'));
}, },


Expand All @@ -13,5 +12,5 @@ define([
} }
}); });


return new SearchResults(); return SearchData;
}); });
6 changes: 4 additions & 2 deletions app/models/app.js
@@ -1,6 +1,7 @@
define([ define([
'use!backbone' 'use!backbone',
], function(B) { 'data/search'
], function(B, SearchData) {
var Search = B.Model.extend({ var Search = B.Model.extend({
idAttribute : 'term' idAttribute : 'term'
}); });
Expand All @@ -20,6 +21,7 @@ define([


return { return {
searches : searches, searches : searches,
searchData : new SearchData(),
currentSearch : new Backbone.Model({ term : null }) currentSearch : new Backbone.Model({ term : null })
}; };
}); });

0 comments on commit 9d1a49a

Please sign in to comment.