Add Jest tests

Automate CSS and JS Banners
Remove image fading for now
Reference docker-compose.yml restored
This commit is contained in:
2018-04-27 18:22:18 +01:00
parent 8492b7cf3d
commit 33ddd5f966
23 changed files with 3919 additions and 1032 deletions

View File

@@ -1,13 +1,19 @@
const CLS = {
const STATES = {
visible: 'is-visible',
minimized: 'is-minimized',
};
export default class Menu {
constructor(cfg) {
this.el = cfg.el;
constructor(cfg = {}) {
if (!cfg.container) return false;
this.container = cfg.container;
this.state = 'visible';
this.lastKnownScrollPosition = 0;
}
init() {
this.container.setAttribute('aria-haspopup', true);
this.container.setAttribute('aria-expanded', false);
this.attachEvents();
setTimeout(() => {
this.showMenu();
@@ -15,33 +21,39 @@ export default class Menu {
}
attachEvents() {
let lastKnownPosition = 0;
window.addEventListener('scroll', () => {
if (this.state !== 'hidden') {
if (this.state !== 'visible' && window.scrollY < lastKnownPosition) {
this.showMenu();
} else if (this.state !== 'minimized' && window.scrollY >
lastKnownPosition) {
this.minimizeMenu();
}
lastKnownPosition = window.scrollY;
}
this.updateState(this.lastKnownScrollPosition, window.scrollY);
this.lastKnownScrollPosition = window.scrollY;
});
}
updateState(lastY = 0, currentY) {
if (this.state !== 'hidden') {
if (this.state !== 'visible' && currentY < lastY) {
this.showMenu();
} else if (this.state !== 'minimized' && currentY >
lastY) {
this.minimizeMenu();
}
}
}
showMenu() {
this.state = 'visible';
this.el.classList.add(CLS.visible);
this.el.classList.remove(CLS.minimized);
this.container.setAttribute('aria-expanded', false);
this.container.classList.add(STATES.visible);
this.container.classList.remove(STATES.minimized);
}
minimizeMenu() {
this.state = 'minimized';
this.el.classList.add(CLS.minimized);
this.container.classList.add(STATES.minimized);
}
hideMenu() {
this.state = 'hidden';
this.el.classList.remove(CLS.visible);
this.container.setAttribute('aria-expanded', true);
this.container.classList.remove(STATES.visible);
}
}