FIX: Small timeline docking tweaks

This commit is contained in:
Robin Ward 2016-05-26 13:58:31 -04:00
parent 6da097d91c
commit f8e6d05b8d
No known key found for this signature in database
GPG Key ID: 0E091E2B4ED1B83D
2 changed files with 19 additions and 8 deletions

View File

@ -1,5 +1,6 @@
import MountWidget from 'discourse/components/mount-widget';
import Docking from 'discourse/mixins/docking';
import { observes } from 'ember-addons/ember-computed-decorators';
export default MountWidget.extend(Docking, {
widget: 'topic-timeline-container',
@ -12,6 +13,11 @@ export default MountWidget.extend(Docking, {
dockAt: this.dockAt };
},
@observes('topic.highest_post_number')
newPostAdded() {
this.queueRerender(() => this.queueDockCheck());
},
dockCheck(info) {
if (this.get('loading')) { return; }
@ -31,6 +37,7 @@ export default MountWidget.extend(Docking, {
this.dockAt = 0;
} else if (pos > topicBottom) {
this.dockAt = topicBottom - timelineHeight - parentTop;
if (this.dockAt < 0) { this.dockAt = 0; }
} else {
this.dockAt = null;
}

View File

@ -3,23 +3,27 @@ const helper = {
};
export default Ember.Mixin.create({
_dockHandler: null,
queueDockCheck: null,
init() {
this._super();
this.queueDockCheck = () => {
Ember.run.debounce(this, this.dockCheck, helper, 20);
};
},
didInsertElement() {
this._super();
// Check the dock after the current run loop since reading sizes is slow
this._dockHandler = () => Ember.run.next(() => this.dockCheck(helper));
$(window).bind('scroll.discourse-dock', this._dockHandler);
$(document).bind('touchmove.discourse-dock', this._dockHandler);
$(window).bind('scroll.discourse-dock', this.queueDockCheck);
$(document).bind('touchmove.discourse-dock', this.queueDockCheck);
this.dockCheck(helper);
},
willDestroyElement() {
this._super();
$(window).unbind('scroll.discourse-dock', this._dockHandler);
$(document).unbind('touchmove.discourse-dock', this._dockHandler);
$(window).unbind('scroll.discourse-dock', this.queueDockCheck);
$(document).unbind('touchmove.discourse-dock', this.queueDockCheck);
}
});