-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
131 lines (113 loc) · 5.29 KB
/
script.js
File metadata and controls
131 lines (113 loc) · 5.29 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
document.addEventListener('DOMContentLoaded', () => {
// 1. Mobile Menu Toggle
const mobileMenuBtn = document.getElementById('mobileMenuBtn');
const navLinks = document.getElementById('navLinks');
if (mobileMenuBtn) {
mobileMenuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
// Change icon
const icon = navLinks.classList.contains('active') ? 'x' : 'menu';
mobileMenuBtn.innerHTML = `<i data-feather="${icon}"></i>`;
feather.replace();
});
}
// Close mobile menu when a link is clicked
const links = document.querySelectorAll('.nav-link');
links.forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
mobileMenuBtn.innerHTML = `<i data-feather="menu"></i>`;
feather.replace();
});
});
// 2. Navbar Scroll Effect
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.style.padding = '10px 0';
navbar.style.boxShadow = '0 4px 10px rgba(0,0,0,0.1)';
} else {
navbar.style.padding = '15px 0';
navbar.style.boxShadow = '0 4px 6px rgba(0,0,0,0.05)';
}
});
// 3. Smooth Scrolling for Anchor Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if(targetId === '#') return;
const targetElement = document.querySelector(targetId);
if(targetElement) {
const headerOffset = 70;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
}
});
});
// 4. Handle "आताच मागवा" (Order Now) buttons clicking
const orderBtns = document.querySelectorAll('.order-btn');
const productSelect = document.getElementById('product');
orderBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
const productName = btn.getAttribute('data-product');
// Auto-select in form
if (productSelect) {
for(let i=0; i < productSelect.options.length; i++) {
if(productSelect.options[i].value === productName) {
productSelect.selectedIndex = i;
break;
}
}
}
// Scroll to contact form
const contactSection = document.getElementById('contact');
if (contactSection) {
const headerOffset = 70;
const elementPosition = contactSection.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
}
});
});
// 5. WhatsApp Integration
const phoneNumber = "919876543210"; // Replace with actual WhatsApp number
// Main WhatsApp Button
const whatsappMainBtn = document.getElementById('whatsappMainBtn');
if (whatsappMainBtn) {
whatsappMainBtn.addEventListener('click', (e) => {
e.preventDefault();
const message = encodeURIComponent("नमस्कार, मला ताजे कलिंगड (Watermelon) खरेदी करायचे आहे. कृपया मला माहिती सांगा.");
window.open(`https://wa.me/${phoneNumber}?text=${message}`, '_blank');
});
}
// Order Form Submission
const orderForm = document.getElementById('orderForm');
if (orderForm) {
orderForm.addEventListener('submit', (e) => {
e.preventDefault();
const name = document.getElementById('name').value;
const phone = document.getElementById('phone').value;
const product = document.getElementById('product').value;
const quantity = document.getElementById('quantity').value;
const address = document.getElementById('address').value;
// Format WhatsApp Message in Marathi/English
const message = `*नवीन ऑर्डर (Fresh Tarbuj Center)*%0A%0A` +
`*नाव:* ${name}%0A` +
`*मोबाईल:* ${phone}%0A` +
`*उत्पादन:* ${product}%0A` +
`*प्रमाण (नग):* ${quantity}%0A` +
`*पत्ता:* ${address}%0A%0A` +
`कृपया माझी ऑर्डर कन्फर्म करा.`;
window.open(`https://wa.me/${phoneNumber}?text=${message}`, '_blank');
});
}
});