add base styles and scripts

This commit is contained in:
2025-09-04 22:41:59 +01:00
parent a665235b9f
commit 5ed57ac818
43 changed files with 1554 additions and 13 deletions

View File

@@ -1,10 +1,19 @@
import domReady from '@roots/sage/client/dom-ready';
import Header from '../views/sections/header/header';
import Footer from '../views/sections/footer/footer';
import blocks from './blocks.js';
import LazyLoad from './lib/Lazy.js';
import Accordion from './lib/Accordion.js';
/**
* Application entrypoint
*/
domReady(async () => {
// ...
LazyLoad();
Accordion();
Header();
Footer();
blocks();
});
/**

View File

@@ -0,0 +1,6 @@
import WYSIWYG from '../views/blocks/WYSIWYG/WYSIWYG';
export default function()
{
WYSIWYG();
}

View File

@@ -0,0 +1,15 @@
export default function Accordion()
{
const accordions = document.querySelectorAll(".js-accordion");
if(!accordions) return;
accordions.forEach(accordion => {
const question = accordion.querySelector(".js-accordion-toggle");
question.addEventListener("click", function(e) {
e.preventDefault();
accordion.classList.toggle("open");
});
});
}

View File

@@ -0,0 +1,33 @@
export default function LazyLoadInit()
{
document.addEventListener('DOMContentLoaded', LazyLoad());
}
function LazyLoad() {
var lazyImages = [].slice.call(document.querySelectorAll('img.lazy'));
if ('IntersectionObserver' in window) {
let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
let lazyImage = entry.target;
lazyImage.src = lazyImage.dataset.src;
if(lazyImage.dataset.srcset) {
lazyImage.srcset = lazyImage.dataset.srcset;
}
lazyImage.classList.remove('lazy');
lazyImageObserver.unobserve(lazyImage);
}
});
});
lazyImages.forEach(function(lazyImage) {
lazyImageObserver.observe(lazyImage);
});
} else {
// Possibly fall back to a more compatible method here
}
}

View File

@@ -0,0 +1,24 @@
export default function VideoSrcset( element )
{
const sizes = JSON.parse(element.dataset.sizes);
Object.keys(sizes).forEach((key) => {
const size = key;
const source = element.querySelector('.bgvid-' + size);
if(source) {
const sourceWidth = source.dataset.width;
const poster = source.dataset.poster;
if(window.innerWidth >= sourceWidth) {
console.log('screen width is greater than or equal to the source width');
console.log('screen width: ' + window.innerWidth);
console.log('source width: ' + sourceWidth);
element.src = source.src;
element.poster = poster;
element.load;
}
}
});
}