From eab85ee822235e9272a65c28798f4af87111cf72 Mon Sep 17 00:00:00 2001 From: Marco Tranchino Date: Tue, 24 Sep 2024 16:59:22 +0100 Subject: [PATCH] Update JQuery visibility check on sticky element Following a PR review[1], this commit changes the test on this.$sticky, in order to verify if the object actually contains any elements. Further details in the PR[2]. [1] https://github.com/alphagov/tech-docs-gem/pull/368#issuecomment-2370689455 [2] https://github.com/alphagov/tech-docs-gem/pull/368 --- lib/assets/javascripts/_modules/table-of-contents.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assets/javascripts/_modules/table-of-contents.js b/lib/assets/javascripts/_modules/table-of-contents.js index 5fe2f780..b24257e7 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 && this.$sticky.is(':visible') + var stickyIsVisible = this.$sticky.length > 0 && this.$sticky.is(':visible') if (stickyIsVisible && !this.isMonitoring) { document.addEventListener('focus', this.onFocus, true) this.isMonitoring = true