2014-12-20 14:26:46 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.View.extend({
|
2015-02-10 15:35:40 +08:00
|
|
|
didInsertElement: function() {
|
|
|
|
this.updateTitle();
|
|
|
|
var scrollTop = this.get('controller.scrollTop');
|
|
|
|
$(window).scrollTop(scrollTop);
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
var lastDiscussion = this.get('controller.lastDiscussion');
|
|
|
|
if (lastDiscussion) {
|
|
|
|
var $discussion = $('.index-area .discussion-summary[data-id='+lastDiscussion.get('id')+']');
|
|
|
|
if ($discussion.length) {
|
|
|
|
var indexTop = $('#header').outerHeight();
|
|
|
|
var discussionTop = $discussion.offset().top;
|
|
|
|
if (discussionTop < scrollTop + indexTop || discussionTop + $discussion.outerHeight() > scrollTop + $(window).height()) {
|
|
|
|
$(window).scrollTop(discussionTop - indexTop);
|
2015-02-06 09:52:08 +08:00
|
|
|
}
|
2015-02-10 15:35:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-01-16 14:56:10 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
willDestroyElement: function() {
|
|
|
|
this.set('controller.scrollTop', $(window).scrollTop());
|
|
|
|
},
|
2014-12-20 14:26:46 +08:00
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
updateTitle: Ember.observer('controller.searchQuery', function() {
|
|
|
|
var q = this.get('controller.searchQuery');
|
|
|
|
this.get('controller.controllers.application').set('pageTitle', q ? '"'+q+'"' : '');
|
|
|
|
})
|
2014-12-20 14:26:46 +08:00
|
|
|
});
|