diff --git a/lib/assets/javascripts/_modules/table-of-contents.js b/lib/assets/javascripts/_modules/table-of-contents.js index 850d7285..5fe2f780 100644 --- a/lib/assets/javascripts/_modules/table-of-contents.js +++ b/lib/assets/javascripts/_modules/table-of-contents.js @@ -10,7 +10,7 @@ this.isMonitoring = false } StickyOverlapMonitors.prototype.run = function () { - var stickyIsVisible = this.$sticky.is(':visible') + var stickyIsVisible = this.$sticky && this.$sticky.is(':visible') if (stickyIsVisible && !this.isMonitoring) { document.addEventListener('focus', this.onFocus, true) this.isMonitoring = true @@ -26,11 +26,13 @@ if (!applicable) { return } - var stickyEdge = this.$sticky.get(0).getBoundingClientRect().bottom + this.offset - var diff = focused.getBoundingClientRect().top - stickyEdge + if (this.$sticky && this.$sticky.is(':visible') && this.$sticky.get(0)) { + var stickyEdge = this.$sticky.get(0).getBoundingClientRect().bottom + this.offset + var diff = focused.getBoundingClientRect().top - stickyEdge - if (diff < 0) { - $(window).scrollTop($(window).scrollTop() + diff) + if (diff < 0) { + $(window).scrollTop($(window).scrollTop() + diff) + } } }