-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartner-us.js
205 lines (160 loc) · 5.92 KB
/
partner-us.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
const cardWrapper = document.querySelector('.card-wrapper')
const cardWrapperChildren = Array.from(cardWrapper.children)
const widthToScroll = cardWrapper.children[0].offsetWidth
const arrowPrev = document.querySelector('.arrow.prev')
const arrowNext = document.querySelector('.arrow.next')
const cardBounding = cardWrapper.getBoundingClientRect()
const column = Math.floor(cardWrapper.offsetWidth / (widthToScroll + 24))
let currScroll = 0
let initPos = 0
let clicked = false
cardWrapperChildren.slice(-column).reverse().forEach(item=> {
cardWrapper.insertAdjacentHTML('afterbegin', item.outerHTML)
})
cardWrapperChildren.slice(0, column).forEach(item=> {
cardWrapper.insertAdjacentHTML('beforeend', item.outerHTML)
})
const cardImageAndLink = cardWrapper.querySelectorAll('img, a')
cardImageAndLink.forEach(item=> {
item.setAttribute('draggable', false)
})
cardWrapper.classList.add('no-smooth')
cardWrapper.scrollLeft = cardWrapper.offsetWidth
cardWrapper.classList.remove('no-smooth')
arrowPrev.onclick = function() {
cardWrapper.scrollLeft -= widthToScroll
}
arrowNext.onclick = function() {
cardWrapper.scrollLeft += widthToScroll
}
cardWrapper.onmousedown = function(e) {
cardWrapper.classList.add('grab')
initPos = e.clientX - cardBounding.left
currScroll = cardWrapper.scrollLeft
clicked = true
}
cardWrapper.onmousemove = function(e) {
if(clicked) {
const xPos = e.clientX - cardBounding.left
cardWrapper.scrollLeft = currScroll + -(xPos - initPos)
}
}
cardWrapper.onmouseup = mouseUpAndLeave
cardWrapper.onmouseleave = mouseUpAndLeave
function mouseUpAndLeave() {
cardWrapper.classList.remove('grab')
clicked = false
}
let autoScroll
cardWrapper.onscroll = function() {
if(cardWrapper.scrollLeft === 0) {
cardWrapper.classList.add('no-smooth')
cardWrapper.scrollLeft = cardWrapper.scrollWidth - (2 * cardWrapper.offsetWidth)
cardWrapper.classList.remove('no-smooth')
} else if(cardWrapper.scrollLeft === cardWrapper.scrollWidth - cardWrapper.offsetWidth) {
cardWrapper.classList.add('no-smooth')
cardWrapper.scrollLeft = cardWrapper.offsetWidth
cardWrapper.classList.remove('no-smooth')
}
if(autoScroll) {
clearTimeout(autoScroll)
}
autoScroll = setTimeout(()=> {
cardWrapper.classList.remove('no-smooth')
cardWrapper.scrollLeft += widthToScroll
}, 4000)
}
function goToPage(url) {
window.location.href = url;
}
//profile dropdown
// const profileHeader = document.getElementById('profile')
// profileHeader.addEventListener('click', function() {
// let displayHandling = document.getElementById('signLogin')
// if(displayHandling.style.display === 'none'){
// displayHandling.style.display = 'block'
// } else{
// displayHandling.style.display = 'none'
// }
// })
function toggleBtn(){
let displayHandling = document.getElementById('profile_List')
if(displayHandling.style.display === 'flex'){
displayHandling.style.display = 'none'
} else{
displayHandling.style.display = 'flex'
}
}
const form = document.querySelector('form[name="submit-to-google-sheet"]');
const inputs = form.querySelectorAll('input, textarea');
//const refNumber = localStorage.getItem('refNumber');
//if (refNumber) {
// const message = `Your previous registration reference number is ${refNumber}.`;
// alert(message);
// }
// Save data to local storage on form submission
form.addEventListener('submit', (event) => {
event.preventDefault(); // prevent default form submission
const submissions = JSON.parse(localStorage.getItem('submissions') || '[]');
const submission = {};
for (const input of inputs) {
submission[input.name] = input.value;
localStorage.setItem(input.name, input.value);
input.value = ''; // clear input field
}
submission.timestamp = Date.now();
// Generate and add reference number to submission object
const refNumber = Math.floor(Math.random() * 1000000); // generate random 6-digit number
submission.referenceNumber = refNumber;
submissions.push(submission);
localStorage.setItem('submissions', JSON.stringify(submissions));
// Generate and display application reference number
const message = `Your registration has been submitted. Your registration reference number is ${refNumber}. We will contact you within 24-48 hours.`;
alert(message);
form.reset(); // clear the form
});
// Clear old submissions from local storage after 48 hours
const CLEAR_TIMEOUT = 48 * 60 * 60 * 1000; // 48 hours in milliseconds
let lastInteractionTime = Date.now();
function clearLocalStorage() {
localStorage.removeItem('submissions');
for (const input of inputs) {
localStorage.removeItem(input.name);
}
}
function resetInteractionTime() {
lastInteractionTime = Date.now();
}
function checkInteractionTimeout() {
const elapsedTime = Date.now() - lastInteractionTime;
if (elapsedTime >= CLEAR_TIMEOUT) {
clearLocalStorage();
}
}
// Reset interaction time on any user input or window focus
window.addEventListener('focus', resetInteractionTime);
form.addEventListener('submit', resetInteractionTime);
for (const input of inputs) {
input.addEventListener('input', resetInteractionTime);
}
// Check for inactivity and clear local storage if needed
setInterval(checkInteractionTimeout, 60 * 1000); // Check every minute
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.querySelector("header").style.top = "0";
} else {
document.querySelector("header").style.top = "-7.2rem";
}
prevScrollpos = currentScrollPos;
}
const forms = document.querySelector('.newsLetterForm');
const emailInput = form.querySelector('input[type="email"]');
forms.addEventListener('submit', (event) => {
event.preventDefault();
const email = emailInput.value;
localStorage.setItem('newsletterEmail', email);
emailInput.value = '';
alert('You are now subscribed to our newsletter!');
});