-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripts.js
260 lines (223 loc) · 9.65 KB
/
scripts.js
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
if (hamburger && navLinks) {
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navLinks.classList.toggle('active');
});
}
// Advanced Search Toggle
const advancedSearchToggle = document.getElementById('advancedSearchToggle');
const advancedSearchOptions = document.getElementById('advancedSearchOptions');
if (advancedSearchToggle && advancedSearchOptions) {
advancedSearchToggle.addEventListener('click', (e) => {
e.preventDefault();
advancedSearchOptions.classList.toggle('active');
const icon = advancedSearchToggle.querySelector('i');
icon.classList.toggle('fa-chevron-down');
icon.classList.toggle('fa-chevron-up');
});
}
// Password Strength Checker
function checkPasswordStrength(password) {
let strength = 0;
if (password.length >= 8) strength++;
if (password.match(/[a-z]+/)) strength++;
if (password.match(/[A-Z]+/)) strength++;
if (password.match(/[0-9]+/)) strength++;
if (password.match(/[!@#$%^&*(),.?":{}|<>]+/)) strength++;
return strength;
}
// Form Handling
const signupForm = document.getElementById('signupForm');
const signinForm = document.getElementById('signinForm');
const propertyForm = document.getElementById('propertyForm');
const passwordInput = document.getElementById('password');
const passwordStrength = document.getElementById('passwordStrength');
if (passwordInput && passwordStrength) {
passwordInput.addEventListener('input', (e) => {
const strength = checkPasswordStrength(e.target.value);
const strengthText = ['Very Weak', 'Weak', 'Medium', 'Strong', 'Very Strong'];
const strengthColor = ['#ff4d4d', '#ffa64d', '#ffff4d', '#4dff4d', '#4d4dff'];
if (e.target.value.length > 0) {
passwordStrength.style.display = 'block';
passwordStrength.style.backgroundColor = strengthColor[strength - 1];
passwordStrength.textContent = strengthText[strength - 1];
} else {
passwordStrength.style.display = 'none';
}
});
}
if (signupForm) {
signupForm.addEventListener('submit', (e) => {
e.preventDefault();
const formData = {
fullname: document.getElementById('fullname')?.value,
email: document.getElementById('email')?.value,
phone: document.getElementById('phone')?.value,
userType: document.getElementById('userType')?.value,
password: document.getElementById('password')?.value,
confirmPassword: document.getElementById('confirm-password')?.value
};
if (formData.password !== formData.confirmPassword) {
alert('Passwords do not match!');
return;
}
if (checkPasswordStrength(formData.password) < 3) {
alert('Please choose a stronger password!');
return;
}
// Here you would typically send this data to a server
console.log('Signup form submitted:', formData);
alert('Account created successfully!');
window.location.href = 'signin.html';
});
}
if (signinForm) {
signinForm.addEventListener('submit', (e) => {
e.preventDefault();
const formData = {
email: document.getElementById('email')?.value,
password: document.getElementById('password')?.value,
remember: document.getElementById('remember')?.checked
};
// Here you would typically send this data to a server
console.log('Signin form submitted:', formData);
alert('Signed in successfully!');
window.location.href = 'index.html';
});
}
// Property Form Handling
if (propertyForm) {
const imageUploadContainer = document.getElementById('imageUploadContainer');
const imagePreview = document.getElementById('imagePreview');
const imageInput = document.getElementById('images');
if (imageUploadContainer && imageInput && imagePreview) {
imageUploadContainer.addEventListener('click', () => {
imageInput.click();
});
imageInput.addEventListener('change', function(e) {
const files = Array.from(e.target.files);
imagePreview.innerHTML = '';
files.forEach(file => {
if (file.type.startsWith('image/')) {
const reader = new FileReader();
reader.onload = function(e) {
const img = document.createElement('img');
img.src = e.target.result;
img.classList.add('preview-image');
const wrapper = document.createElement('div');
wrapper.classList.add('image-preview-wrapper');
wrapper.appendChild(img);
imagePreview.appendChild(wrapper);
}
reader.readAsDataURL(file);
}
});
});
// Drag and Drop for Images
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
imageUploadContainer.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
imageUploadContainer.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
imageUploadContainer.addEventListener(eventName, unhighlight, false);
});
function highlight(e) {
imageUploadContainer.classList.add('highlight');
}
function unhighlight(e) {
imageUploadContainer.classList.remove('highlight');
}
imageUploadContainer.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
const dataTransfer = new DataTransfer();
Array.from(files).forEach(file => {
if (file.type.startsWith('image/')) {
dataTransfer.items.add(file);
}
});
imageInput.files = dataTransfer.files;
// Trigger change event to update preview
const event = new Event('change');
imageInput.dispatchEvent(event);
}
}
propertyForm.addEventListener('submit', (e) => {
e.preventDefault();
const amenities = Array.from(document.querySelectorAll('input[name="amenities"]:checked'))
.map(checkbox => checkbox.value);
const formData = {
title: document.getElementById('title')?.value,
type: document.getElementById('type')?.value,
purpose: document.getElementById('purpose')?.value,
city: document.getElementById('city')?.value,
area: document.getElementById('area')?.value,
address: document.getElementById('address')?.value,
price: document.getElementById('price')?.value,
priceType: document.getElementById('priceType')?.value,
bedrooms: document.getElementById('bedrooms')?.value,
bathrooms: document.getElementById('bathrooms')?.value,
totalArea: document.getElementById('area')?.value,
amenities: amenities,
description: document.getElementById('description')?.value,
images: imageInput?.files
};
// Here you would typically send this data to a server
console.log('Property form submitted:', formData);
alert('Property listed successfully!');
window.location.href = 'index.html';
});
}
// Property View Details Buttons
const viewDetailsButtons = document.querySelectorAll('.btn-view');
if (viewDetailsButtons) {
viewDetailsButtons.forEach(button => {
button.addEventListener('click', (e) => {
e.preventDefault();
const propertyCard = button.closest('.property-card');
const propertyTitle = propertyCard.querySelector('h3').textContent;
alert(`Viewing details for: ${propertyTitle}`);
// Here you would typically navigate to the property details page
});
});
}
// Search Functionality
const searchBtn = document.querySelector('.search-btn');
if (searchBtn) {
searchBtn.addEventListener('click', (e) => {
e.preventDefault();
const location = document.querySelector('.search-group input[type="text"]')?.value;
const propertyType = document.querySelector('.search-group select:first-of-type')?.value;
const purpose = document.querySelector('.search-group select:last-of-type')?.value;
// Here you would typically send this data to a server or filter results
console.log('Search parameters:', { location, propertyType, purpose });
alert('Searching properties...');
});
}
// Social Login Handlers
const googleBtn = document.querySelector('.social-btn.google');
const facebookBtn = document.querySelector('.social-btn.facebook');
if (googleBtn) {
googleBtn.addEventListener('click', () => {
// Implement Google OAuth login
console.log('Google login clicked');
alert('Google login integration coming soon!');
});
}
if (facebookBtn) {
facebookBtn.addEventListener('click', () => {
// Implement Facebook OAuth login
console.log('Facebook login clicked');
alert('Facebook login integration coming soon!');
});
}