diff --git a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 index a744515e4..2e7e5c096 100644 --- a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 @@ -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; } diff --git a/app/assets/javascripts/discourse/mixins/docking.js.es6 b/app/assets/javascripts/discourse/mixins/docking.js.es6 index e4f2d843c..ee024ed45 100644 --- a/app/assets/javascripts/discourse/mixins/docking.js.es6 +++ b/app/assets/javascripts/discourse/mixins/docking.js.es6 @@ -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); } });