FIX: Scroll position is tracked on search page

This commit is contained in:
Bianca Nenciu 2017-08-13 13:24:29 +01:00 committed by Joffrey JAFFEUX
parent 80daa7006c
commit 7213e02dee
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import Scrolling from 'discourse/mixins/scrolling';
export default Ember.Component.extend(Scrolling, {
didReceiveAttrs() {
this._super();
this.set('trackerName', `scroll-tracker-${this.get('name')}`);
},
didInsertElement() {
this._super();
this.bindScrolling({ name: this.get('name') });
},
didRender() {
this._super();
const data = this.session.get(this.get('trackerName'));
if (data && data.position >= 0 && data.tag === this.get('tag')) {
Ember.run.next(() => $(window).scrollTop(data.position + 1));
}
},
willDestroyElement() {
this._super();
this.unbindScrolling(this.get('name'));
},
scrolled() {
this._super();
this.session.set(this.get('trackerName'), {
position: $(window).scrollTop(),
tag: this.get('tag'),
});
},
});

View File

@ -1,4 +1,5 @@
{{#d-section pageClass="search" class="search-container"}}
{{scroll-tracker name="full-page-search" tag=searchTerm}}
<div class="search row clearfix">
{{search-text-field value=searchTerm class="full-page-search input-xxlarge search no-blur" action="search" hasAutofocus=hasAutofocus}}
{{d-button action="search" icon="search" class="btn-primary" disabled=searching}}