From eccfa1317a11c2abf42a2eb83292253a7e161dd1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 3 Jun 2016 17:57:52 -0400 Subject: [PATCH] FIX: Safer offset checking --- .../javascripts/discourse/components/topic-timeline.js.es6 | 4 +++- app/assets/javascripts/discourse/mixins/docking.js.es6 | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 index 5574e2e06f3..d3b2f648a47 100644 --- a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 @@ -24,7 +24,9 @@ export default MountWidget.extend(Docking, { }, dockCheck(info) { - const topicTop = $('.container.posts').offset().top - $('#main').offset().top; + const mainOffset = $('#main').offset(); + const offsetTop = mainOffset ? mainOffset.top : 0; + const topicTop = $('.container.posts').offset().top - offsetTop; const topicBottom = $('#topic-bottom').offset().top; const $timeline = this.$('.timeline-container'); const timelineHeight = $timeline.height() || 400; diff --git a/app/assets/javascripts/discourse/mixins/docking.js.es6 b/app/assets/javascripts/discourse/mixins/docking.js.es6 index 8e73c1d3e6e..4b2505b1518 100644 --- a/app/assets/javascripts/discourse/mixins/docking.js.es6 +++ b/app/assets/javascripts/discourse/mixins/docking.js.es6 @@ -1,5 +1,9 @@ const helper = { - offset: () => (window.pageYOffset || $('html').scrollTop()) - $('#main').offset().top + offset() { + const mainOffset = $('#main').offset(); + const offsetTop = mainOffset ? mainOffset.top : 0; + return (window.pageYOffset || $('html').scrollTop()) - offsetTop; + } }; export default Ember.Mixin.create({