Skip to content

Commit

Permalink
A better way of doing the search box showing and hiding.
Browse files Browse the repository at this point in the history
  • Loading branch information
apendleton committed Apr 12, 2012
1 parent 270a44d commit b49d526
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions sparerib/sparerib_public/static/js/sparerib.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,19 @@ var SearchView = Backbone.View.extend({
className: 'search-view',

events: {
'submit form': 'search',
'click ul.results a': 'showTopSearch'
'submit form': 'search'
},

template: _.template($('#search-tpl').html()),
render: function() {
$(this.el).html(this.template(this));

// if we're in the main area, hide the top area
if (this.id == 'main-search-form') {
$('#top-search').hide().find('input[type=text]').val('');
}

return this;
},

search: function(evt) {
evt.preventDefault();
app.navigate('/search/' + encodeURIComponent($(this.el).find('.search-query').val()), {trigger: true});
return false;
},

showTopSearch: function(evt) {
$('#top-search').show()
}
})

Expand Down Expand Up @@ -273,6 +262,15 @@ var AppRouter = Backbone.Router.extend({
// load the upper search box at the beginning
var topSearchView = new SearchView({'id': 'top-search-form'});
$('#top-search').html(topSearchView.render().el);

// on all navigation, check to show/hide the search box
this.on('all', function () {
if ($('#main .search-view').length != 0) {
$('#top-search').hide();
} else {
$('#top-search').show().find('input[type=text]').val('');
}
});
},

searchLanding: function() {
Expand Down Expand Up @@ -329,6 +327,7 @@ var AppRouter = Backbone.Router.extend({

var app = new AppRouter();
window.app = app;
console.log(app);

Backbone.history.start({pushState: true});

Expand Down

0 comments on commit b49d526

Please sign in to comment.