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/**
* BINA AI - Accessible Website Scripts
* Enhanced with accessibility features and smooth interactions
*/
document.addEventListener('DOMContentLoaded', function() {
// Initialize all features
initSmoothScrolling();
initCardAnimations();
initAccessibilityFeatures();
initKeyboardNavigation();
enhanceTableAccessibility();
});
/**
* Smooth scrolling for anchor links
*/
function initSmoothScrolling() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
// Announce to screen readers
const announcement = `Navigating to ${target.querySelector('h2, h3, h4, h5, h6')?.textContent || 'section'}`;
announceToScreenReader(announcement);
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
// Set focus to target for keyboard users
target.setAttribute('tabindex', '-1');
target.focus();
// Remove tabindex after focus
setTimeout(() => {
target.removeAttribute('tabindex');
}, 1000);
}
});
});
}
/**
* Card animations with intersection observer
*/
function initCardAnimations() {
// Check if user prefers reduced motion
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (prefersReducedMotion) {
return; // Skip animations if user prefers reduced motion
}
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
// Add a slight delay for staggered animation
const delay = Array.from(entry.target.parentNode.children).indexOf(entry.target) * 100;
entry.target.style.transitionDelay = `${delay}ms`;
// Unobserve after animation
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe benefit cards and other animated elements
document.querySelectorAll('.benefit-card, .links-section').forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(card);
});
}
/**
* Enhanced accessibility features
*/
function initAccessibilityFeatures() {
// Enhance table accessibility
enhanceTableAccessibility();
// Add ARIA labels to interactive elements
enhanceARIALabels();
// Handle focus management
improveFocusManagement();
}
/**
* Enhance table accessibility and responsive features
*/
function enhanceTableAccessibility() {
const tableWrapper = document.querySelector('.table-wrapper');
const table = document.querySelector('.comparison-table');
if (tableWrapper && table) {
// Add ARIA attributes for accessibility
tableWrapper.setAttribute('role', 'region');
tableWrapper.setAttribute('aria-label', 'Tabel perbandingan fitur BINA AI');
tableWrapper.setAttribute('tabindex', '0');
// Add scroll indicators and keyboard support
tableWrapper.addEventListener('keydown', function(e) {
const scrollStep = 50;
if (e.key === 'ArrowLeft') {
e.preventDefault();
this.scrollLeft -= scrollStep;
} else if (e.key === 'ArrowRight') {
e.preventDefault();
this.scrollLeft += scrollStep;
} else if (e.key === 'Home') {
e.preventDefault();
this.scrollLeft = 0;
} else if (e.key === 'End') {
e.preventDefault();
this.scrollLeft = this.scrollWidth - this.clientWidth;
}
});
// Add visual feedback for scroll position
function updateScrollIndicator() {
const isAtStart = tableWrapper.scrollLeft === 0;
const isAtEnd = tableWrapper.scrollLeft >= (tableWrapper.scrollWidth - tableWrapper.clientWidth - 5);
tableWrapper.classList.toggle('scroll-start', isAtStart);
tableWrapper.classList.toggle('scroll-end', isAtEnd);
}
tableWrapper.addEventListener('scroll', updateScrollIndicator);
updateScrollIndicator(); // Initial check
// Add focus management for table cells
const tableCells = table.querySelectorAll('th, td');
tableCells.forEach(cell => {
cell.addEventListener('focus', function() {
// Ensure the focused cell is visible
const cellRect = this.getBoundingClientRect();
const wrapperRect = tableWrapper.getBoundingClientRect();
if (cellRect.left < wrapperRect.left) {
tableWrapper.scrollLeft -= (wrapperRect.left - cellRect.left + 10);
} else if (cellRect.right > wrapperRect.right) {
tableWrapper.scrollLeft += (cellRect.right - wrapperRect.right + 10);
}
});
});
}
}
/**
* Add screen reader only class for captions
*/
function addScreenReaderOnlyStyles() {
const style = document.createElement('style');
style.textContent = `
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
`;
document.head.appendChild(style);
}
/**
* Enhance ARIA labels
*/
function enhanceARIALabels() {
// Add ARIA labels to benefit cards
document.querySelectorAll('.benefit-card').forEach((card, index) => {
const title = card.querySelector('h4')?.textContent;
if (title) {
card.setAttribute('aria-labelledby', `benefit-title-${index}`);
card.querySelector('h4').id = `benefit-title-${index}`;
}
});
// Enhance video container
const videoContainer = document.querySelector('.video-container');
if (videoContainer) {
videoContainer.setAttribute('role', 'region');
videoContainer.setAttribute('aria-label', 'BINA AI demonstration video');
}
// Add landmarks
const header = document.querySelector('header');
if (header) {
header.setAttribute('role', 'banner');
}
const footer = document.querySelector('footer');
if (footer) {
footer.setAttribute('role', 'contentinfo');
}
}
/**
* Improve focus management
*/
function improveFocusManagement() {
// Enhance focus indicators for custom elements
document.querySelectorAll('.benefit-card, .cta-button').forEach(element => {
element.addEventListener('focus', function() {
this.setAttribute('data-focused', 'true');
});
element.addEventListener('blur', function() {
this.removeAttribute('data-focused');
});
});
// Add focus styles
const focusStyle = document.createElement('style');
focusStyle.textContent = `
[data-focused="true"] {
outline: 3px solid var(--color-primary);
outline-offset: 2px;
}
`;
document.head.appendChild(focusStyle);
}
/**
* Enhanced keyboard navigation
*/
function initKeyboardNavigation() {
// Add keyboard navigation for cards
document.querySelectorAll('.benefit-card').forEach(card => {
// Make cards focusable
card.setAttribute('tabindex', '0');
// Add keyboard interaction
card.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
// Find any link within the card and activate it
const link = this.querySelector('a');
if (link) {
link.click();
} else {
// Announce card content to screen reader
const title = this.querySelector('h4')?.textContent;
const description = this.querySelector('p')?.textContent;
if (title && description) {
announceToScreenReader(`${title}: ${description}`);
}
}
}
});
});
// Escape key to return to top
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
const skipLink = document.querySelector('.skip-link');
if (skipLink) {
skipLink.focus();
announceToScreenReader('Returned to top of page');
}
}
});
}
/**
* Announce messages to screen readers
*/
function announceToScreenReader(message) {
const announcement = document.createElement('div');
announcement.setAttribute('aria-live', 'polite');
announcement.setAttribute('aria-atomic', 'true');
announcement.className = 'sr-only';
announcement.textContent = message;
document.body.appendChild(announcement);
// Remove after announcement
setTimeout(() => {
document.body.removeChild(announcement);
}, 1000);
}
/**
* Handle responsive behavior
*/
function handleResponsiveFeatures() {
// Add mobile-specific enhancements
if (window.innerWidth <= 768) {
// Improve touch targets
document.querySelectorAll('.cta-button, .benefit-card').forEach(element => {
element.style.minHeight = '44px'; // WCAG touch target minimum
});
}
}
/**
* Initialize when DOM is ready
*/
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
addScreenReaderOnlyStyles();
handleResponsiveFeatures();
});
} else {
addScreenReaderOnlyStyles();
handleResponsiveFeatures();
}
// Handle window resize
window.addEventListener('resize', handleResponsiveFeatures);