Integrate Prettier in to Stylelint and ESLint
This commit is contained in:
29
js/menu.js
29
js/menu.js
@@ -1,20 +1,20 @@
|
||||
const STATES = {
|
||||
visible: 'is-visible',
|
||||
minimized: 'is-minimized',
|
||||
visible: "is-visible",
|
||||
minimized: "is-minimized",
|
||||
};
|
||||
|
||||
export default class Menu {
|
||||
constructor(cfg = {}) {
|
||||
if (!cfg.container) return false;
|
||||
this.container = cfg.container;
|
||||
this.state = 'visible';
|
||||
this.state = "visible";
|
||||
this.lastKnownScrollPosition = 0;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (!this.state) return false;
|
||||
this.container.setAttribute('aria-haspopup', true);
|
||||
this.container.setAttribute('aria-expanded', false);
|
||||
this.container.setAttribute("aria-haspopup", true);
|
||||
this.container.setAttribute("aria-expanded", false);
|
||||
this.attachEvents();
|
||||
setTimeout(() => {
|
||||
this.showMenu();
|
||||
@@ -23,38 +23,37 @@ export default class Menu {
|
||||
}
|
||||
|
||||
attachEvents() {
|
||||
window.addEventListener('scroll', () => {
|
||||
window.addEventListener("scroll", () => {
|
||||
this.updateState(this.lastKnownScrollPosition, window.scrollY);
|
||||
this.lastKnownScrollPosition = window.scrollY;
|
||||
});
|
||||
}
|
||||
|
||||
updateState(lastY = 0, currentY) {
|
||||
if (this.state !== 'hidden') {
|
||||
if (this.state !== 'visible' && currentY < lastY) {
|
||||
if (this.state !== "hidden") {
|
||||
if (this.state !== "visible" && currentY < lastY) {
|
||||
this.showMenu();
|
||||
} else if (this.state !== 'minimized' && currentY
|
||||
> lastY) {
|
||||
} else if (this.state !== "minimized" && currentY > lastY) {
|
||||
this.minimizeMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showMenu() {
|
||||
this.state = 'visible';
|
||||
this.container.setAttribute('aria-expanded', false);
|
||||
this.state = "visible";
|
||||
this.container.setAttribute("aria-expanded", false);
|
||||
this.container.classList.add(STATES.visible);
|
||||
this.container.classList.remove(STATES.minimized);
|
||||
}
|
||||
|
||||
minimizeMenu() {
|
||||
this.state = 'minimized';
|
||||
this.state = "minimized";
|
||||
this.container.classList.add(STATES.minimized);
|
||||
}
|
||||
|
||||
hideMenu() {
|
||||
this.state = 'hidden';
|
||||
this.container.setAttribute('aria-expanded', true);
|
||||
this.state = "hidden";
|
||||
this.container.setAttribute("aria-expanded", true);
|
||||
this.container.classList.remove(STATES.visible);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user