-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
551 lines (343 loc) · 13.3 KB
/
script.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
// ***
console.log();
// ***
// image animation
// Reusable function
// Scrolling animation effect function
// imageElementClass: add you image class
// direction: should be "+" or "-" default if "+"
// speed: default is 15
// transition: dafault is 0s
// Usage example: scrollEffect("contactBg", "+", 15, "0.5s", 1);
function scrollEffect(imageElementClass, direction = "+", speed = 1.5, transition = "0s", start = 0, scale = 1, position = "0%") {
// get image element
let image = document.querySelector(`.${imageElementClass}`);
if (!(image == null)) {
// get rectgetClientRects
let rect = image.getBoundingClientRect();
let rectHeight = rect.height / 2;
// set transition and scale
image.style.transition = transition;
image.style.transform = `scale(${scale})`;
if (image.classList.contains("scrollEffectImgHor") && image.classList.contains("scrollEffectImgVer")) {
alert("You can't use both of class effect in same time!");
} else if (image.classList.contains("scrollEffectImgVer")) {
window.addEventListener('scroll', _ => {
if (window.pageYOffset > start) {
let scrollCalc = (window.pageYOffset - start) / speed;
let finalScrollCalc = scrollCalc + rectHeight;
image.style.backgroundPositionY = `calc(${position} + ${direction}${finalScrollCalc}px)`;
};
});
} else if (image.classList.contains("scrollEffectImgHor")) {
image.style.backgroundPositionX = `${position}`;
window.addEventListener('scroll', _ => {
if (window.pageYOffset > start) {
let scrollCalc = (window.pageYOffset - start) / speed;
let finalScrollCalc = scrollCalc;
image.style.backgroundPositionX = `calc(${position} + ${direction}${finalScrollCalc}px)`;
};
});
} else if (!(image.classList.contains("scrollEffectImgHor") && image.classList.contains("scrollEffectImgVer"))) {
alert("Effect class not found, make sure you add him first then use the function!");
};
};
};
function clearText(element) {
element.innerHTML = element.textContent;
}
function selectBoxScript() {
const select = document.querySelector("div.select");
let isClicked = true;
if (select) {
const title = document.querySelector("div.select .bar .title");
const arrow = document.querySelector("div.select .bar .arrow");
const container = document.querySelector("div.select .container");
const opts = document.querySelectorAll("div.select .container span");
let value = document.querySelector("div.select .container span.selected").getAttribute("opt-value");
const containerRect = container.getBoundingClientRect();
const containerHeight = containerRect.height;
container.style.height = 0;
title.textContent = value;
select.addEventListener("click", _ => {
select.classList.toggle("clicked", isClicked);
if (isClicked) {
container.style.height = `${containerHeight}px`;
} else {
container.style.height = 0;
};
isClicked = !isClicked;
});
opts.forEach(opt => {
opt.addEventListener("click", _ => {
opts.forEach(opt => {opt.classList.remove("selected")});
opt.classList.add("selected");
value = opt.getAttribute("opt-value");
title.textContent = value;
});
});
};
};
selectBoxScript()
// ^Reusable function^
// FAQs section
class FAQ {
static this = [];
static node = [];
static idCount = 0;
constructor(tags, title, blog) {
this.id = FAQ.idCount++;
this.tags = tags;
this.title = title;
this.blog = blog;
FAQ.this.push(this);
// this.appendQ;
};
get appendQ() {
let qBox = document.querySelector(".questionsBox");
let q = document.createElement("button");
q.classList.add("q");
q.innerHTML =`
<div class="qTitle">
<h3>${this.title}</h3>
<span class="triggerIcon">^</span>
</div>
<div class="blog">
<p class="answer">${this.blog}</p>
<div class="links">
<a href="#" class="link"><i class="fa-brands fa-facebook"></i></a>
<a href="#" class="link"><i class="fa-brands fa-twitter"></i></a>
<a href="#" class="link"><i class="fa-brands fa-linkedin"></i></a>
<a href="#" class="link"><i class="fa-solid fa-link"></i></a>
</div>
</div>`;
if (!(qBox == null)) {
qBox.appendChild(q);
FAQ.node.push(q);
};
};
};
// ^FAQs section^
// Create question
let q1 = new FAQ(["general"], `What is an FAQ section?`, `An FAQ section can be used to quickly answer common questions about your business like "Where do you ship to?", "What are your opening hours?", or "How can I book a service?".`);
let q2 = new FAQ(["general"], `Why do FAQs matter?`, `FAQs are a great way to help site visitors find quick answers to common questions about your business and create a better navigation experience.`);
let q4 = new FAQ(["general"], `Where can I add my FAQs?`, `FAQs can be added to any page on your site or to your Wix mobile app, giving access to members on the go.`);
let q5 = new FAQ(["setting_up_FAQs"], `How do I add a new question & answer?`, `To add a new FAQ follow these steps:<br>1. Manage FAQs from your site dashboard or in the Editor<br>2. Add a new question & answer<br>3. Assign your FAQ to a category<br>4. Save and publish.<br><br>You can always come back and edit your FAQs.`);
let q6 = new FAQ(["setting_up_FAQs"], `Can I insert an image, video, or GIF in my FAQ?`, `Yes. To add media follow these steps:<br>1. Manage FAQs from your site dashboard or in the Editor<br>2. Create a new FAQ or edit an existing one<br>3. From the answer text box click on the video, image or GIF icon<br>4. Add media from your library and save.`);
let q7 = new FAQ(["setting_up_FAQs"], `How do I edit or remove the 'Frequently Asked Questions' title?`, `You can edit the title from the FAQ 'Settings' tab in the Editor.<br>To remove the title from your mobile app go to the 'Site & App' tab in your Owner's app and customize.`);
// ^Create question^
// FAQs filter and appenChild
let settings = document.querySelector(".settings");
let settingsBtn = document.querySelectorAll(".opt");
// default option
FAQ.this.forEach(q => {
if (q.tags.includes("setting_up_FAQs")) {
q.appendQ;
};
});
settingsBtn.forEach(settingsBtn => {
settingsBtn.addEventListener("click", _ => {
let qBox = document.querySelectorAll(".questionsBox .q");
let filterValue = settingsBtn.getAttribute("filter-value");
qBox.forEach(q => {q.remove();});
FAQ.this.forEach(q => {
if (q.tags.includes(filterValue)) {
q.appendQ;
} else if (filterValue == "all") {
q.appendQ;
};
});
qAnim();
});
});
// ^FAQs filter and appenChild^
// question animation
function qAnim() {
FAQ.node.forEach(q => {
let blog = q.children[1];
let links = q.children[1].children[1];
let arrow = q.children[0].children[1];
let blogHeight = blog.offsetHeight;
blog.style.height = "0";
q.addEventListener("click", _ => {
if (blog.style.height == "0px") {
FAQ.node.forEach(q => {
let blog = q.children[1];
let arrow = q.children[0].children[1];
blog.style.height = "0";
arrow.style.transform = "rotate(180deg) scaleX(1.5)";
blog.style.paddingTop = "0px";
links.style.paddingTop = "0px";
});
blog.style.height = `${blogHeight + 50}px`;
arrow.style.transform = "rotate(0deg) scaleX(1.5)";
blog.style.paddingTop = "30px";
links.style.paddingTop = "20px";
} else {
blog.style.height = "0";
arrow.style.transform = "rotate(180deg) scaleX(1.5)";
blog.style.paddingTop = "0px";
links.style.paddingTop = "0px";
};
});
});
settingsBtn.forEach(btn => {
btn.addEventListener("click", _ => {
settingsBtn.forEach(btn => {btn.classList.remove("selected");});
btn.classList.add("selected");
});
});
};
qAnim();
// ^question animation^
// search box animation
let searchIcon = document.querySelector(".faqs .container form i");
let toggle = true;
if (searchIcon !== null) {
let searchForm = document.querySelector(".faqs .container form");
let searchInput = document.querySelector(".faqs .container form input");
searchIcon.addEventListener("click", _ => {
if (toggle) {
searchForm.classList.add("selected");
searchInput.style.display = "unset";
searchIcon.style.transform = "translateX(0px)";
searchInput.focus();
toggle = !toggle;
} else {
searchForm.classList.remove("selected");
searchInput.style.display = "none";
searchIcon.style.transform = "translateX(20px)";
toggle = !toggle;
};
});
searchInput.addEventListener("blur", _ => {
if (toggle) {
searchForm.classList.add("selected");
searchInput.style.display = "unset";
searchIcon.style.transform = "translateX(0px)";
searchInput.focus();
toggle = !toggle;
} else {
searchForm.classList.remove("selected");
searchInput.style.display = "none";
searchIcon.style.transform = "translateX(20px)";
toggle = !toggle;
};
});
};
// ^search box animation^
// lazyLoadText
let boxs = document.querySelectorAll(".lazyLoadText");
let observer = new IntersectionObserver(entries => {
entries.forEach(box => {
// box.target.classList.toggle("slide", box.isIntersecting);
if (box.isIntersecting) {
box.target.classList.add("slide");
};
});
}, {rootMargin: "-100px"});
boxs.forEach(box => {
observer.observe(box);
});
// ^lazyLoadText^
// page on load anim
window.addEventListener("load", _ => {
document.body.classList.add("loaded");
});
// ^page on load anim^
// valid inputs
let inputs = document.querySelectorAll("input");
inputs.forEach(input => {
input.addEventListener("keyup", _ => {
if (!input.checkValidity()) {
input.style.borderColor = "#8e2627";
} else {
input.style.borderColor = "unset";
};
});
});
// ^valid inputs^
// menu
const mobileNav = document.querySelector(".mobileNav");
const menu = document.querySelector(".menu");
let menuIsHidden = true;
menu.addEventListener("click", _ => {
mobileNav.classList.toggle("slide", menuIsHidden);
if (menuIsHidden) {
menu.style.position = "fixed";
} else {
menu.style.position = "absolute"
};
menuIsHidden = !menuIsHidden;
});
// ^menu^
// Set page width attr
const detectWidth = new ResizeObserver((entries) => {
let rect = entries[0].contentRect;
let width = rect.width;
if (width < 768) {
let btn = document.querySelector("footer .purpleReversBigBtn");
let introFooter = document.querySelector(".introFooter");
let aboutDavoneDis = document.querySelector(".aboutDavon .top .sectionDis");
let resourceDis = document.querySelector(".resources .topSection .text .sectionDis");
let word = document.querySelector(".word .sectionWord");
let pageDis = document.querySelector(".pageTitle p.discription");
if (btn) {
btn.classList.remove("purpleReversBigBtn");
btn.classList.add("purpleReversSmallBtn");
};
if (introFooter) {
introFooter.classList.remove("verticalLine");
};
if (aboutDavoneDis) {
clearText(aboutDavoneDis);
};
if (resourceDis) {
clearText(resourceDis);
};
if (word) {
clearText(word);
};
if (pageDis) {
clearText(pageDis);
};
// scrollEffect("image class","moving direction +Or-", speed 10, "transition 0.5s", start position 1200, scale 1, "backgroundPosition 50%");
// Usage example: scrollEffect("contactBg", "+", 10, "0s", 1200, 1, "50%");
// Mobile View
scrollEffect("introdactionBg", "+", 10, "0s", 0, 1, "50%");
scrollEffect("aboutDavonBg", "+", 1.5, "0s", 1400);
scrollEffect("ourAcademicsBg", "+", 10, "0s", 2580, 1, "50%");
scrollEffect("wordBg", "+", 10, "0s", 4300, 1, "140%");
scrollEffect("rightSideBg", "+", 10, "0s", 0, 1, "50%");
scrollEffect("ourMissionBg", "+", 2, "0s");
scrollEffect("contactBg", "+", 15, "0s", 0, 1, "50%");
} else {
// Larg Monitor View
scrollEffect("introdactionBg", "+", 10, "0s", 0, 1.2, "0%");
scrollEffect("aboutDavonBg", "+", 1.5, "0s", 1400);
scrollEffect("ourAcademicsBg", "+", 10, "0s", 2580, 1.2);
scrollEffect("wordBg", "+", 10, "0s", 4300, 1, "100%");
scrollEffect("rightSideBg", "+", 10, "0s", 0, 1, "25%");
scrollEffect("ourMissionBg", "+", 2, "0s");
scrollEffect("contactBg", "+", 15, "0s", 0, 1, "50%");
};
});
detectWidth.observe(document.body);
// ^Set page width attr^
// resource seach bar
const resourceSearchIcont = document.querySelector(".resources .topbar form div i");
if (resourceSearchIcont) {
const resourceForm = document.querySelector(".resources .topbar form");
const resourceInput = document.querySelector(".resources .topbar form input");
const rect = resourceForm.getBoundingClientRect();
const formWidth = rect.width - 20;
let resourceIsClicked = true;
resourceSearchIcont.addEventListener("click", _ => {
resourceForm.classList.toggle("clicked", resourceIsClicked);
if (resourceIsClicked) {
resourceInput.style.width = `${formWidth}px`;
};
resourceIsClicked = !resourceIsClicked;
});
};
// ^resource seach bar^