discourse/app/assets/javascripts/discourse/views/discovery-topics.js.es6
2014-07-24 14:59:53 -04:00

47 lines
1.3 KiB
JavaScript

import UrlRefresh from 'discourse/mixins/url-refresh';
export default Discourse.View.extend(Discourse.LoadMore, UrlRefresh, {
eyelineSelector: '.topic-list-item',
actions: {
loadMore: function() {
var self = this;
Discourse.notifyTitle(0);
this.get('controller').loadMoreTopics().then(function (hasMoreResults) {
Em.run.schedule('afterRender', function() {
self.saveScrollPosition();
});
if (!hasMoreResults) {
self.get('eyeline').flushRest();
}
});
}
},
_readjustScrollPosition: function() {
var scrollTo = Discourse.Session.currentProp('topicListScrollPosition');
if (typeof scrollTo !== "undefined") {
Em.run.schedule('afterRender', function() {
$(window).scrollTop(scrollTo+1);
});
}
}.on('didInsertElement'),
_updateTitle: function() {
Discourse.notifyTitle(this.get('controller.topicTrackingState.incomingCount'));
}.observes('controller.topicTrackingState.incomingCount'),
// Remember where we were scrolled to
saveScrollPosition: function() {
Discourse.Session.current().set('topicListScrollPosition', $(window).scrollTop());
},
// When the topic list is scrolled
scrolled: function() {
this._super();
this.saveScrollPosition();
}
});