Skip to content

Feature/726 linting errors #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions components/add-to-calendar/add-to-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
Drupal.behaviors.localgovAddToCalendar = {
attach(context) {
const addToCalendarButtons = once(
'all-add-to-calendar-buttons',
'.localgov-add-to-calendar__trigger',
"all-add-to-calendar-buttons",
".localgov-add-to-calendar__trigger",
context,
);
if (addToCalendarButtons.length) {
addToCalendarButtons.forEach((button) => {
const calendarModal = button.nextElementSibling;
const calendarModalClose = calendarModal.querySelector(
'.localgov-add-to-calendar__dialog-close-button',
".localgov-add-to-calendar__dialog-close-button",
);
button.addEventListener('click', () => {
button.addEventListener("click", () => {
calendarModal.showModal();
});
calendarModalClose.addEventListener('click', () => {
calendarModalClose.addEventListener("click", () => {
calendarModal.close();
});
});
Expand Down
16 changes: 8 additions & 8 deletions js/back-to-top.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* past the top of the viewport. In practices, there's only one of
* these since we've only targeted one element.
*/
const [backToTop] = once('back-to-top', '.back-to-top', context);
const [backToTop] = once("back-to-top", ".back-to-top", context);
const [backToTopTarget] = once(
'back-to-top-target',
'.back-to-top-target',
"back-to-top-target",
".back-to-top-target",
context,
);

Expand All @@ -32,7 +32,7 @@
entry.isIntersecting ||
(!entry.isIntersecting && entry.boundingClientRect.top <= 0)
? false
: 'until-hidden';
: "until-hidden";
});
}

Expand All @@ -52,15 +52,15 @@
}

// Create an element absolutely positioned at our threshold.
backToTopTarget.style.position = 'absolute';
backToTopTarget.style.position = "absolute";
backToTopTarget.style.top = `${viewportHeight * minContentViewportRatio}px`;
backToTop.addEventListener('click', (event) => {
event.target.hidden = 'until-found';
backToTop.addEventListener("click", (event) => {
event.target.hidden = "until-found";
});

// Create an IntersectionObserver.
const intersectionObserver = new IntersectionObserver(observerCallback, {
rootMargin: '16px',
rootMargin: "16px",
});
intersectionObserver.observe(backToTopTarget);
},
Expand Down
4 changes: 2 additions & 2 deletions js/guides.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// the element with the corresponding ID.
const path = window.location.hash;
// check if path links to id
if (path.includes('#')) {
const id = path.split('#')[1];
if (path.includes("#")) {
const id = path.split("#")[1];
const element = document.querySelector(`#${id}`);
if (element) {
element.focus();
Expand Down
72 changes: 36 additions & 36 deletions js/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
// @todo: make it possible to override this without having to maintain a
// *copy* of this file.
const headerSearchFormLabel = once(
'header-search-label',
'.lgd-region--search form label',
"header-search-label",
".lgd-region--search form label",
context,
);

if (headerSearchFormLabel.length) {
headerSearchFormLabel[0].classList.add('visually-hidden');
headerSearchFormLabel[0].classList.add("visually-hidden");
}

// Set up initial variables.
//
// We need a bunch of classes and selectors.
let secondaryMenuRegionIsOpen = false;
const headerToggleSelector = '.lgd-header__toggle';
const primaryToggleClass = 'lgd-header__toggle--primary';
const toggleActiveClass = 'lgd-header__toggle--active';
const regionActiveClass = 'lgd-header__nav--active';
const headerToggleSelector = ".lgd-header__toggle";
const primaryToggleClass = "lgd-header__toggle--primary";
const toggleActiveClass = "lgd-header__toggle--active";
const regionActiveClass = "lgd-header__nav--active";
// This contains all toggles and their corresponding regions.
const navInfo = {};
// This is used as a check on resize to see if the window size *actually*
Expand All @@ -36,7 +36,7 @@
// and we can build an object full of references to them and to their
// regions. We use .once() to avoid re-running this.
const headerToggles = once(
'header-toggle',
"header-toggle",
headerToggleSelector,
context,
);
Expand All @@ -49,7 +49,7 @@
// button attributes.
function handleReset() {
headerToggles.forEach((headerToggle) => {
headerToggle.setAttribute('aria-expanded', 'false');
headerToggle.setAttribute("aria-expanded", "false");
headerToggle.classList.remove(toggleActiveClass);
});

Expand All @@ -60,12 +60,12 @@

// General function for when the ESC is clicked.
function handleEscKeyClick(buttonToFocus) {
context.addEventListener('keydown', (e) => {
context.addEventListener("keydown", (e) => {
// When on any link in the secondary menu, if you hit escape
// set focus back to:
// 1. menu button on small screens, and
// 2. services button on large screens
if (e.key === 'Escape') {
if (e.key === "Escape") {
e.preventDefault();
handleReset();
buttonToFocus.focus();
Expand All @@ -77,15 +77,15 @@
// references to the various DOM elements we need to work with.
headerToggles.forEach((toggle) => {
const region = context.getElementById(
toggle.getAttribute('aria-controls'),
toggle.getAttribute("aria-controls"),
);
const nav = toggle.classList.contains(primaryToggleClass)
? 'primary'
: 'secondary';
? "primary"
: "secondary";
// The resulting region.primary.firstLink isn't used, but it's less
// difficult to add it than to add only region.secondary.firstLink.
if (region) {
const links = region.querySelectorAll('.menu a');
const links = region.querySelectorAll(".menu a");
const firstLink = links[0];
const lastLink = links[links.length - 1];

Expand All @@ -98,9 +98,9 @@
function handleToggleClick(toggleThatWasClicked) {
// Get the current state as a boolean.
const currentState =
toggleThatWasClicked.getAttribute('aria-expanded') === 'true';
toggleThatWasClicked.getAttribute("aria-expanded") === "true";

toggleThatWasClicked.setAttribute('aria-expanded', !currentState);
toggleThatWasClicked.setAttribute("aria-expanded", !currentState);
toggleThatWasClicked.classList.toggle(toggleActiveClass);
}

Expand All @@ -127,8 +127,8 @@
// When on the first link in the secondary menu, if you shift+tab
// set focus back to the services button
function handleSecondaryMenuShiftTabClick() {
navInfo.secondary.firstLink.addEventListener('keydown', (e) => {
if (e.shiftKey && e.key === 'Tab') {
navInfo.secondary.firstLink.addEventListener("keydown", (e) => {
if (e.shiftKey && e.key === "Tab") {
e.preventDefault();
navInfo.secondary.toggle.focus();
}
Expand All @@ -138,8 +138,8 @@
// When on the last link in the secondary menu, if you hit tab
// set focus back to the services button
function handleSecondaryMenuTabClick() {
navInfo.secondary.lastLink.addEventListener('keydown', (e) => {
if (e.key === 'Tab') {
navInfo.secondary.lastLink.addEventListener("keydown", (e) => {
if (e.key === "Tab") {
e.preventDefault();
navInfo.secondary.toggle.focus();
}
Expand All @@ -148,10 +148,10 @@

// If you click on the page, anywhere outside the secondary menu region
// or the secondary menu toggle button, close the secondary menu region
document.addEventListener('click', (e) => {
document.addEventListener("click", (e) => {
if (
!e.target.closest('#lgd-header__nav--secondary') &&
!e.target.closest('.lgd-header__toggle--secondary') &&
!e.target.closest("#lgd-header__nav--secondary") &&
!e.target.closest(".lgd-header__toggle--secondary") &&
secondaryMenuRegionIsOpen
) {
handleSecondaryMenuToggleClick();
Expand All @@ -169,56 +169,56 @@

if (window.innerWidth < 768) {
if (
Object.keys(navInfo).includes('secondary') &&
Object.keys(navInfo).includes("secondary") &&
navInfo.secondary.toggle
) {
navInfo.secondary.toggle.removeEventListener(
'click',
"click",
handleSecondaryMenuToggleClick,
true,
);
navInfo.secondary.toggle.removeEventListener(
'click',
"click",
handleSecondaryMenuShiftTabClick,
true,
);
navInfo.secondary.toggle.removeEventListener(
'click',
"click",
handleSecondaryMenuTabClick,
true,
);
}
if (navInfo.primary.toggle) {
navInfo.primary.toggle.addEventListener(
'click',
"click",
handlePrimaryMenuToggleClick,
);
}
} else {
if (
Object.keys(navInfo).includes('primary') &&
Object.keys(navInfo).includes("primary") &&
navInfo.primary.toggle
) {
navInfo.primary.toggle.removeEventListener(
'click',
"click",
handlePrimaryMenuToggleClick,
true,
);
}
if (
Object.keys(navInfo).includes('secondary') &&
Object.keys(navInfo).includes("secondary") &&
navInfo.secondary.toggle
) {
navInfo.secondary.toggle.addEventListener(
'click',
"click",
handleSecondaryMenuToggleClick,
);
navInfo.secondary.toggle.addEventListener(
'click',
"click",
handleSecondaryMenuShiftTabClick,
);
navInfo.secondary.toggle.addEventListener(
'keyup',
"keyup",
handleSecondaryMenuTabClick,
);
}
Expand All @@ -239,7 +239,7 @@
// Call our functions, initially and also when the window is resized.
handleWindowResized();
window.addEventListener(
'resize',
"resize",
Drupal.debounce(handleCheckIfWindowActuallyResized, 50, false),
);
},
Expand Down
31 changes: 15 additions & 16 deletions js/sticky-header.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function stickyHeaderScript(Drupal) {
Drupal.behaviors.stickyHeader = {
attach(context) {
const headers = once('allStickyHeaders', '.lgd-header', context);
const headers = once("allStickyHeaders", ".lgd-header", context);

if (!headers) {
return;
Expand All @@ -11,42 +11,41 @@
function calculatePositions() {
let tabsHeight = 0;
const tabs = header
.closest('body')
.querySelector('.lgd-region--tabs');
.closest("body")
.querySelector(".lgd-region--tabs");
if (tabs) {
tabsHeight = tabs.offsetHeight;
}

let displaceOffsetTop = 0;
const displaceOffsetTopValue = parseInt(
getComputedStyle(document.documentElement)
.getPropertyValue('--drupal-displace-offset-top')
.replace('px', ''),
.getPropertyValue("--drupal-displace-offset-top")
.replace("px", ""),
10,
);
console.log('working');
if (displaceOffsetTopValue) {
displaceOffsetTop = displaceOffsetTopValue;
}

const headerHeight = header.offsetHeight;
const headerPosition = displaceOffsetTop + tabsHeight;

if (header.closest('body').classList.contains('sticky-header')) {
if (header.closest("body").classList.contains("sticky-header")) {
document.documentElement.style.setProperty(
'--lgd-sticky-header-position',
"--lgd-sticky-header-position",
`${headerPosition}px`,
);
document.documentElement.style.setProperty(
'--lgd-sticky-header-height',
"--lgd-sticky-header-height",
`${headerHeight}px`,
);
}

if (
header.closest('body').classList.contains('sticky-header--sticky')
header.closest("body").classList.contains("sticky-header--sticky")
) {
header.style.position = 'fixed';
header.style.position = "fixed";
}
}

Expand All @@ -55,10 +54,10 @@

function handleScroll() {
if (oldScroll > window.scrollY) {
header.closest('body').classList.add('sticky-header--sticky');
header.closest("body").classList.add("sticky-header--sticky");
} else {
header.closest('body').classList.remove('sticky-header--sticky');
header.style.position = 'relative';
header.closest("body").classList.remove("sticky-header--sticky");
header.style.position = "relative";
}
// Update oldScroll to the new scroll position after the comparison
oldScroll = window.scrollY;
Expand All @@ -67,9 +66,9 @@
}

if (
header.closest('body').classList.contains('sticky-header--scroll')
header.closest("body").classList.contains("sticky-header--scroll")
) {
window.addEventListener('scroll', handleScroll);
window.addEventListener("scroll", handleScroll);
}

setTimeout(() => {
Expand Down
Loading
Loading