-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscroll-restriction.js
More file actions
135 lines (111 loc) · 4.62 KB
/
scroll-restriction.js
File metadata and controls
135 lines (111 loc) · 4.62 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
document.addEventListener('DOMContentLoaded', function () {
// Get reference to the locomotive scroll instance
const locoScroll = window.locoScroll;
if (!locoScroll) {
console.warn('⚠️ LocomotiveScroll instance not found. Scroll fixes not applied.');
return;
}
// Fix for navigation scrolling issue
function fixNavigationScrolling() {
// Ensure navigation links use locoScroll for smooth scrolling
document.querySelectorAll('#nav a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const targetId = this.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement && locoScroll) {
e.preventDefault();
// Use locoScroll to scroll to the target while maintaining scrollability
locoScroll.scrollTo(targetElement);
}
});
});
}
// Fix for footer scrolling issue
function fixFooterScrolling() {
const footer = document.getElementById('page5');
const formSection = document.getElementById('page4');
if (!footer || !formSection) {
console.warn('⚠️ Required page sections not found for scroll fix.');
return;
}
// Ensure LocomotiveScroll correctly calculates scrollable area
function updateScrollableArea() {
// Force locomotive scroll to recalculate limits
locoScroll.update();
// Get the document height including all sections
const docHeight = document.body.scrollHeight;
// Set data attribute to help with scroll calculations
document.body.setAttribute('data-scroll-height', docHeight);
// Make sure the main container has proper height
const main = document.getElementById('main');
if (main) {
main.style.minHeight = docHeight + 'px';
}
}
// Update on form visibility change
function checkFormVisibility() {
const formContainer = document.getElementById('recruitment-form-container');
const authOverlay = document.getElementById('auth-overlay');
if (formContainer && authOverlay) {
setTimeout(updateScrollableArea, 300); // Delay to allow DOM updates
}
}
// Initial update
updateScrollableArea();
// Listen for form visibility changes
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.attributeName === 'style') {
checkFormVisibility();
}
});
});
const formContainer = document.getElementById('recruitment-form-container');
const authOverlay = document.getElementById('auth-overlay');
if (formContainer) {
observer.observe(formContainer, { attributes: true });
}
if (authOverlay) {
observer.observe(authOverlay, { attributes: true });
}
// Listen for window resize to update scrollable area
window.addEventListener('resize', updateScrollableArea);
// Fix for users who are stuck in the footer area
footer.addEventListener('mousewheel', function (e) {
if (e.deltaY < 0) {
locoScroll.scrollTo(formSection);
}
});
// Alternative for touch devices
let touchStartY = 0;
footer.addEventListener('touchstart', function (e) {
touchStartY = e.touches[0].clientY;
}, { passive: true });
footer.addEventListener('touchmove', function (e) {
const touchY = e.touches[0].clientY;
const deltaY = touchY - touchStartY;
if (deltaY > 30) {
locoScroll.scrollTo(formSection);
}
}, { passive: true });
}
// Initialize the fix
fixFooterScrolling();
fixNavigationScrolling();
// Update locomotive scroll on auth state change
window.addEventListener('firebaseLoaded', function () {
window.firebase.onAuthStateChanged(window.firebase.auth, function () {
setTimeout(function () {
if (window.locoScroll) {
window.locoScroll.update();
}
}, 500);
});
});
// Add a global method to force scroll update
window.updatePageScroll = function () {
if (window.locoScroll) {
window.locoScroll.update();
}
};
});