Skip to content

Commit

Permalink
Merge pull request #293 from nhsuk/bug/feedback-banner-js-error
Browse files Browse the repository at this point in the history
[refs #107] Fix feedback banner JS to prevent console errors
  • Loading branch information
mcheung-nhs authored Dec 11, 2018
2 parents dfa7e59 + 8103ed8 commit e3322c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# NHS.UK Frontend Changelog

## 0.5.1 (Prerelease) - Dec 11, 2018

:wrench: **Fixes**

- Feedback banner - Fix an issue with the JavaScript reporting errors within the console log
when scrolling down the page if the feedback banner did not exist on the page. ([PR 293](https://github.com/nhsuk/nhsuk-frontend/pull/293))

- Details - Add the missing component JavaScript to the `nhsuk.min.js` bundle. ([PR 285](https://github.com/nhsuk/nhsuk-frontend/pull/285))

## 0.5.0 (Prerelease) - Dec 07, 2018

:boom: **Breaking changes**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nhsuk-frontend",
"version": "0.5.0",
"version": "0.5.1",
"description": "The NHS website frontend styles, for creating NHS websites and services.",
"sasslintConfig": "config/sass-lint.yml",
"scripts": {
Expand Down
34 changes: 18 additions & 16 deletions packages/components/feedback-banner/feedback-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@ document.addEventListener("DOMContentLoaded", function(){
// isScrolledIntoView function and spiking CPU, to check when the footer
// comes in to view, to make the banner not sticky but position it in the
// normal flow of the page below the footer
$(window).scroll(function() {
if (!didScroll) {
timer = setInterval(function() {
if (didScroll) {
didScroll = false;
clearTimeout(timer);

if (isScrolledIntoView(footer)) {
banner.classList.add("js-inview")
} else {
banner.classList.remove("js-inview")
if (typeof(banner) != 'undefined' && banner != null) {
$(window).scroll(function() {
if (!didScroll) {
timer = setInterval(function() {
if (didScroll) {
didScroll = false;
clearTimeout(timer);

if (isScrolledIntoView(footer)) {
banner.classList.add("js-inview")
} else {
banner.classList.remove("js-inview")
}
}
}
}, 500);
}
didScroll = true;
});
}, 500);
}
didScroll = true;
});
}

});

Expand Down

0 comments on commit e3322c5

Please sign in to comment.