-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
164 lines (149 loc) · 6.34 KB
/
Copy pathscript.js
File metadata and controls
164 lines (149 loc) · 6.34 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
var WA_NUMBER = "919963932277";
function openWA(product, name, phone, qty, message) {
var lines = ["Hello Spirucraft! I'm interested in: *" + product + "*"];
if (name) lines.push("Name: " + name);
if (phone) lines.push("Phone: " + phone);
if (qty) lines.push("Quantity: " + qty);
if (message) lines.push("Message: " + message);
var text = encodeURIComponent(lines.join("\n"));
window.open("https://wa.me/" + WA_NUMBER + "?text=" + text, "_blank");
}
document.addEventListener('DOMContentLoaded', function() {
// ---------- Modal ----------
var overlay = document.getElementById('modalOverlay');
var label = document.getElementById('modalProductLabel');
var currentProduct = "General Enquiry";
window.openModal = function(product) {
currentProduct = product;
if (label) label.textContent = product;
if (overlay) {
overlay.classList.add('open');
document.body.style.overflow = 'hidden';
}
};
function closeModal() {
if (overlay) {
overlay.classList.remove('open');
document.body.style.overflow = '';
}
}
var modalCloseBtn = document.getElementById('modalClose');
if (modalCloseBtn) modalCloseBtn.addEventListener('click', closeModal);
if (overlay) overlay.addEventListener('click', function(e) { if (e.target === overlay) closeModal(); });
var enquiryForm = document.getElementById('enquiryForm');
if (enquiryForm) {
enquiryForm.addEventListener('submit', function(e) {
e.preventDefault();
var name = document.getElementById('fName').value.trim();
var phone = document.getElementById('fPhone').value.trim();
var qty = document.getElementById('fQty').value.trim();
var message = document.getElementById('fMessage').value.trim();
openWA(currentProduct, name, phone, qty, message);
closeModal();
this.reset();
});
}
// ---------- Inline contact-page form (submits straight to WhatsApp) ----------
var pageForm = document.getElementById('pageEnquiryForm');
if (pageForm) {
pageForm.addEventListener('submit', function(e) {
e.preventDefault();
var name = document.getElementById('pfName').value.trim();
var phone = document.getElementById('pfPhone').value.trim();
var qty = document.getElementById('pfQty').value.trim();
var message = document.getElementById('pfMessage').value.trim();
openWA('General Enquiry', name, phone, qty, message);
});
}
// ---------- Mobile menu ----------
var mm = document.getElementById('mobileMenu');
var hamburgerBtn = document.getElementById('hamburgerBtn');
var mmClose = document.getElementById('mmClose');
if (hamburgerBtn) hamburgerBtn.addEventListener('click', function() {
mm.classList.add('open');
document.body.style.overflow = 'hidden';
});
if (mmClose) mmClose.addEventListener('click', function() {
mm.classList.remove('open');
document.body.style.overflow = '';
});
if (mm) {
mm.querySelectorAll('a').forEach(function(a) {
a.addEventListener('click', function() {
mm.classList.remove('open');
document.body.style.overflow = '';
});
});
}
// ---------- Scroll-triggered process diagram draw-in ----------
var flowPaths = document.querySelectorAll('.flow-path');
var diagramEl = document.getElementById('processSvg');
if (diagramEl && flowPaths.length) {
var io = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
flowPaths.forEach(function(p, i) { setTimeout(function() { p.classList.add('in-view'); }, i * 180); });
io.disconnect();
}
});
}, { threshold: 0.3 });
io.observe(diagramEl);
}
// ---------- FAQ accordion ----------
document.querySelectorAll('.faq-item').forEach(function(item) {
var q = item.querySelector('.faq-q');
var a = item.querySelector('.faq-a');
q.addEventListener('click', function() {
var isOpen = item.classList.contains('open');
document.querySelectorAll('.faq-item.open').forEach(function(other) {
if (other !== item) {
other.classList.remove('open');
other.querySelector('.faq-a').style.maxHeight = null;
}
});
if (isOpen) {
item.classList.remove('open');
a.style.maxHeight = null;
} else {
item.classList.add('open');
a.style.maxHeight = a.scrollHeight + 'px';
}
});
});
// ---------- Product filter tabs (products.html) ----------
var tabs = document.querySelectorAll('.filter-tab');
var cards = document.querySelectorAll('[data-category]');
tabs.forEach(function(tab) {
tab.addEventListener('click', function() {
tabs.forEach(function(t) {
t.classList.remove('active');
});
tab.classList.add('active');
var cat = tab.getAttribute('data-filter');
cards.forEach(function(card) {
var categories = card.getAttribute('data-category').split(' ');
var show = cat === 'all' || categories.includes(cat);
card.style.display = show ? '' : 'none';
});
});
});
// ---------- Reveal-on-scroll for generic elements ----------
var revealEls = document.querySelectorAll('.reveal');
if (revealEls.length) {
var rio = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
rio.unobserve(entry.target);
}
});
}, { threshold: 0.15 });
revealEls.forEach(function(el) {
el.style.opacity = '0';
el.style.transform = 'translateY(16px)';
el.style.transition = 'opacity .6s ease, transform .6s ease';
rio.observe(el);
});
}
});