-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
293 lines (260 loc) · 11.4 KB
/
script.js
File metadata and controls
293 lines (260 loc) · 11.4 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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* ===================================================================
MASTER DATA ("Dictionary")
!!! YEH ARRAY AB 'data.js' MEIN HAI !!!
!!! IS FILE SE 'allTutors' ARRAY KO DELETE KAR DEIN !!!
=================================================================== */
// const allTutors = [ ... ] <-- Yahaan se poora array DELETE KAREIN
/* ===================================================================
2. MAIN SCRIPT LOGIC
(Yeh same rahega)
=================================================================== */
document.addEventListener("DOMContentLoaded", () => {
// Check karein ki 'data.js' load hui hai ya nahi
if (typeof allTutors === 'undefined') {
console.error("ERROR: data.js file load nahi hui hai.");
return;
}
// --- Page-Specific Logic ---
if (document.getElementById("tutorCardContainer")) {
renderHomepageTutors();
initStatsCounter();
initReviewsSlider();
}
if (document.getElementById("teachersListContainer")) {
renderSearchPageTutors();
}
});
/* ===================================================================
3. RENDERING FUNCTIONS (HTML banane wale functions)
=================================================================== */
/**
* --- UPDATED: Homepage (index.html) ke liye Tutors Render karta hai ---
* Ab yeh poore card ko ek link banata hai
*/
function renderHomepageTutors() {
const container = document.getElementById("tutorCardContainer");
if (!container) return;
const homeTutors = allTutors.slice(0, 12);
container.innerHTML = homeTutors.map(tutor => `
<a href="teacher_profile.html?id=${tutor.id}" class="tutor-link">
<div class="card">
<img src="${tutor.img}" alt="${tutor.name}" />
<h3>${tutor.name}</h3>
<p>${tutor.subjects.join(' & ')} - ${tutor.experience} Years Experience</p>
<p><span class="location">🏠 ${tutor.location}</span></p>
<div class="card-header">
<span class="star-badge">★ ${tutor.rating.toFixed(1)}</span>
${tutor.isPopular ? '<span class="popular-tag">🔥 Popular</span>' : ''}
</div>
<div class="feedbacks">${tutor.reviews} feedbacks</div>
</div>
</a>
`).join('');
}
/**
* Teacher Search Page (search_teachers.html) ke liye cards Render karta hai
* (Yeh same rahega)
*/
function renderSearchPageTutors() {
const container = document.getElementById("teachersListContainer");
if (!container) return;
const initialTutors = allTutors.slice(0, 8);
container.innerHTML = initialTutors.map(tutor => createTeacherCardHTML(tutor)).join('');
const loadMoreBtn = document.getElementById('loadMoreTeachers');
const loadMoreContainer = document.getElementById('loadMoreContainer');
const moreTeachersContainer = document.getElementById('moreTeachersSection');
if (loadMoreBtn && moreTeachersContainer && loadMoreContainer) {
loadMoreBtn.addEventListener('click', function () {
const remainingTutors = allTutors.slice(8);
moreTeachersContainer.innerHTML = remainingTutors.map(tutor => createTeacherCardHTML(tutor)).join('');
moreTeachersContainer.style.display = "flex";
loadMoreContainer.style.display = 'none'; // Button ke container ko hide karein
moreTeachersContainer.scrollIntoView({ behavior: "smooth" });
});
}
}
/**
* --- UPDATED: search_teachers.html ke liye ek card ka HTML banata hai ---
* Ab yeh Teacher ke Naam ko link banata hai
* @param {object} tutor - Tutor object (allTutors array se)
* @returns {string} - HTML string
*/
/* ===================================================================
(Baaki saari file same rahegi)
...
=================================================================== */
/**
* --- UPDATED: search_teachers.html ke liye ek card ka HTML banata hai ---
* Ab yeh Teacher ke Naam aur Image dono ko link banata hai
* @param {object} tutor - Tutor object (allTutors array se)
* @returns {string} - HTML string
*/
function createTeacherCardHTML(tutor) {
return `
<div class="teacher-card">
<div class="teacher-img">
<a href="teacher_profile.html?id=${tutor.id}" class="profile-link-img">
<img src="${tutor.img}" alt="${tutor.name}">
</a>
</div>
<div class="teacher-info">
<div class="teacher-header">
<span class="teacher-icon">${tutor.genderIcon}</span>
<a href="teacher_profile.html?id=${tutor.id}" class="profile-link">
<span class="teacher-name">${tutor.name}</span>
</a>
<span class="teacher-rating">
<span class="star-badge">★ ${tutor.rating.toFixed(1)}</span>
<span class="rating-count">${tutor.reviews} Ratings</span>
</span>
${tutor.isPopular ? '<span class="teacher-popular">🔥 Popular</span>' : ''}
</div>
<div class="teacher-location">🏠 ${tutor.location}</div>
<div class="teacher-tags">
${tutor.subjects.map(sub => `<span class="tag subject">${sub}</span>`).join('')}
<span class="tag exp">${tutor.experience} Years Experience</span>
</div>
<div class="teacher-desc">
${tutor.bio.substring(0, 100)}... </div>
<div class="teacher-actions">
<button class="btn call-btn">📞 Show Number</button>
<button class="btn whatsapp-btn">🟢 WhatsApp</button>
<button class="btn enquiry-btn">💬 Send Enquiry</button>
</div>
</div>
</div>
`;
}
/* ===================================================================
(Baaki saari file same rahegi)
...
=================================================================== */
/* ===================================================================
4. UTILITY FUNCTIONS (UPDATED SEARCH FUNCTION)
(Yeh poora section same rahega jaisa pichli baar banaya tha)
=================================================================== */
function searchTutors() {
const locationInput = document.getElementById('location');
const subjectInput = document.getElementById('subject');
const location = locationInput.value.toLowerCase();
const subject = subjectInput.value.toLowerCase();
const container = document.getElementById('teachersListContainer');
if (container) {
// --- LOGIC FOR SEARCH_TEACHERS.HTML PAGE ---
const filteredTutors = allTutors.filter(tutor => {
const locationMatch = location ? tutor.location.toLowerCase().includes(location) : true;
const subjectsString = tutor.subjects.join(' ').toLowerCase();
const subjectMatch = subject ? subjectsString.includes(subject) : true;
return locationMatch && subjectMatch;
});
if (filteredTutors.length > 0) {
container.innerHTML = filteredTutors.map(tutor => createTeacherCardHTML(tutor)).join('');
} else {
container.innerHTML = `<h3 style="text-align:center; color:#555; margin: 40px 0;">No tutors found matching your criteria.</h3>`;
}
const loadMoreContainer = document.getElementById('loadMoreContainer');
const moreTeachersContainer = document.getElementById('moreTeachersSection');
if (loadMoreContainer) loadMoreContainer.style.display = 'none';
if (moreTeachersContainer) moreTeachersContainer.style.display = 'none';
} else {
// --- FALLBACK LOGIC FOR INDEX.HTML PAGE ---
alert(`Searching tutors in "${locationInput.value}" for subject "${subjectInput.value}"`);
}
}
window.searchTutors = searchTutors;
// --- Stats Counter (index.html ke liye) ---
// (Yeh poora function same rahega)
function initStatsCounter() {
const counters = document.querySelectorAll(".stat-number");
const duration = 4000;
counters.forEach((counter) => {
const target = +counter.getAttribute("data-target");
let start = 0;
let step = Math.ceil(target / (duration / 20));
if (step < 1) step = 1;
let current = 0;
function updateCounter() {
current += step;
if (current > target) current = target;
if (target >= 1000000) {
counter.textContent = Math.floor(current / 1000000) + " Million+";
} else if (target >= 1000) {
counter.textContent = Math.floor(current).toLocaleString() + "+";
} else {
counter.textContent = current + "+";
}
if (current < target) {
setTimeout(updateCounter, 20);
} else {
if (target >= 1000000) {
counter.textContent = Math.floor(target / 1000000) + " Million+";
} else if (target >= 1000) {
counter.textContent = target.toLocaleString() + "+";
} else {
counter.textContent = target + "+";
}
}
}
updateCounter();
});
}
// --- Reviews Slider (index.html ke liye) ---
// (Yeh poora function same rahega)
function initReviewsSlider() {
const slider = document.getElementById("reviewsSlider");
const leftBtn = document.getElementById("sliderLeftBtn");
const rightBtn = document.getElementById("sliderRightBtn");
if (!slider || !leftBtn || !rightBtn) return;
let cardWidth = slider.children[0].offsetWidth + 24;
let index = 0;
let isHovered = false;
for (let i = 0; i < 3; i++) {
slider.appendChild(slider.children[i].cloneNode(true));
}
function slideNext() {
if (isHovered) return;
index++;
slider.style.transition = "transform 0.7s cubic-bezier(.77,0,.18,1)";
slider.style.transform = `translateX(-${index * cardWidth}px)`;
if (index === slider.children.length - 3) {
setTimeout(() => {
slider.style.transition = "none";
slider.style.transform = "translateX(0)";
index = 0;
}, 700);
}
}
let sliderInterval = setInterval(slideNext, 2500);
slider.addEventListener("mouseenter", () => (isHovered = true));
slider.addEventListener("mouseleave", () => (isHovered = false));
leftBtn.addEventListener('click', () => {
if (index <= 0) return;
index--;
slider.style.transition = 'transform 0.7s cubic-bezier(.77,0,.18,1)';
slider.style.transform = `translateX(-${index * cardWidth}px)`;
});
rightBtn.addEventListener('click', () => {
slideNext();
});
window.addEventListener("resize", () => {
cardWidth = slider.children[0].offsetWidth + 24;
slider.style.transition = "none";
slider.style.transform = `translateX(-${index * cardWidth}px)`;
});
}
// --- Like/Comment (onclick dwara call kiya gaya) ---
// (Yeh functions same rahenge)
function likeReview(btn) {
let count = btn.querySelector(".like-count");
count.textContent = parseInt(count.textContent) + 1;
btn.classList.add("liked");
setTimeout(() => btn.classList.remove("liked"), 400);
}
function commentReview(btn) {
let count = btn.querySelector(".comment-count");
count.textContent = parseInt(count.textContent) + 1;
btn.classList.add("commented");
setTimeout(() => btn.classList.remove("commented"), 400);
}
window.likeReview = likeReview;
window.commentReview = commentReview;