Skip to content
Browse files

fix #1 and clean things up a bit

  • Loading branch information...
1 parent 970a9b6 commit 9d1a49a956db67b0f347491a4c6e42ade9899285 @rmurphey committed Apr 13, 2012
Showing with 24 additions and 16 deletions.
  1. +7 −0 app/components/results.js
  2. +1 −1 app/components/searchForm.js
  3. +10 −10 app/controllers/search.js
  4. +2 −3 app/data/search.js
  5. +4 −2 app/models/app.js
View
7 app/components/results.js
@@ -23,6 +23,13 @@ define([
this.itemTpl = _.template(itemTpl);
},
+ reset : function() {
+ this._filter(
+ { currentTarget : this.query('.js-all-filter') },
+ ''
+ );
+ },
+
_filter : function(evt, type) {
$(evt.currentTarget).addClass('active').siblings().removeClass('active');
if (type) {
View
2 app/components/searchForm.js
@@ -10,7 +10,7 @@ define([ 'app/components/base', 'text!app/templates/searchForm.html' ], function
e.preventDefault();
var term = $.trim(this.query('.js-input').val());
if (!term) { return; }
- this.trigger('search', term);
+ this.currentSearch.set('term', term);
}
});
});
View
20 app/controllers/search.js
@@ -1,32 +1,32 @@
define([
'models/app',
- 'data/search',
'components/results',
'components/searchForm',
'components/recentSearches'
-], function(app, SearchData, ResultsComponent, SearchFormComponent, RecentSearchesComponent) {
+], function(app, ResultsComponent, SearchFormComponent, RecentSearchesComponent) {
return function(term) {
var mainbar = $('#mainbar').empty(),
sidebar = $('#sidebar').empty(),
- sf = new SearchFormComponent().render().placeAt(mainbar),
+ sf = new SearchFormComponent({
+ currentSearch : app.currentSearch
+ }).render().placeAt(mainbar),
results = new ResultsComponent({
- searchData : SearchData
+ searchData : app.searchData
}).render().placeAt(mainbar),
recent = new RecentSearchesComponent({
searches : app.searches,
currentSearch : app.currentSearch
}).render().placeAt(sidebar);
- sf.on('search', function(term) {
- window.Router.navigate('/search/' + term, true);
- });
-
app.currentSearch.on('change', function(s) {
- SearchData.term = s.get('term');
- SearchData.fetch();
+ var term = s.get('term');
+ window.Router.navigate('/search/' + term, true);
+ app.searchData.term = s.get('term');
+ app.searchData.fetch();
+ results.reset();
});
update(term);
View
5 app/data/search.js
@@ -1,10 +1,9 @@
define([
'use!backbone'
], function(B) {
- var SearchResults = B.Collection.extend({
+ var SearchData = B.Collection.extend({
fetch : function() {
var fetch = _.bind(B.Collection.prototype.fetch, this);
-
fetch().then(_.bind(this.trigger, this, 'change'));
},
@@ -13,5 +12,5 @@ define([
}
});
- return new SearchResults();
+ return SearchData;
});
View
6 app/models/app.js
@@ -1,6 +1,7 @@
define([
- 'use!backbone'
-], function(B) {
+ 'use!backbone',
+ 'data/search'
+], function(B, SearchData) {
var Search = B.Model.extend({
idAttribute : 'term'
});
@@ -20,6 +21,7 @@ define([
return {
searches : searches,
+ searchData : new SearchData(),
currentSearch : new Backbone.Model({ term : null })
};
});

0 comments on commit 9d1a49a

Please sign in to comment.
Something went wrong with that request. Please try again.