Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 577fcc2

Browse files
committed
adjusting things related to dom caching and searching on discover
1 parent 0a7d894 commit 577fcc2

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

js/router.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ module.exports = Backbone.Router.extend({
7676
for (var key in this.viewCache) {
7777
cached = this.viewCache[key];
7878
if (Date.now() - cached.cachedAt >= cached.view.cacheExpires) {
79-
delete this.viewCache[key].view.__cachedScrollPos;
8079
delete this.viewCache[key];
8180
}
8281
}

js/views/homeVw.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = pageVw.extend({
2323
'click .js-vendorsTab': function(){this.setState("vendors");},
2424
'click .js-homeCreateStore': 'createStore',
2525
'click .js-homeCreateListing': 'createListing',
26-
'click .js-homeSearchItemsClear': 'searchItemsClear',
26+
'click .js-homeSearchItemsClear': 'onSearchItemsClear',
2727
'keyup .js-homeSearchItems': 'searchItemsKeyup',
2828
'focus .js-homeSearchItems': 'searchItemsFocus',
2929
'blur .js-homeSearchItems': 'searchItemsBlur',
@@ -79,14 +79,26 @@ module.exports = pageVw.extend({
7979

8080
onCacheReattached: function(e) {
8181
var splitRoute = e.route.split('/'),
82-
state = splitRoute[1];
82+
state = splitRoute[1],
83+
searchTerm = splitRoute[2];
8384

8485
if (e.view !== this) return;
8586
state = state || this.state;
8687

87-
if (this.cachedScrollPositions[state]) this.obContainer[0].scrollTop = this.cachedScrollPositions[state];
88+
if (this.cachedScrollPositions[state])
89+
this.obContainer[0].scrollTop = this.cachedScrollPositions[state];
8890
this.setState(state);
89-
splitRoute[2] && splitRoute[2] !== this.searchItemsText && this.searchItems(splitRoute[2]);
91+
92+
if (!searchTerm && this.searchItemsText) {
93+
this.searchItemsClear(state);
94+
if (state === 'products') this.obContainer[0].scrollTop = 0;
95+
}
96+
97+
if (searchTerm && searchTerm !== this.searchItemsText) {
98+
this.searchItems(searchTerm);
99+
this.obContainer[0].scrollTop = 0;
100+
}
101+
90102
this.obContainer.on('scroll', this.scrollHandler);
91103
},
92104

@@ -321,6 +333,8 @@ module.exports = pageVw.extend({
321333
},
322334

323335
setState: function(state, searchItemsText){
336+
var searchTextFrag;
337+
324338
if (!state){
325339
state = "products";
326340
}
@@ -330,15 +344,11 @@ module.exports = pageVw.extend({
330344
this.$el.find('.js-' + state + 'Tab').addClass('active');
331345
this.$el.find('.js-' + state + 'Search').removeClass('hide');
332346

333-
if (searchItemsText){
334-
this.searchItemsText = searchItemsText;
347+
if (searchItemsText) this.searchItemsText = searchItemsText;
348+
searchTextFrag = this.searchItemsText ? `/${this.searchItemsText.replace(/ /g, "")}` : '';
335349

336-
//add action to history
337-
Backbone.history.navigate("#home/" + state + "/" + searchItemsText.replace(/ /g, ""), { replace: true });
338-
} else {
339-
//add action to history
340-
Backbone.history.navigate("#home/" + state, { replace: true });
341-
}
350+
//add action to history
351+
Backbone.history.navigate("#home/" + state + searchTextFrag, { replace: true });
342352

343353
this.state = state;
344354
},
@@ -484,8 +494,13 @@ module.exports = pageVw.extend({
484494
}
485495
},
486496

487-
searchItemsClear: function(){
488-
this.setState("products");
497+
onSearchItemsClear: function(e) {
498+
this.searchItemsClear();
499+
},
500+
501+
searchItemsClear: function(state){
502+
this.searchItemsText = '';
503+
this.setState(state || 'products');
489504
this.loadItems();
490505

491506
//clear address bar

0 commit comments

Comments
 (0)