From 19b68048d0d6f3fcd1b41cd3768ebae24d5bacdb Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Fri, 10 May 2019 13:58:21 +0100 Subject: [PATCH] Fix undefined local variables in sticky JS Running the sticky JS in Jest raised errors due to these variables not being assigned properly. It's JavaScript so any variable not defined by the `var` prefix will automatically become a property of the global object. That is not what is intended by the code so requires changing. --- app/assets/javascripts/stick-to-window-when-scrolling.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/stick-to-window-when-scrolling.js b/app/assets/javascripts/stick-to-window-when-scrolling.js index 7f2066aa5..0a3176beb 100644 --- a/app/assets/javascripts/stick-to-window-when-scrolling.js +++ b/app/assets/javascripts/stick-to-window-when-scrolling.js @@ -11,12 +11,11 @@ var $scrollArea = $el.closest('.sticky-scroll-area'); $scrollArea = $scrollArea.length ? $scrollArea : $el.parent(); - scrollArea = $scrollArea.get(0); this._els = [el]; this.edge = edge; this.selector = selector; - this.node = scrollArea; + this.node = $scrollArea.get(0); this.setEvents(); }; ScrollArea.prototype.addEl = function (el) { @@ -38,7 +37,7 @@ }; ScrollArea.prototype.getFocusedDetails = { forElement: function ($focusedElement) { - focused = { + var focused = { 'top': $focusedElement.offset().top, 'height': $focusedElement.outerHeight(), 'type': 'element'