-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
340 lines (299 loc) · 11.6 KB
/
Copy pathscript.js
File metadata and controls
340 lines (299 loc) · 11.6 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
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
function isDocumentScrollable() {
const scrollHeight = document.documentElement.scrollHeight;
const clientHeight = window.innerHeight;
if ((clientHeight / scrollHeight) >= 0.90) {
return false;
}
return scrollHeight > clientHeight + 20;
}
function updateScrollIndicator() {
const indicators = document.querySelectorAll('.scroll-indicator');
const scrollable = isDocumentScrollable();
const scrolled = window.scrollY > 40;
indicators.forEach(indicator => {
if (scrollable) {
indicator.style.display = 'flex';
indicator.style.opacity = scrolled ? '0' : '0.6';
} else {
indicator.style.display = 'none';
}
});
}
function onWindowScroll() {
if (!isDocumentScrollable()) {
document.querySelectorAll('.scroll-indicator').forEach(ind => ind.style.display = 'none');
return;
}
const scrolled = window.scrollY > 40;
document.querySelectorAll('.scroll-indicator').forEach(ind => {
if (ind.style.display !== 'none') {
ind.style.opacity = scrolled ? '0' : '0.6';
}
});
}
const VALID_PAGES = ['home', 'project', 'about', 'contact'];
function showPage(pageId, btnElement) {
if (!VALID_PAGES.includes(pageId)) pageId = 'home';
document.querySelectorAll('.page').forEach(p => p.classList.remove('active'));
document.querySelectorAll('.nav-link').forEach(b => b.classList.remove('active'));
const targetPage = document.getElementById(pageId);
if (targetPage) targetPage.classList.add('active');
let activeBtn = btnElement;
if (!activeBtn) {
const navLinks = document.querySelectorAll('.nav-link');
activeBtn = navLinks[VALID_PAGES.indexOf(pageId)] || navLinks[0];
}
if (activeBtn) activeBtn.classList.add('active');
if (location.hash.replace('#', '') !== pageId) {
history.pushState({ page: pageId }, '', '#' + pageId);
}
window.scrollTo(0, 0);
setTimeout(() => {
updateScrollIndicator();
}, 50);
}
function routeFromHash() {
const hash = location.hash.replace('#', '');
showPage(VALID_PAGES.includes(hash) ? hash : 'home');
}
document.addEventListener('DOMContentLoaded', routeFromHash);
window.addEventListener('popstate', routeFromHash);
function toggleDocModal(show, modalId) {
const modal = document.getElementById(modalId || 'docModal');
if (modal) {
modal.style.display = show ? 'block' : 'none';
if (show) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
}
}
function toggleCookiePolicyModal(show) {
const modal = document.getElementById('cookiePolicyModal');
if (modal) {
modal.style.display = show ? 'block' : 'none';
document.body.style.overflow = show ? 'hidden' : '';
}
}
function checkCookieConsent() {
const consent = localStorage.getItem('cookie_consent');
if (!consent) {
setTimeout(() => {
const banner = document.getElementById('cookieConsentBanner');
if (banner) banner.style.display = 'block';
}, 1500);
}
}
function acceptCookies() {
localStorage.setItem('cookie_consent', 'accepted');
const banner = document.getElementById('cookieConsentBanner');
if (banner) banner.style.display = 'none';
}
function denyCookies() {
localStorage.setItem('cookie_consent', 'denied');
const banner = document.getElementById('cookieConsentBanner');
if (banner) banner.style.display = 'none';
}
emailjs.init({ publicKey: 'NtcEzquyod-S_wNtp' });
const EMAILJS_SERVICE_ID = 'service_6owwois';
const EMAILJS_TEMPLATE_ID = 'template_xka8ozt';
const CONTACT_EMAIL = 'iankipngetich123@gmail.com';
let lastSubmitAt = 0;
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
function submitForm() {
const hp = document.getElementById('f-hp');
if (hp && hp.value.trim() !== '') {
return;
}
const now = Date.now();
if (now - lastSubmitAt < 15000) {
showAlert('Please wait a few seconds before sending another message.', 'RATE_LIMITED');
return;
}
const fname = document.getElementById('f-fname').value.trim().slice(0, 80);
const lname = document.getElementById('f-lname').value.trim().slice(0, 80);
const sal = document.getElementById('f-sal').value.trim();
const email = document.getElementById('f-email').value.trim().slice(0, 120);
const company = document.getElementById('f-company').value.trim().slice(0, 120);
const mobile = document.getElementById('f-mobile').value.trim().slice(0, 30);
const msg = document.getElementById('f-msg').value.trim().slice(0, 4000);
if (!fname || !email || !msg) {
showAlert('Please fill in Name, Email and Message Payload.', 'INPUT_REQUIRED');
return;
}
if (!EMAIL_PATTERN.test(email)) {
showAlert('Please enter a valid email address.', 'INVALID_EMAIL');
return;
}
if (EMAILJS_SERVICE_ID === 'YOUR_SERVICE_ID' || EMAILJS_TEMPLATE_ID === 'YOUR_TEMPLATE_ID') {
showAlert('EmailJS is not fully configured yet — Service ID / Template ID are missing.', 'CONFIG_INCOMPLETE');
return;
}
const submitBtn = document.querySelector('.form-submit');
const originalBtnHtml = submitBtn ? submitBtn.innerHTML : '';
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.style.opacity = '0.6';
submitBtn.innerHTML = '<i class="ti ti-loader-2 spin-anim"></i> TRANSMITTING...';
}
const templateParams = {
salutation: sal,
first_name: fname,
last_name: lname,
from_name: `${sal} ${fname} ${lname}`.trim(),
from_email: email,
reply_to: email,
company: company || 'N/A',
mobile: mobile || 'N/A',
message: msg,
to_email: CONTACT_EMAIL
};
emailjs.send(EMAILJS_SERVICE_ID, EMAILJS_TEMPLATE_ID, templateParams).then(
() => {
lastSubmitAt = Date.now();
const successDiv = document.getElementById('success-msg');
if (successDiv) {
successDiv.style.display = 'block';
setTimeout(() => { successDiv.style.display = 'none'; }, 6000);
}
['f-fname', 'f-lname', 'f-sal', 'f-email', 'f-company', 'f-mobile', 'f-msg', 'f-hp'].forEach(id => {
const el = document.getElementById(id);
if (el) { if (el.tagName === 'SELECT') el.selectedIndex = 0; else el.value = ''; }
});
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.style.opacity = '';
submitBtn.innerHTML = originalBtnHtml;
}
},
(err) => {
showAlert('Transmission failed — the message could not be sent. Please try again shortly.', 'TRANSMIT_ERROR');
console.error('EmailJS error:', err);
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.style.opacity = '';
submitBtn.innerHTML = originalBtnHtml;
}
}
);
}
function showAlert(message, title) {
const overlay = document.getElementById('hudAlertOverlay');
const titleEl = document.getElementById('hudAlertTitle');
const msgEl = document.getElementById('hudAlertMsg');
if (titleEl) titleEl.textContent = title || 'SYSTEM_NOTICE';
if (msgEl) msgEl.textContent = message;
if (overlay) {
overlay.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
}
function closeAlert() {
const overlay = document.getElementById('hudAlertOverlay');
if (overlay) overlay.style.display = 'none';
document.body.style.overflow = '';
}
const mediaGalleries = {
mpesa: {
title: 'M-Pesa Forensic Audit',
assets: [
{ label: '[ UI_PREVIEW_01 ]', desc: 'Main desktop dashboard interface — tactical HUD layout.', img: 'assets/1.png' },
{ label: '[ METRIC_CHART_02 ]', desc: 'Risk visualization — radar sonar chart and category breakdowns.', img: 'assets/2.png' },
{ label: '[ LOG_STREAM_03 ]', desc: 'Live transaction ledger reconstruction and log stream.', img: 'assets/3.png' },
{ label: '[ AML_FLAGS_04 ]', desc: 'AML pattern detection panel — structuring & rapid transit flags.', img: 'assets/4.png' },
{ label: '[ REPORT_EXPORT_05 ]', desc: 'Compiled forensic report export and credit decision summary.', img: 'assets/5.png' },
{ label: '[ MEDIA_06 ]', desc: 'Additional forensic audit interface capture.', img: 'assets/6.png' },
{ label: '[ MEDIA_07 ]', desc: 'Additional forensic audit interface capture.', img: 'assets/7.png' }
]
},
cosyspec: {
title: 'CosySpecBot // Telegram AI',
assets: [
{ label: '[ BOT_LOGO ]', desc: 'CosySpecBot brand mark / logo.', img: 'assets/cosyspec-logo.png' },
{ label: '[ CHAT_PREVIEW ]', desc: 'Live in-chat conversation preview on Telegram.', img: 'assets/cosyspec-chat.png' }
]
}
};
let currentGallery = 'mpesa';
let currentMediaIndex = 0;
function renderMedia() {
const gallery = mediaGalleries[currentGallery];
const assets = gallery.assets;
const asset = assets[currentMediaIndex];
const labelEl = document.getElementById('mediaLabel');
const descEl = document.getElementById('mediaDesc');
if (labelEl) labelEl.textContent = asset.label;
if (descEl) descEl.textContent = asset.desc;
document.getElementById('mediaCount').textContent = `${currentMediaIndex + 1} / ${assets.length}`;
document.getElementById('mediaModalTitle').textContent = `Project Media — Asset ${currentMediaIndex + 1}`;
const subEl = document.getElementById('mediaModalSub');
if (subEl) subEl.textContent = `${gallery.title} // Media Overlay Viewer`;
const imgEl = document.getElementById('mediaImage');
const iconEl = document.getElementById('mediaIcon');
if (imgEl) {
imgEl.src = asset.img;
imgEl.style.display = 'block';
}
if (iconEl) iconEl.style.display = 'none';
}
function openMediaModal(idx, galleryKey) {
currentGallery = (galleryKey && mediaGalleries[galleryKey]) ? galleryKey : 'mpesa';
currentMediaIndex = idx;
renderMedia();
const modal = document.getElementById('mediaModal');
if (modal) {
modal.style.display = 'block';
document.body.style.overflow = 'hidden';
}
}
function toggleMediaModal(show) {
const modal = document.getElementById('mediaModal');
if (modal) {
modal.style.display = show ? 'block' : 'none';
document.body.style.overflow = show ? 'hidden' : '';
}
}
function navMedia(dir) {
const assets = mediaGalleries[currentGallery].assets;
currentMediaIndex = (currentMediaIndex + dir + assets.length) % assets.length;
renderMedia();
}
function toggleAboutPhotoModal(show) {
const modal = document.getElementById('aboutPhotoModal');
if (modal) {
modal.style.display = show ? 'block' : 'none';
document.body.style.overflow = show ? 'hidden' : '';
}
}
window.addEventListener('scroll', onWindowScroll);
window.addEventListener('resize', () => {
updateScrollIndicator();
});
window.addEventListener('click', (e) => {
const docModal = document.getElementById('docModal');
if (e.target === docModal) toggleDocModal(false, 'docModal');
const docModalCosyspec = document.getElementById('docModalCosyspec');
if (e.target === docModalCosyspec) toggleDocModal(false, 'docModalCosyspec');
const mediaModal = document.getElementById('mediaModal');
if (e.target === mediaModal) toggleMediaModal(false);
const aboutPhotoModal = document.getElementById('aboutPhotoModal');
if (e.target === aboutPhotoModal) toggleAboutPhotoModal(false);
const cookiePolicyModal = document.getElementById('cookiePolicyModal');
if (e.target === cookiePolicyModal) toggleCookiePolicyModal(false);
const hudAlertOverlay = document.getElementById('hudAlertOverlay');
if (e.target === hudAlertOverlay) closeAlert();
});
window.addEventListener('keydown', (e) => {
if (e.key !== 'Escape') return;
toggleDocModal(false, 'docModal');
toggleDocModal(false, 'docModalCosyspec');
toggleMediaModal(false);
toggleAboutPhotoModal(false);
toggleCookiePolicyModal(false);
closeAlert();
});
document.addEventListener('DOMContentLoaded', () => {
updateScrollIndicator();
checkCookieConsent();
});