Skip to content

Commit

Permalink
Give a try to (semi)standard
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlaki committed Aug 21, 2024
1 parent 384dd72 commit 9b429e6
Show file tree
Hide file tree
Showing 10 changed files with 1,788 additions and 69 deletions.
1,790 changes: 1,749 additions & 41 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"eleventy:serve": "npx eleventy --serve",
"eleventy:build": "npx eleventy",
"build": "npm-run-all dist:delete sass:compile eleventy:build",
"js:lint": "semistandard src/js/*.js",
"js:fix": "semistandard src/js/*.js --fix",
"sass:watch": "sass --watch --update --load-path=node_modules --no-source-map --style=expanded src/scss:src/css",
"sass:fix": "stylelint src/scss/**/*.scss --fix",
"sass:lint": "stylelint src/scss/**/*.scss",
Expand All @@ -28,6 +30,7 @@
"sass": "^1.77.8",
"slugify": "^1.6.6",
"sprucecss": "^2.3.3",
"semistandard": "^17.0.0",
"stylelint": "^16.8.2",
"stylelint-config-sass-guidelines": "^12.0.0",
"stylelint-order": "^6.0.4"
Expand Down
24 changes: 12 additions & 12 deletions src/js/cookie-consent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
setCookie, getCookie, issetCookie, removeCookie,
setCookie, getCookie, issetCookie, removeCookie
} from './cookie.js';

