-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (73 loc) · 2.73 KB
/
Copy pathscript.js
File metadata and controls
89 lines (73 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const menuToggle = document.querySelector('.menu-toggle');
const siteNav = document.querySelector('.site-nav');
if (menuToggle && siteNav) {
menuToggle.addEventListener('click', () => {
const open = siteNav.classList.toggle('is-open');
menuToggle.setAttribute('aria-expanded', String(open));
});
siteNav.querySelectorAll('a, button').forEach((link) => {
link.addEventListener('click', () => {
siteNav.classList.remove('is-open');
menuToggle.setAttribute('aria-expanded', 'false');
});
});
}
const homeNavTabs = Array.from(document.querySelectorAll('[data-home-view]'));
const homeViewPanels = Array.from(document.querySelectorAll('.view-panel[data-view]'));
const homeHashMap = {
'#home': 'home',
'#design': 'design',
'#artisan': 'artisan',
'#showroom': 'showroom',
'#wholesale': 'wholesale',
'#about': 'about',
'#contact': 'contact'
};
function activateHomeView(viewName, updateHash = true, scrollToMain = true) {
if (!homeViewPanels.length) return;
homeViewPanels.forEach((panel) => {
const active = panel.dataset.view === viewName;
panel.classList.toggle('is-active', active);
panel.hidden = !active;
});
homeNavTabs.forEach((button) => {
const active = button.dataset.homeView === viewName;
button.classList.toggle('is-current', active);
button.setAttribute('aria-pressed', String(active));
});
if (updateHash) {
const nextHash = viewName === 'home' ? '#home' : `#${viewName}`;
history.replaceState(null, '', nextHash);
}
if (scrollToMain) {
const main = document.querySelector('#main');
if (main) {
window.scrollTo({ top: main.offsetTop - 80, behavior: 'smooth' });
}
}
}
if (homeNavTabs.length && homeViewPanels.length) {
homeNavTabs.forEach((button) => {
button.addEventListener('click', () => activateHomeView(button.dataset.homeView, true, true));
});
const initialView = homeHashMap[window.location.hash] || 'home';
activateHomeView(initialView, false, false);
window.addEventListener('hashchange', () => {
const viewName = homeHashMap[window.location.hash];
if (viewName) activateHomeView(viewName, false, false);
});
}
const slideshows = Array.from(document.querySelectorAll('.slideshow'));
slideshows.forEach((slideshow) => {
const slides = Array.from(slideshow.querySelectorAll('img'));
if (slides.length < 2) return;
let index = slides.findIndex((slide) => slide.classList.contains('is-active'));
if (index < 0) index = 0;
slides[index].classList.add('is-active');
const rotateMs = Number(slideshow.dataset.rotate || 4500);
window.setInterval(() => {
slides[index].classList.remove('is-active');
index = (index + 1) % slides.length;
slides[index].classList.add('is-active');
}, rotateMs);
});