Skip to content

A platform for community discussion. Free, open, simple.

PERF: fast docking of timeline so it does not overlap

Samf4418ae88482
diff --git a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 b/app/assets/javascripts/discourse/components/topic-timeline.js.es6
index c693fd9c942..b89f8041947 100644
--- a/app/assets/javascripts/discourse/components/topic-timeline.js.es6
+++ b/app/assets/javascripts/discourse/components/topic-timeline.js.es6
@@ -47,6 +47,17 @@ export default MountWidget.extend(Docking, {
this.queueRerender();
},
+ fastDockCheck(){
+ // we need to dock super fast here, avoid any slow methods
+ // this is not debounced
+ const offset = window.pageYOffset;
+
+ if (offset && this.fastDockAt && offset > this.fastDockAt) {
+ this.fastDockAt = null;
+ $('.timeline-container').addClass('timeline-docked timeline-docked-bottom');
+ }
+ },
+
dockCheck(info) {
const mainOffset = $('#main').offset();
const offsetTop = mainOffset ? mainOffset.top : 0;
@@ -62,13 +73,14 @@ export default MountWidget.extend(Docking, {
this.dockBottom = false;
if (posTop < topicTop) {
- this.dockAt = topicTop;
+ this.dockAt = parseInt(topicTop, 10);
} else if (pos > topicBottom + footerHeight) {
- this.dockAt = (topicBottom - timelineHeight) + footerHeight;
+ this.dockAt = parseInt((topicBottom - timelineHeight) + footerHeight, 10);
this.dockBottom = true;
if (this.dockAt < 0) { this.dockAt = 0; }
} else {
this.dockAt = null;
+ this.fastDockAt = parseInt(topicBottom - timelineHeight + footerHeight - offsetTop, 10);
}
if (this.dockAt !== prev) {
diff --git a/app/assets/javascripts/discourse/mixins/docking.js.es6 b/app/assets/javascripts/discourse/mixins/docking.js.es6
index 4b2505b1518..2a0fc36fa05 100644
--- a/app/assets/javascripts/discourse/mixins/docking.js.es6
+++ b/app/assets/javascripts/discourse/mixins/docking.js.es6
@@ -12,6 +12,12 @@ export default Ember.Mixin.create({
init() {
this._super();
this.queueDockCheck = () => {
+
+ // we want to do a very fast non-debounced check first
+ if (this.fastDockCheck) {
+ this.fastDockCheck();
+ }
+
Ember.run.debounce(this, this.safeDockCheck, 5);
};
},