(() => {
Expand All @@ -10,8 +10,8 @@ import {
let redirect = false;

if (
!issetCookie(`${prefix}-cookie-law-analytics`)
&& !issetCookie(`${prefix}-cookie-law-denied`)
!issetCookie(`${prefix}-cookie-law-analytics`) &&
!issetCookie(`${prefix}-cookie-law-denied`)
) {
caption = `<div class="cookie-consent-helper"><div class="cookie-consent cookie-consent--slidein" tabindex="-1">
<div class="cookie-consent__caption">This site use cookies. For more information please visit our <a href="/privacy-policy/">privacy policy</a> page.</div>
Expand All @@ -26,7 +26,7 @@ import {
consentModal.focus();
}

function animationEndCallback() {
function animationEndCallback () {
consentModal.removeEventListener('animationend', animationEndCallback);

if (redirect) {
Expand All @@ -36,8 +36,8 @@ import {

document.addEventListener('click', (e) => {
if (
e.target
&& e.target.getAttribute('data-action') === 'cookie-accept'
e.target &&
e.target.getAttribute('data-action') === 'cookie-accept'
) {
setCookie(`${prefix}-cookie-law-analytics`, 'accepted', 365);

Expand All @@ -47,8 +47,8 @@ import {
}

if (
e.target
&& e.target.getAttribute('data-action') === 'cookie-decline'
e.target &&
e.target.getAttribute('data-action') === 'cookie-decline'
) {
setCookie(`${prefix}-cookie-law-denied`, 'true');

Expand All @@ -60,8 +60,8 @@ import {

btns.forEach((btn) => {
if (
issetCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`)
&& getCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`) === 'accepted'
issetCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`) &&
getCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`) === 'accepted'
) {
btn.innerHTML = `${btn.getAttribute('data-on-text')} ${btn.innerHTML}`;
} else {
Expand All @@ -70,8 +70,8 @@ import {

btn.addEventListener('click', () => {
if (
issetCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`)
&& getCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`) === 'accepted'
issetCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`) &&
getCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`) === 'accepted'
) {
removeCookie(`${prefix}-cookie-law-${btn.getAttribute('data-type')}`);
} else {
Expand Down
16 changes: 9 additions & 7 deletions src/js/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
* @param {object} options
* @return {void}
*/
export function setCookie(key, value, expires = null, path = '/', options = {}) {
export function setCookie (key, value, expires = null, path = '/', options = {}) {
const defaults = {
[key]: value,
expires,
path,
SameSite: 'Lax',
Secure: true,
Secure: true
};

const pairs = { ...defaults, ...options };

pairs.expires = pairs.expires ? new Date(Date.now() + 86400 * 1000 * pairs.expires)
.toUTCString() : null;
pairs.expires = pairs.expires
? new Date(Date.now() + 86400 * 1000 * pairs.expires)
.toUTCString()
: null;

document.cookie = Object.entries(pairs)
.reduce((stack, entry) => stack.concat(entry.join('=')), [])
Expand All @@ -33,7 +35,7 @@ export function setCookie(key, value, expires = null, path = '/', options = {})
* @param {string} key
* @return {mixed}
*/
export function getCookie(key) {
export function getCookie (key) {
const cookie = document.cookie.match(new RegExp(`(^| )${key}=([^;]+)`));

return (cookie && cookie[2]) ? cookie[2] : null;
Expand All @@ -45,7 +47,7 @@ export function getCookie(key) {
* @param {string} key
* @return {bool}
*/
export function issetCookie(key) {
export function issetCookie (key) {
return document.cookie.match(new RegExp(`(^| )${key}=([^;]+)`)) !== null;
}

Expand All @@ -55,6 +57,6 @@ export function issetCookie(key) {
* @param {string} key
* @return {void}
*/
export function removeCookie(key) {
export function removeCookie (key) {
setCookie(key, null, 'Thu, 01 Jan 1970 00:00:01 GMT');
}
6 changes: 3 additions & 3 deletions src/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

if (!buttons || !modal) return;

function openModal() {
function openModal () {
activeElement = document.activeElement;
siteWrapper.setAttribute('inert', '');
modal.classList.add('modal-backdrop--open');
input.focus();
}

function closeModal() {
function closeModal () {
siteWrapper.removeAttribute('inert');
modal.classList.remove('modal-backdrop--open');
activeElement.focus();
}

function handleKeyDown(e) {
function handleKeyDown (e) {
if (e.code === 'Escape') {
closeModal();
}
Expand Down
4 changes: 3 additions & 1 deletion src/js/navigation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global getComputedStyle */

(() => {
const header = document.querySelector('.site-header');
const navigation = document.querySelector('.site-navigation');
Expand All @@ -7,7 +9,7 @@

if (!menu || typeof button === 'undefined') return;

function widthChange(query) {
function widthChange (query) {
button.setAttribute('aria-expanded', !query.matches);
}

Expand Down
4 changes: 2 additions & 2 deletions src/js/scripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
getCookie,
getCookie
} from './cookie.js';

if (getCookie('spruce-cookie-law-analytics') === 'accepted') {
Expand All @@ -19,6 +19,6 @@ if (getCookie('spruce-cookie-law-analytics') === 'accepted') {
gtag('js', new Date());
gtag('config', spruceGtagId, {
cookie_domain: window.location.hostname,
cookie_flags: 'SameSite=None;Secure',
cookie_flags: 'SameSite=None;Secure'
});
}
4 changes: 3 additions & 1 deletion src/js/theme-detection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* global localStorage */

(() => {
const systemMode = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
const preferredTheme = localStorage.getItem('preferred-theme');

function setTheme(theme) {
function setTheme (theme) {
document.documentElement.setAttribute('data-theme-mode', theme === 'system' ? systemMode : theme);
}

Expand Down
2 changes: 2 additions & 0 deletions src/js/theme-switcher.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global localStorage */

(() => {
const themeSwitcher = document.querySelector('#theme-switcher');
const preferredTheme = localStorage.getItem('preferred-theme') ?? 'system';
Expand Down
4 changes: 2 additions & 2 deletions src/js/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
if (targetElement) {
scrollItems.push({
offset: targetElement.getBoundingClientRect().top + document.documentElement.scrollTop - 70,
element: item,
element: item
});
}
});

function updateActiveItems() {
function updateActiveItems () {
const scrollPosition = window.scrollY;

const activeItem = scrollItems.reduce((closestItem, currentItem) => {
Expand Down

0 comments on commit 9b429e6

Please sign in to comment.