-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (130 loc) · 5.41 KB
/
Copy pathscript.js
File metadata and controls
155 lines (130 loc) · 5.41 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
// Screen scroll animations (Intersection Observer)
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animated');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.addEventListener('DOMContentLoaded', function() {
// Animations apply kirima
const animatedElements = document.querySelectorAll(
'.animate-on-scroll, .animate-left, .animate-right, .animate-scale, .animate-fade-in, .animate-stagger'
);
animatedElements.forEach(el => observer.observe(el));
const menuToggle = document.querySelector('.menu-toggle');
const nav = document.querySelector('nav');
if (menuToggle && nav) {
menuToggle.addEventListener('click', function(e) {
e.stopPropagation();
nav.classList.toggle('active');
});
}
document.addEventListener('click', function(event) {
if (nav && !event.target.closest('nav') && !event.target.closest('.menu-toggle')) {
nav.classList.remove('active');
}
});
// =========================================================
const myAccountWrapper = document.getElementById('myAccountWrapper');
const accountDropdown = document.getElementById('accountDropdown');
const toggleAuthMode = document.getElementById('toggleAuthMode');
const formTitle = document.getElementById('formTitle');
const authSubmitBtn = document.getElementById('authSubmitBtn');
const switchText = document.getElementById('switchText');
// My Account click කරද්දී dropdown box එක toggle (open/close) වීම
if (myAccountWrapper && accountDropdown) {
myAccountWrapper.addEventListener('click', function(e) {
e.stopPropagation();
accountDropdown.classList.toggle('active');
});
}
if (accountDropdown) {
accountDropdown.addEventListener('click', function(e) {
e.stopPropagation();
});
}
document.addEventListener('click', function() {
if (accountDropdown && accountDropdown.classList.contains('active')) {
accountDropdown.classList.remove('active');
}
});
if (toggleAuthMode && accountDropdown) {
toggleAuthMode.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
accountDropdown.classList.toggle('register-mode');
if (accountDropdown.classList.contains('register-mode')) {
formTitle.textContent = "Create Account";
authSubmitBtn.textContent = "Register Now";
switchText.textContent = "Already have an account?";
toggleAuthMode.textContent = "Login";
} else {
formTitle.textContent = "Login";
authSubmitBtn.textContent = "Login Now";
switchText.textContent = "New user?";
toggleAuthMode.textContent = "Create Account";
}
});
}
const today = new Date().toISOString().split('T')[0];
const dateInput = document.getElementById('date');
if(dateInput) dateInput.min = today;
const reservationForm = document.getElementById('reservation-form');
if(reservationForm) {
reservationForm.addEventListener('submit', function(e) {
e.preventDefault();
alert('Thank you for your reservation!');
reservationForm.reset();
});
}
const deliveryOptions = document.querySelectorAll('.delivery-option');
deliveryOptions.forEach(option => {
option.addEventListener('click', function() {
deliveryOptions.forEach(opt => opt.classList.remove('selected'));
this.classList.add('selected');
});
});
const paymentMethods = document.querySelectorAll('.payment-method');
paymentMethods.forEach(method => {
method.addEventListener('click', function() {
paymentMethods.forEach(m => m.classList.remove('selected'));
this.classList.add('selected');
});
});
const quantityBtns = document.querySelectorAll('.quantity-btn');
quantityBtns.forEach(btn => {
btn.addEventListener('click', function() {
const display = this.parentElement.querySelector('.quantity-display');
let quantity = parseInt(display.textContent);
if (this.textContent === '+') quantity++;
else if (this.textContent === '-' && quantity > 1) quantity--;
display.textContent = quantity;
});
});
const removeBtns = document.querySelectorAll('.remove-btn');
removeBtns.forEach(btn => {
btn.addEventListener('click', function() {
this.closest('.cart-item').remove();
});
});
const checkoutBtn = document.querySelector('.checkout-btn');
if(checkoutBtn) {
checkoutBtn.addEventListener('click', function() {
alert('Thank you for your order!');
});
}
const contactForm = document.getElementById('contact-form');
if(contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
alert('Thank you for your message!');
contactForm.reset();
});
}
});