2122 lines
68 KiB
JavaScript
2122 lines
68 KiB
JavaScript
/* ==========================================================================
|
|
AI INSTITUTE — MAIN.JS
|
|
Vanilla interactions only:
|
|
1. Sticky header state
|
|
2. Mobile navigation
|
|
3. Courses dropdown
|
|
4. Course filtering
|
|
5. FAQ accordion
|
|
6. Scroll reveal
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
var header = document.getElementById('site-header');
|
|
var nav = document.getElementById('primary-nav');
|
|
var navToggle = document.querySelector('.nav-toggle');
|
|
var dropdownItems = Array.prototype.slice.call(
|
|
document.querySelectorAll('.nav__item--dropdown')
|
|
);
|
|
|
|
/* ------------------------------------------------------------------
|
|
1. Sticky header state
|
|
------------------------------------------------------------------ */
|
|
function updateHeaderState() {
|
|
if (!header) {
|
|
return;
|
|
}
|
|
header.classList.toggle('is-scrolled', window.scrollY > 8);
|
|
}
|
|
|
|
updateHeaderState();
|
|
window.addEventListener('scroll', updateHeaderState, { passive: true });
|
|
|
|
/* ------------------------------------------------------------------
|
|
2. Mobile navigation
|
|
------------------------------------------------------------------ */
|
|
function setNavState(isOpen) {
|
|
if (!nav || !navToggle) {
|
|
return;
|
|
}
|
|
nav.classList.toggle('is-open', isOpen);
|
|
navToggle.classList.toggle('is-active', isOpen);
|
|
navToggle.setAttribute('aria-expanded', String(isOpen));
|
|
navToggle.setAttribute(
|
|
'aria-label',
|
|
isOpen ? 'Close navigation menu' : 'Open navigation menu'
|
|
);
|
|
document.body.classList.toggle('nav-open', isOpen);
|
|
|
|
if (!isOpen) {
|
|
closeDropdowns();
|
|
}
|
|
}
|
|
|
|
if (navToggle && nav) {
|
|
navToggle.addEventListener('click', function () {
|
|
setNavState(!nav.classList.contains('is-open'));
|
|
});
|
|
|
|
nav.querySelectorAll('a').forEach(function (link) {
|
|
link.addEventListener('click', function () {
|
|
if (window.innerWidth <= 980) {
|
|
setNavState(false);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------
|
|
3. Courses dropdown
|
|
------------------------------------------------------------------ */
|
|
function closeDropdowns(except) {
|
|
dropdownItems.forEach(function (item) {
|
|
if (item === except) {
|
|
return;
|
|
}
|
|
item.classList.remove('is-open');
|
|
var trigger = item.querySelector('.nav__dropdown-toggle');
|
|
if (trigger) {
|
|
trigger.setAttribute('aria-expanded', 'false');
|
|
}
|
|
});
|
|
}
|
|
|
|
dropdownItems.forEach(function (item) {
|
|
var trigger = item.querySelector('.nav__dropdown-toggle');
|
|
|
|
if (!trigger) {
|
|
return;
|
|
}
|
|
|
|
trigger.addEventListener('click', function (event) {
|
|
event.stopPropagation();
|
|
var willOpen = !item.classList.contains('is-open');
|
|
closeDropdowns(item);
|
|
item.classList.toggle('is-open', willOpen);
|
|
trigger.setAttribute('aria-expanded', String(willOpen));
|
|
});
|
|
|
|
item.querySelectorAll('.dropdown__link').forEach(function (link) {
|
|
link.addEventListener('click', function () {
|
|
item.classList.remove('is-open');
|
|
trigger.setAttribute('aria-expanded', 'false');
|
|
});
|
|
});
|
|
});
|
|
|
|
document.addEventListener('click', function (event) {
|
|
if (!event.target.closest('.nav__item--dropdown')) {
|
|
closeDropdowns();
|
|
}
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Escape') {
|
|
closeDropdowns();
|
|
setNavState(false);
|
|
}
|
|
});
|
|
|
|
window.addEventListener('resize', function () {
|
|
if (window.innerWidth > 980) {
|
|
setNavState(false);
|
|
}
|
|
});
|
|
|
|
/* ------------------------------------------------------------------
|
|
4. Course filtering
|
|
------------------------------------------------------------------ */
|
|
var filterButtons = Array.prototype.slice.call(
|
|
document.querySelectorAll('.filter-pill')
|
|
);
|
|
var courseCards = Array.prototype.slice.call(
|
|
document.querySelectorAll('.course-card')
|
|
);
|
|
|
|
filterButtons.forEach(function (button) {
|
|
button.addEventListener('click', function () {
|
|
var filter = button.getAttribute('data-filter');
|
|
|
|
filterButtons.forEach(function (pill) {
|
|
var isActive = pill === button;
|
|
pill.classList.toggle('is-active', isActive);
|
|
pill.setAttribute('aria-pressed', String(isActive));
|
|
});
|
|
|
|
courseCards.forEach(function (card) {
|
|
var category = card.getAttribute('data-category');
|
|
var shouldShow = filter === 'all' || category === filter;
|
|
card.classList.toggle('is-hidden', !shouldShow);
|
|
});
|
|
});
|
|
});
|
|
|
|
/* ------------------------------------------------------------------
|
|
5. FAQ accordion
|
|
------------------------------------------------------------------ */
|
|
var accordionItems = Array.prototype.slice.call(
|
|
document.querySelectorAll('.accordion__item')
|
|
);
|
|
|
|
accordionItems.forEach(function (item) {
|
|
var trigger = item.querySelector('.accordion__trigger');
|
|
|
|
if (!trigger) {
|
|
return;
|
|
}
|
|
|
|
trigger.addEventListener('click', function () {
|
|
var wasOpen = item.classList.contains('is-open');
|
|
|
|
accordionItems.forEach(function (other) {
|
|
other.classList.remove('is-open');
|
|
var otherTrigger = other.querySelector('.accordion__trigger');
|
|
if (otherTrigger) {
|
|
otherTrigger.setAttribute('aria-expanded', 'false');
|
|
}
|
|
});
|
|
|
|
if (!wasOpen) {
|
|
item.classList.add('is-open');
|
|
trigger.setAttribute('aria-expanded', 'true');
|
|
}
|
|
});
|
|
});
|
|
|
|
/* ------------------------------------------------------------------
|
|
6. Scroll reveal
|
|
------------------------------------------------------------------ */
|
|
var revealElements = Array.prototype.slice.call(
|
|
document.querySelectorAll('.reveal')
|
|
);
|
|
|
|
var prefersReducedMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
|
|
if (!revealElements.length) {
|
|
return;
|
|
}
|
|
|
|
if (prefersReducedMotion || !('IntersectionObserver' in window)) {
|
|
revealElements.forEach(function (element) {
|
|
element.classList.add('is-visible');
|
|
});
|
|
return;
|
|
}
|
|
|
|
var observer = new IntersectionObserver(
|
|
function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('is-visible');
|
|
observer.unobserve(entry.target);
|
|
}
|
|
});
|
|
},
|
|
{
|
|
threshold: 0.12,
|
|
rootMargin: '0px 0px -60px 0px'
|
|
}
|
|
);
|
|
|
|
revealElements.forEach(function (element) {
|
|
observer.observe(element);
|
|
});
|
|
});
|
|
})();
|
|
|
|
/* ==========================================================================
|
|
COURSE FILTER — ANIMATED ENHANCEMENT
|
|
Appended as an isolated IIFE so it cannot interfere with the code above.
|
|
It shares the existing .is-hidden / .is-visible state while adding the
|
|
fade + scale animation and the delayed display:none step.
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initAnimatedCourseFilter() {
|
|
var pills = Array.prototype.slice.call(
|
|
document.querySelectorAll('.filter-pill')
|
|
);
|
|
var cards = Array.prototype.slice.call(
|
|
document.querySelectorAll('#course-grid .course-card')
|
|
);
|
|
|
|
if (!pills.length || !cards.length) {
|
|
return;
|
|
}
|
|
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
var hideDelay = reduceMotion ? 0 : 300;
|
|
|
|
function clearTimer(card) {
|
|
if (card.__courseFilterTimer) {
|
|
window.clearTimeout(card.__courseFilterTimer);
|
|
card.__courseFilterTimer = null;
|
|
}
|
|
}
|
|
|
|
function showCard(card) {
|
|
clearTimer(card);
|
|
|
|
var wasHidden = card.classList.contains('is-hidden') ||
|
|
card.style.display === 'none';
|
|
|
|
card.style.display = '';
|
|
card.classList.remove('is-hidden');
|
|
|
|
if (wasHidden) {
|
|
card.classList.add('is-hidden');
|
|
void card.offsetWidth;
|
|
card.classList.remove('is-hidden');
|
|
}
|
|
|
|
card.classList.add('is-visible');
|
|
}
|
|
|
|
function hideCard(card) {
|
|
card.classList.remove('is-visible');
|
|
card.classList.add('is-hidden');
|
|
clearTimer(card);
|
|
|
|
card.__courseFilterTimer = window.setTimeout(function () {
|
|
card.style.display = 'none';
|
|
card.__courseFilterTimer = null;
|
|
}, hideDelay);
|
|
}
|
|
|
|
function setActivePill(activePill) {
|
|
pills.forEach(function (pill) {
|
|
var isActive = pill === activePill;
|
|
pill.classList.toggle('is-active', isActive);
|
|
pill.setAttribute('aria-pressed', String(isActive));
|
|
});
|
|
}
|
|
|
|
pills.forEach(function (pill) {
|
|
pill.addEventListener('click', function () {
|
|
var filter = pill.getAttribute('data-filter') || 'all';
|
|
|
|
setActivePill(pill);
|
|
|
|
cards.forEach(function (card) {
|
|
var category = card.getAttribute('data-category');
|
|
var shouldShow = filter === 'all' || category === filter;
|
|
|
|
if (shouldShow) {
|
|
showCard(card);
|
|
} else {
|
|
hideCard(card);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initAnimatedCourseFilter);
|
|
} else {
|
|
initAnimatedCourseFilter();
|
|
}
|
|
})();
|
|
|
|
/* ==========================================================================
|
|
HIRING PARTNERS — ENDLESS MARQUEE
|
|
Appended as an isolated IIFE so it cannot interfere with the code above.
|
|
The track holds an even number of identical sets, so translateX(-50%)
|
|
loops with no visible jump.
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initPartnerMarquee() {
|
|
var section = document.getElementById('partners');
|
|
if (!section) {
|
|
return;
|
|
}
|
|
|
|
var grid = section.querySelector('.partner-grid');
|
|
if (!grid) {
|
|
return;
|
|
}
|
|
|
|
if (grid.getAttribute('data-marquee-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
var originals = Array.prototype.slice.call(grid.children).filter(
|
|
function (child) {
|
|
return child.classList &&
|
|
child.classList.contains('partner-logo');
|
|
}
|
|
);
|
|
|
|
if (!originals.length) {
|
|
return;
|
|
}
|
|
|
|
grid.setAttribute('data-marquee-init', 'true');
|
|
|
|
var marquee = document.createElement('div');
|
|
marquee.className = 'partner-marquee';
|
|
grid.parentNode.insertBefore(marquee, grid);
|
|
marquee.appendChild(grid);
|
|
|
|
grid.setAttribute('role', 'list');
|
|
|
|
originals.forEach(function (logo) {
|
|
logo.setAttribute('role', 'listitem');
|
|
});
|
|
|
|
function addSet() {
|
|
originals.forEach(function (logo) {
|
|
var clone = logo.cloneNode(true);
|
|
clone.setAttribute('aria-hidden', 'true');
|
|
clone.removeAttribute('role');
|
|
clone.removeAttribute('data-marquee-init');
|
|
grid.appendChild(clone);
|
|
});
|
|
}
|
|
|
|
/* The first duplicate gives the two identical sets required by the
|
|
translateX(-50%) loop. */
|
|
addSet();
|
|
var sets = 2;
|
|
|
|
function getGap() {
|
|
var styles = window.getComputedStyle(grid);
|
|
var gap = parseFloat(styles.columnGap || styles.gap);
|
|
return isNaN(gap) ? 18 : gap;
|
|
}
|
|
|
|
function getSetWidth(gap) {
|
|
var width = 0;
|
|
|
|
originals.forEach(function (logo, index) {
|
|
width += logo.getBoundingClientRect().width;
|
|
if (index < originals.length - 1) {
|
|
width += gap;
|
|
}
|
|
});
|
|
|
|
return width + gap;
|
|
}
|
|
|
|
var gap = getGap();
|
|
var setWidth = getSetWidth(gap);
|
|
var containerWidth = marquee.clientWidth || section.clientWidth;
|
|
|
|
while (
|
|
setWidth < containerWidth &&
|
|
sets * setWidth < containerWidth * 2
|
|
) {
|
|
addSet();
|
|
addSet();
|
|
sets += 2;
|
|
}
|
|
|
|
grid.classList.add('is-marquee');
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initPartnerMarquee);
|
|
} else {
|
|
initPartnerMarquee();
|
|
}
|
|
})();
|
|
|
|
/* ==========================================================================
|
|
HERO SLIDER — TWO-SLIDE CROSSFADE WITH ZOOM
|
|
Appended as an isolated IIFE so it cannot interfere with the code above.
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
var HERO_SLIDES = [
|
|
'assets/img/heroimage.png',
|
|
'assets/img/heroimage2.jpg'
|
|
];
|
|
|
|
function initHeroSlider() {
|
|
var media = document.querySelector('.hero__media');
|
|
var wrap = document.querySelector('.hero__image-wrap');
|
|
|
|
if (!wrap) {
|
|
return;
|
|
}
|
|
|
|
if (wrap.getAttribute('data-hero-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
var firstImage = wrap.querySelector('.hero__image');
|
|
if (!firstImage) {
|
|
return;
|
|
}
|
|
|
|
wrap.setAttribute('data-hero-init', 'true');
|
|
|
|
if (HERO_SLIDES[0]) {
|
|
firstImage.src = HERO_SLIDES[0];
|
|
}
|
|
firstImage.classList.add('is-active');
|
|
|
|
var images = [firstImage];
|
|
|
|
if (HERO_SLIDES[1]) {
|
|
var secondImage = document.createElement('img');
|
|
secondImage.className = 'hero__image';
|
|
secondImage.src = HERO_SLIDES[1];
|
|
secondImage.alt = 'A dark desk with a monitor showing a glowing blue and purple screen';
|
|
secondImage.width = 1000;
|
|
secondImage.height = 1200;
|
|
secondImage.loading = 'lazy';
|
|
wrap.appendChild(secondImage);
|
|
images.push(secondImage);
|
|
}
|
|
|
|
/* Floating card copy */
|
|
if (media) {
|
|
var floatCard = media.querySelector('.hero__float');
|
|
var floatCopy = floatCard
|
|
? floatCard.querySelector('span:not(.hero__float-icon)')
|
|
: null;
|
|
|
|
if (floatCopy) {
|
|
floatCopy.className = 'hero__float-copy';
|
|
floatCopy.innerHTML = 'Ideas → real projects' +
|
|
'<small>Your next chapter starts here</small>';
|
|
}
|
|
}
|
|
|
|
/* Primary button arrow */
|
|
var primaryButton = document.querySelector('.hero .btn--primary');
|
|
|
|
if (primaryButton && !primaryButton.querySelector('.hero__arrow')) {
|
|
var arrow = document.createElement('span');
|
|
arrow.className = 'hero__arrow';
|
|
arrow.setAttribute('aria-hidden', 'true');
|
|
arrow.innerHTML = '<svg viewBox="0 0 24 24" fill="none" ' +
|
|
'stroke="currentColor" stroke-width="2" stroke-linecap="round" ' +
|
|
'stroke-linejoin="round" focusable="false">' +
|
|
'<path d="M7 17 17 7"/><path d="M7 7h10v10"/></svg>';
|
|
primaryButton.appendChild(arrow);
|
|
}
|
|
|
|
/* Slider dots */
|
|
var dots = document.createElement('div');
|
|
dots.className = 'hero__dots';
|
|
var dotButtons = [];
|
|
|
|
images.forEach(function (image, index) {
|
|
var dot = document.createElement('button');
|
|
dot.type = 'button';
|
|
dot.className = 'hero__dot' + (index === 0 ? ' is-active' : '');
|
|
dot.setAttribute('aria-label', 'Show slide ' + (index + 1));
|
|
dot.addEventListener('click', function () {
|
|
goTo(index);
|
|
restart();
|
|
});
|
|
dots.appendChild(dot);
|
|
dotButtons.push(dot);
|
|
});
|
|
|
|
wrap.appendChild(dots);
|
|
|
|
var current = 0;
|
|
var timer = null;
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
var AUTO_MS = 5000;
|
|
var LEAVE_MS = 1200;
|
|
|
|
function updateDots() {
|
|
dotButtons.forEach(function (dot, index) {
|
|
dot.classList.toggle('is-active', index === current);
|
|
});
|
|
}
|
|
|
|
function goTo(index) {
|
|
if (index === current) {
|
|
updateDots();
|
|
return;
|
|
}
|
|
|
|
var previous = images[current];
|
|
var next = images[index];
|
|
|
|
if (previous) {
|
|
previous.classList.remove('is-active');
|
|
previous.classList.add('is-leaving');
|
|
|
|
window.setTimeout(function () {
|
|
previous.classList.remove('is-leaving');
|
|
}, LEAVE_MS);
|
|
}
|
|
|
|
next.classList.remove('is-leaving');
|
|
next.classList.add('is-active');
|
|
|
|
current = index;
|
|
updateDots();
|
|
}
|
|
|
|
function stop() {
|
|
if (timer) {
|
|
window.clearInterval(timer);
|
|
timer = null;
|
|
}
|
|
}
|
|
|
|
function start() {
|
|
stop();
|
|
|
|
if (reduceMotion || document.hidden || images.length < 2) {
|
|
return;
|
|
}
|
|
|
|
timer = window.setInterval(function () {
|
|
goTo((current + 1) % images.length);
|
|
}, AUTO_MS);
|
|
}
|
|
|
|
function restart() {
|
|
start();
|
|
}
|
|
|
|
if (media) {
|
|
media.addEventListener('mouseenter', stop);
|
|
media.addEventListener('mouseleave', start);
|
|
}
|
|
|
|
document.addEventListener('visibilitychange', function () {
|
|
if (document.hidden) {
|
|
stop();
|
|
} else {
|
|
start();
|
|
}
|
|
});
|
|
|
|
start();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initHeroSlider);
|
|
} else {
|
|
initHeroSlider();
|
|
}
|
|
})();
|
|
|
|
/* ==========================================================================
|
|
FINAL CTA — EYEBROW, SPOTLIGHT, RIPPLE & SMOOTH SCROLL
|
|
Appended as an isolated IIFE so it cannot interfere with the code above.
|
|
It reuses the existing .reveal / .is-visible observer from main.js and
|
|
does not add a second scroll-reveal script.
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initCta() {
|
|
var section = document.querySelector('.cta');
|
|
|
|
if (!section) {
|
|
return;
|
|
}
|
|
|
|
if (section.getAttribute('data-cta-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
section.setAttribute('data-cta-init', 'true');
|
|
|
|
var title = section.querySelector('.cta__title');
|
|
var text = section.querySelector('.cta__text');
|
|
|
|
/* 1. Eyebrow + subtext */
|
|
if (title && !section.querySelector('.eyebrow')) {
|
|
var eyebrow = document.createElement('span');
|
|
eyebrow.className = 'eyebrow';
|
|
eyebrow.textContent = 'Your next chapter';
|
|
title.parentNode.insertBefore(eyebrow, title);
|
|
}
|
|
|
|
if (text) {
|
|
text.textContent = 'Start with curiosity. Build with purpose. ' +
|
|
'Find a learning path that connects your ambitions to ' +
|
|
'practical AI skills.';
|
|
}
|
|
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
var isTouch = window.matchMedia(
|
|
'(hover: none), (pointer: coarse)'
|
|
).matches;
|
|
|
|
/* 2. Cursor spotlight (desktop, motion allowed only) */
|
|
if (!reduceMotion && !isTouch) {
|
|
var spotlight = document.createElement('div');
|
|
spotlight.className = 'cta__spotlight';
|
|
spotlight.setAttribute('aria-hidden', 'true');
|
|
section.appendChild(spotlight);
|
|
|
|
section.addEventListener('mousemove', function (event) {
|
|
var rect = section.getBoundingClientRect();
|
|
var size = spotlight.offsetWidth || 300;
|
|
|
|
spotlight.style.left =
|
|
(event.clientX - rect.left - size / 2) + 'px';
|
|
spotlight.style.top =
|
|
(event.clientY - rect.top - size / 2) + 'px';
|
|
});
|
|
|
|
section.addEventListener('mouseenter', function () {
|
|
spotlight.classList.add('is-visible');
|
|
});
|
|
|
|
section.addEventListener('mouseleave', function () {
|
|
spotlight.classList.remove('is-visible');
|
|
});
|
|
}
|
|
|
|
/* 3. Ripple + smooth scroll */
|
|
var buttons = Array.prototype.slice.call(
|
|
section.querySelectorAll('.btn')
|
|
);
|
|
|
|
buttons.forEach(function (button) {
|
|
button.addEventListener('click', function (event) {
|
|
var rect = button.getBoundingClientRect();
|
|
var x = event.clientX
|
|
? event.clientX - rect.left
|
|
: rect.width / 2;
|
|
var y = event.clientY
|
|
? event.clientY - rect.top
|
|
: rect.height / 2;
|
|
|
|
var ripple = document.createElement('span');
|
|
ripple.className = 'btn-ripple';
|
|
ripple.style.left = x + 'px';
|
|
ripple.style.top = y + 'px';
|
|
button.appendChild(ripple);
|
|
|
|
window.setTimeout(function () {
|
|
if (ripple.parentNode) {
|
|
ripple.parentNode.removeChild(ripple);
|
|
}
|
|
}, 600);
|
|
|
|
var href = button.getAttribute('href') || '';
|
|
|
|
if (href.charAt(0) === '#' && href.length > 1) {
|
|
var target = document.getElementById(href.slice(1));
|
|
|
|
if (target) {
|
|
event.preventDefault();
|
|
target.scrollIntoView({
|
|
behavior: 'smooth',
|
|
block: 'start'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initCta);
|
|
} else {
|
|
initCta();
|
|
}
|
|
})();
|
|
|
|
/* ==========================================================================
|
|
HERO IMAGE SLIDER — DOM-BASED TWO-SLIDE CROSSFADE
|
|
Appended as an isolated IIFE so it cannot interfere with the code above.
|
|
Slide 1 is read from the existing .hero__image. Slide 2 uses a placeholder
|
|
that can later be replaced with an /assets/img/ file.
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
/* Slide 1 is filled from the DOM during init. */
|
|
const HERO_SLIDES = [
|
|
{ src: '', alt: '' },
|
|
{
|
|
/* Replace this with /assets/img/your-hero-2.jpg when ready. */
|
|
src: 'https://picsum.photos/seed/ai-institute-hero-2/1000/1200',
|
|
alt: 'A dark desk with a monitor showing a glowing blue and purple screen'
|
|
}
|
|
];
|
|
|
|
function buildHeroSliderCss(includeAspectRatio) {
|
|
return [
|
|
'.hero .hero__image-wrap { position: relative; overflow: hidden;' +
|
|
(includeAspectRatio ? ' aspect-ratio: 16 / 11;' : '') + ' }',
|
|
'.hero .hero__image-wrap .hero__image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: translateX(6%) scale(1); transition: opacity 1s ease, transform 1.2s ease; }',
|
|
'.hero .hero__image-wrap .hero__image.is-active { opacity: 1; transform: translateX(0); animation: hero-zoom 6s ease-in-out infinite alternate; }',
|
|
'.hero .hero__image-wrap .hero__image.is-leaving { opacity: 0; transform: translateX(-6%) scale(1.05); animation: none; }',
|
|
'@keyframes hero-zoom { from { transform: scale(1); } to { transform: scale(1.12); } }',
|
|
'.hero .hero__image-wrap .hero__dots { position: absolute; right: 18px; bottom: 18px; display: flex; gap: 6px; z-index: 5; }',
|
|
'.hero .hero__image-wrap .hero__dot { width: 8px; height: 8px; border: none; border-radius: 999px; background: rgba(255,255,255,0.4); cursor: pointer; padding: 0; transition: 0.3s; }',
|
|
'.hero .hero__image-wrap .hero__dot.is-active { width: 22px; background: #BD252A; }',
|
|
'.hero .hero__image-wrap .hero__dot:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }',
|
|
'@media (prefers-reduced-motion: reduce) { .hero .hero__image-wrap .hero__image { animation: none !important; transition: none !important; } }'
|
|
].join('\n');
|
|
}
|
|
|
|
function initHeroSlider() {
|
|
var wrap = document.querySelector('.hero__image-wrap');
|
|
|
|
if (!wrap) {
|
|
return;
|
|
}
|
|
|
|
if (wrap.getAttribute('data-hero-slider-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
var firstImage = wrap.querySelector('.hero__image');
|
|
|
|
if (!firstImage) {
|
|
return;
|
|
}
|
|
|
|
wrap.setAttribute('data-hero-slider-init', 'true');
|
|
|
|
/* Read slide 1 from the existing markup. */
|
|
HERO_SLIDES[0].src = firstImage.getAttribute('src') || '';
|
|
HERO_SLIDES[0].alt = firstImage.getAttribute('alt') || '';
|
|
|
|
/* Inject the slider CSS into <head>; style.css stays untouched. */
|
|
if (!document.getElementById('hero-slider-style')) {
|
|
var style = document.createElement('style');
|
|
style.id = 'hero-slider-style';
|
|
style.textContent = buildHeroSliderCss(wrap.offsetHeight === 0);
|
|
document.head.appendChild(style);
|
|
}
|
|
|
|
/* Avoid duplicating the markup if another slider already built it. */
|
|
if (wrap.querySelector('.hero__dots') ||
|
|
wrap.querySelectorAll('.hero__image').length > 1) {
|
|
return;
|
|
}
|
|
|
|
firstImage.classList.add('is-active');
|
|
|
|
var secondImage = document.createElement('img');
|
|
secondImage.className = 'hero__image';
|
|
secondImage.src = HERO_SLIDES[1].src;
|
|
secondImage.alt = HERO_SLIDES[1].alt;
|
|
secondImage.width = 1000;
|
|
secondImage.height = 1200;
|
|
secondImage.loading = 'lazy';
|
|
wrap.appendChild(secondImage);
|
|
|
|
var images = [firstImage, secondImage];
|
|
var dots = document.createElement('div');
|
|
dots.className = 'hero__dots';
|
|
var dotButtons = [];
|
|
|
|
HERO_SLIDES.forEach(function (slide, index) {
|
|
var dot = document.createElement('button');
|
|
dot.type = 'button';
|
|
dot.className = 'hero__dot' + (index === 0 ? ' is-active' : '');
|
|
dot.setAttribute('aria-label', 'Show slide ' + (index + 1));
|
|
dot.addEventListener('click', function () {
|
|
goTo(index);
|
|
restart();
|
|
});
|
|
dots.appendChild(dot);
|
|
dotButtons.push(dot);
|
|
});
|
|
|
|
wrap.appendChild(dots);
|
|
|
|
var current = 0;
|
|
var timer = null;
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
var AUTO_MS = 5000;
|
|
var LEAVE_MS = 1200;
|
|
|
|
function updateDots() {
|
|
dotButtons.forEach(function (dot, index) {
|
|
dot.classList.toggle('is-active', index === current);
|
|
});
|
|
}
|
|
|
|
function goTo(index) {
|
|
if (index === current) {
|
|
updateDots();
|
|
return;
|
|
}
|
|
|
|
var previous = images[current];
|
|
var next = images[index];
|
|
|
|
if (previous) {
|
|
previous.classList.remove('is-active');
|
|
previous.classList.add('is-leaving');
|
|
|
|
window.setTimeout(function () {
|
|
previous.classList.remove('is-leaving');
|
|
}, LEAVE_MS);
|
|
}
|
|
|
|
next.classList.remove('is-leaving');
|
|
next.classList.add('is-active');
|
|
|
|
current = index;
|
|
updateDots();
|
|
}
|
|
|
|
function stop() {
|
|
if (timer) {
|
|
window.clearInterval(timer);
|
|
timer = null;
|
|
}
|
|
}
|
|
|
|
function start() {
|
|
stop();
|
|
|
|
if (reduceMotion || document.hidden || images.length < 2) {
|
|
return;
|
|
}
|
|
|
|
timer = window.setInterval(function () {
|
|
goTo((current + 1) % images.length);
|
|
}, AUTO_MS);
|
|
}
|
|
|
|
function restart() {
|
|
start();
|
|
}
|
|
|
|
var media = document.querySelector('.hero__media');
|
|
|
|
if (media) {
|
|
media.addEventListener('mouseenter', stop);
|
|
media.addEventListener('mouseleave', start);
|
|
}
|
|
|
|
document.addEventListener('visibilitychange', function () {
|
|
if (document.hidden) {
|
|
stop();
|
|
} else {
|
|
start();
|
|
}
|
|
});
|
|
|
|
start();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initHeroSlider);
|
|
} else {
|
|
initHeroSlider();
|
|
}
|
|
})();
|
|
|
|
/* ==========================================================================
|
|
CAREER PATHWAYS — TEXT, STAGGER, SPOTLIGHT & KEYBOARD
|
|
Appended as an isolated IIFE so it cannot interfere with the code above.
|
|
It reuses the existing .reveal / .is-visible observer from main.js and
|
|
does not add a second scroll-reveal script.
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initPathways() {
|
|
var section = document.getElementById('pathways');
|
|
|
|
if (!section) {
|
|
return;
|
|
}
|
|
|
|
if (section.getAttribute('data-pathways-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
section.setAttribute('data-pathways-init', 'true');
|
|
|
|
var title = section.querySelector('.section__title');
|
|
var lead = section.querySelector('.section__lead');
|
|
var disclaimer = section.querySelector('.disclaimer');
|
|
|
|
if (title) {
|
|
title.textContent = 'Career Pathways';
|
|
}
|
|
|
|
if (lead) {
|
|
lead.textContent = 'Skills that open up possibilities. Explore ' +
|
|
'potential pathways where practical AI knowledge and human ' +
|
|
'skills can make a difference.';
|
|
}
|
|
|
|
if (disclaimer) {
|
|
disclaimer.textContent = 'These are possible opportunities, not ' +
|
|
'promised outcomes. Employment, freelance income, and ' +
|
|
'business results depend on your skills, experience, effort, ' +
|
|
'and market conditions.';
|
|
}
|
|
|
|
var cards = Array.prototype.slice.call(
|
|
section.querySelectorAll('.pathway-card')
|
|
);
|
|
|
|
cards.forEach(function (card, index) {
|
|
card.style.setProperty('--i', index);
|
|
card.setAttribute('tabindex', '0');
|
|
});
|
|
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
var isTouch = window.matchMedia(
|
|
'(hover: none), (pointer: coarse)'
|
|
).matches;
|
|
|
|
if (reduceMotion || isTouch) {
|
|
return;
|
|
}
|
|
|
|
cards.forEach(function (card) {
|
|
card.addEventListener('mousemove', function (event) {
|
|
var rect = card.getBoundingClientRect();
|
|
|
|
card.style.setProperty(
|
|
'--mx',
|
|
(event.clientX - rect.left) + 'px'
|
|
);
|
|
card.style.setProperty(
|
|
'--my',
|
|
(event.clientY - rect.top) + 'px'
|
|
);
|
|
});
|
|
|
|
card.addEventListener('mouseleave', function () {
|
|
card.style.setProperty('--mx', '50%');
|
|
card.style.setProperty('--my', '50%');
|
|
});
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initPathways);
|
|
} else {
|
|
initPathways();
|
|
}
|
|
})();
|
|
|
|
// ===== CERTIFICATION PAGE =====
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initCertPage() {
|
|
var page = document.querySelector('.cert-page');
|
|
|
|
if (!page) {
|
|
return;
|
|
}
|
|
|
|
if (page.getAttribute('data-cert-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
page.setAttribute('data-cert-init', 'true');
|
|
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
var isTouch = window.matchMedia(
|
|
'(hover: none), (pointer: coarse)'
|
|
).matches;
|
|
|
|
/* Pathway line fills in as the section scrolls into view. */
|
|
var path = page.querySelector('.cert-path');
|
|
|
|
if (path) {
|
|
if (reduceMotion || !('IntersectionObserver' in window)) {
|
|
path.classList.add('is-lit');
|
|
} else {
|
|
var pathObserver = new IntersectionObserver(
|
|
function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('is-lit');
|
|
pathObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
},
|
|
{ threshold: 0.35 }
|
|
);
|
|
|
|
pathObserver.observe(path);
|
|
}
|
|
}
|
|
|
|
/* Subtle 3D tilt on the certificate preview card. */
|
|
var tiltCard = page.querySelector('[data-cert-tilt]');
|
|
|
|
if (tiltCard && !reduceMotion && !isTouch) {
|
|
var MAX_TILT = 6;
|
|
|
|
tiltCard.addEventListener('mousemove', function (event) {
|
|
var rect = tiltCard.getBoundingClientRect();
|
|
var px = (event.clientX - rect.left) / rect.width - 0.5;
|
|
var py = (event.clientY - rect.top) / rect.height - 0.5;
|
|
|
|
tiltCard.style.setProperty(
|
|
'--cert-rx',
|
|
(-py * MAX_TILT * 2).toFixed(2) + 'deg'
|
|
);
|
|
tiltCard.style.setProperty(
|
|
'--cert-ry',
|
|
(px * MAX_TILT * 2).toFixed(2) + 'deg'
|
|
);
|
|
});
|
|
|
|
tiltCard.addEventListener('mouseleave', function () {
|
|
tiltCard.style.setProperty('--cert-rx', '0deg');
|
|
tiltCard.style.setProperty('--cert-ry', '0deg');
|
|
});
|
|
}
|
|
|
|
/* Certificate FAQ accordion (one item open at a time). */
|
|
var faqItems = Array.prototype.slice.call(
|
|
page.querySelectorAll('.cert-faq__item')
|
|
);
|
|
|
|
faqItems.forEach(function (item) {
|
|
var trigger = item.querySelector('.cert-faq__trigger');
|
|
var panel = item.querySelector('.cert-faq__panel');
|
|
|
|
if (!trigger) {
|
|
return;
|
|
}
|
|
|
|
trigger.addEventListener('click', function () {
|
|
var wasOpen = item.classList.contains('is-open');
|
|
|
|
faqItems.forEach(function (other) {
|
|
other.classList.remove('is-open');
|
|
|
|
var otherTrigger = other.querySelector('.cert-faq__trigger');
|
|
var otherPanel = other.querySelector('.cert-faq__panel');
|
|
|
|
if (otherTrigger) {
|
|
otherTrigger.setAttribute('aria-expanded', 'false');
|
|
}
|
|
if (otherPanel) {
|
|
otherPanel.setAttribute('aria-hidden', 'true');
|
|
}
|
|
});
|
|
|
|
if (!wasOpen) {
|
|
item.classList.add('is-open');
|
|
trigger.setAttribute('aria-expanded', 'true');
|
|
|
|
if (panel) {
|
|
panel.setAttribute('aria-hidden', 'false');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initCertPage);
|
|
} else {
|
|
initCertPage();
|
|
}
|
|
})();
|
|
|
|
// ===== ABOUT PAGE =====
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initAboutPage() {
|
|
var page = document.querySelector('.about-page');
|
|
|
|
if (!page) {
|
|
return;
|
|
}
|
|
|
|
if (page.getAttribute('data-about-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
page.setAttribute('data-about-init', 'true');
|
|
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
|
|
/* Missing image fallbacks. */
|
|
var images = Array.prototype.slice.call(page.querySelectorAll('img'));
|
|
|
|
images.forEach(function (img) {
|
|
function markMissing() {
|
|
var wrapper = img.parentElement;
|
|
|
|
if (wrapper) {
|
|
wrapper.classList.add('is-missing');
|
|
}
|
|
}
|
|
|
|
img.addEventListener('error', markMissing);
|
|
|
|
if (img.complete && img.naturalWidth === 0) {
|
|
markMissing();
|
|
}
|
|
});
|
|
|
|
/* Practical approach image: clip-path wipe + slow zoom. */
|
|
var media = page.querySelector('.about-approach__media');
|
|
|
|
if (media) {
|
|
if (reduceMotion || !('IntersectionObserver' in window)) {
|
|
media.classList.add('about-inview');
|
|
} else {
|
|
var mediaObserver = new IntersectionObserver(
|
|
function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('about-inview');
|
|
mediaObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
},
|
|
{ threshold: 0.25 }
|
|
);
|
|
|
|
mediaObserver.observe(media);
|
|
}
|
|
}
|
|
|
|
/* Learning journey: connector line + badge sequence. */
|
|
var journey = page.querySelector('.about-journey');
|
|
|
|
if (journey) {
|
|
if (reduceMotion || !('IntersectionObserver' in window)) {
|
|
journey.classList.add('about-lit');
|
|
} else {
|
|
var journeyObserver = new IntersectionObserver(
|
|
function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('about-lit');
|
|
journeyObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
},
|
|
{ threshold: 0.3 }
|
|
);
|
|
|
|
journeyObserver.observe(journey);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initAboutPage);
|
|
} else {
|
|
initAboutPage();
|
|
}
|
|
})();
|
|
|
|
// ===== ABOUT FACULTY UPDATE =====
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initFacultyTilt() {
|
|
var grid = document.querySelector('.about-faculty-grid');
|
|
var cards = document.querySelectorAll('.about-faculty-card');
|
|
|
|
if (!grid || !cards.length) {
|
|
return;
|
|
}
|
|
|
|
if (grid.getAttribute('data-about-faculty-tilt') === 'true') {
|
|
return;
|
|
}
|
|
|
|
grid.setAttribute('data-about-faculty-tilt', 'true');
|
|
|
|
var reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
var isTouch = window.matchMedia('(hover: none), (pointer: coarse)').matches;
|
|
|
|
if (reduceMotion || isTouch) {
|
|
return;
|
|
}
|
|
|
|
Array.prototype.forEach.call(cards, function (card) {
|
|
card.addEventListener('mousemove', function (event) {
|
|
var rect = card.getBoundingClientRect();
|
|
var px = (event.clientX - rect.left) / rect.width - 0.5;
|
|
var py = (event.clientY - rect.top) / rect.height - 0.5;
|
|
|
|
card.style.setProperty('--rx', (-py * 8).toFixed(2) + 'deg');
|
|
card.style.setProperty('--ry', (px * 8).toFixed(2) + 'deg');
|
|
});
|
|
|
|
card.addEventListener('mouseleave', function () {
|
|
card.style.setProperty('--rx', '0deg');
|
|
card.style.setProperty('--ry', '0deg');
|
|
});
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initFacultyTilt);
|
|
} else {
|
|
initFacultyTilt();
|
|
}
|
|
})();
|
|
|
|
// ===== ABOUT APPROACH: reveal =====
|
|
(function () {
|
|
'use strict';
|
|
|
|
var media = document.querySelector('.about-approach__media');
|
|
var content = document.querySelector('.about-approach__content');
|
|
if (!media || !content) return;
|
|
|
|
function show() {
|
|
media.classList.add('about-inview');
|
|
content.classList.add('is-visible');
|
|
}
|
|
|
|
if (!('IntersectionObserver' in window)) {
|
|
show();
|
|
return;
|
|
}
|
|
|
|
var io = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
show();
|
|
io.disconnect();
|
|
}
|
|
});
|
|
}, { threshold: 0.15 });
|
|
|
|
io.observe(media);
|
|
io.observe(content);
|
|
})();
|
|
|
|
// ===== CTA SECTIONS: reveal + ripple =====
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initCtaSections() {
|
|
var sections = Array.prototype.slice.call(
|
|
document.querySelectorAll('.bc-cta, .cert-cta')
|
|
);
|
|
var bootcampInner = document.querySelector('.bc-cta__inner');
|
|
var reduceMotion = window.matchMedia(
|
|
'(prefers-reduced-motion: reduce)'
|
|
).matches;
|
|
|
|
if (bootcampInner) {
|
|
if (reduceMotion || !('IntersectionObserver' in window)) {
|
|
bootcampInner.classList.add('is-reveal-visible');
|
|
} else {
|
|
bootcampInner.classList.add('is-reveal-pending');
|
|
|
|
var observer = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.remove('is-reveal-pending');
|
|
entry.target.classList.add('is-reveal-visible');
|
|
observer.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, { threshold: 0.2 });
|
|
|
|
observer.observe(bootcampInner);
|
|
}
|
|
}
|
|
|
|
if (reduceMotion || !sections.length) {
|
|
return;
|
|
}
|
|
|
|
sections.forEach(function (section) {
|
|
var buttons = Array.prototype.slice.call(
|
|
section.querySelectorAll('.btn')
|
|
);
|
|
|
|
buttons.forEach(function (button) {
|
|
button.addEventListener('click', function (event) {
|
|
var rect = button.getBoundingClientRect();
|
|
var hasPoint = event.clientX > 0 || event.clientY > 0;
|
|
var x = hasPoint ? event.clientX - rect.left : rect.width / 2;
|
|
var y = hasPoint ? event.clientY - rect.top : rect.height / 2;
|
|
|
|
var ripple = document.createElement('span');
|
|
ripple.className = 'btn__ripple';
|
|
ripple.style.left = x + 'px';
|
|
ripple.style.top = y + 'px';
|
|
button.appendChild(ripple);
|
|
|
|
ripple.addEventListener('animationend', function () {
|
|
if (ripple.parentNode) {
|
|
ripple.parentNode.removeChild(ripple);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initCtaSections);
|
|
} else {
|
|
initCtaSections();
|
|
}
|
|
})();
|
|
|
|
/* ==========================================================================
|
|
APPLICATION FORM VALIDATION
|
|
========================================================================== */
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initApplicationForm() {
|
|
var form = document.querySelector('.application-form');
|
|
|
|
if (!form) {
|
|
return;
|
|
}
|
|
|
|
var submitButton = form.querySelector('.application-submit');
|
|
var submitLabel = form.querySelector('.application-submit__label');
|
|
var originalLabel = submitLabel ? submitLabel.textContent : 'Submit Application';
|
|
|
|
var rules = {
|
|
full_name: function (input) {
|
|
var value = input.value.trim();
|
|
|
|
if (!value) {
|
|
return 'Please enter your full name.';
|
|
}
|
|
|
|
if (value.length > 120) {
|
|
return 'Please keep your full name under 120 characters.';
|
|
}
|
|
|
|
return '';
|
|
},
|
|
phone: function (input) {
|
|
var value = input.value.trim();
|
|
|
|
if (!value) {
|
|
return 'Please enter your phone number.';
|
|
}
|
|
|
|
if (!/^[0-9+\-()\s]+$/.test(value)) {
|
|
return 'Please enter a valid phone number.';
|
|
}
|
|
|
|
var digits = value.replace(/\D/g, '');
|
|
|
|
if (digits.length < 7) {
|
|
return 'Please enter a valid phone number with at least 7 digits.';
|
|
}
|
|
|
|
if (digits.length > 20) {
|
|
return 'Please enter a phone number with no more than 20 digits.';
|
|
}
|
|
|
|
return '';
|
|
},
|
|
email: function (input) {
|
|
var value = input.value.trim();
|
|
|
|
if (!value) {
|
|
return 'Please enter your email address.';
|
|
}
|
|
|
|
if (value.length > 254 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
|
|
return 'Please enter a valid email address.';
|
|
}
|
|
|
|
return '';
|
|
},
|
|
age: function (input) {
|
|
var value = input.value.trim();
|
|
|
|
if (!value) {
|
|
return '';
|
|
}
|
|
|
|
if (!/^\d+$/.test(value)) {
|
|
return 'Age must be a number between 16 and 100.';
|
|
}
|
|
|
|
var age = parseInt(value, 10);
|
|
|
|
if (age < 16 || age > 100) {
|
|
return 'Age must be a number between 16 and 100.';
|
|
}
|
|
|
|
return '';
|
|
},
|
|
terms: function (input) {
|
|
if (!input.checked) {
|
|
return 'Please agree to the Terms to continue.';
|
|
}
|
|
|
|
return '';
|
|
}
|
|
};
|
|
|
|
function getField(input) {
|
|
return input ? input.closest('.application-field') : null;
|
|
}
|
|
|
|
function setError(name, message) {
|
|
var input = form.querySelector('[name="' + name + '"]');
|
|
var field = getField(input);
|
|
var error = form.querySelector('[data-error-for="' + name + '"]');
|
|
|
|
if (field) {
|
|
field.classList.toggle('has-error', Boolean(message));
|
|
}
|
|
|
|
if (input) {
|
|
input.setAttribute('aria-invalid', message ? 'true' : 'false');
|
|
}
|
|
|
|
if (error) {
|
|
error.textContent = message;
|
|
}
|
|
}
|
|
|
|
function validateField(input) {
|
|
var rule = rules[input.name];
|
|
|
|
if (!rule) {
|
|
return true;
|
|
}
|
|
|
|
var message = rule(input);
|
|
setError(input.name, message);
|
|
|
|
return !message;
|
|
}
|
|
|
|
Object.keys(rules).forEach(function (name) {
|
|
var input = form.querySelector('[name="' + name + '"]');
|
|
|
|
if (!input) {
|
|
return;
|
|
}
|
|
|
|
input.addEventListener('blur', function () {
|
|
var field = getField(input);
|
|
|
|
if (field && (field.classList.contains('has-error') || input.value.trim() !== '')) {
|
|
validateField(input);
|
|
}
|
|
});
|
|
|
|
input.addEventListener('input', function () {
|
|
var field = getField(input);
|
|
|
|
if (field && field.classList.contains('has-error')) {
|
|
validateField(input);
|
|
}
|
|
});
|
|
|
|
input.addEventListener('change', function () {
|
|
var field = getField(input);
|
|
|
|
if (field && field.classList.contains('has-error')) {
|
|
validateField(input);
|
|
}
|
|
});
|
|
});
|
|
|
|
form.addEventListener('submit', function (event) {
|
|
var firstInvalid = null;
|
|
|
|
Object.keys(rules).forEach(function (name) {
|
|
var input = form.querySelector('[name="' + name + '"]');
|
|
|
|
if (!input) {
|
|
return;
|
|
}
|
|
|
|
if (!validateField(input) && !firstInvalid) {
|
|
firstInvalid = input;
|
|
}
|
|
});
|
|
|
|
if (firstInvalid) {
|
|
event.preventDefault();
|
|
firstInvalid.focus();
|
|
|
|
if (firstInvalid.scrollIntoView) {
|
|
firstInvalid.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (submitButton) {
|
|
submitButton.disabled = true;
|
|
submitButton.setAttribute('aria-busy', 'true');
|
|
}
|
|
|
|
if (submitLabel) {
|
|
submitLabel.textContent = 'Submitting...';
|
|
}
|
|
});
|
|
|
|
window.addEventListener('pageshow', function () {
|
|
if (submitButton) {
|
|
submitButton.disabled = false;
|
|
submitButton.removeAttribute('aria-busy');
|
|
}
|
|
|
|
if (submitLabel) {
|
|
submitLabel.textContent = originalLabel;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initApplicationForm);
|
|
} else {
|
|
initApplicationForm();
|
|
}
|
|
})();
|
|
|
|
// ===== STUDENT WORK GALLERY FILTERS
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initStudentWorkFilters() {
|
|
var page = document.querySelector('.student-work');
|
|
var grid = document.getElementById('student-work-grid');
|
|
|
|
if (!page || !grid) {
|
|
return;
|
|
}
|
|
|
|
if (grid.getAttribute('data-student-filters-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
grid.setAttribute('data-student-filters-init', 'true');
|
|
|
|
var cards = Array.prototype.slice.call(
|
|
grid.querySelectorAll('.student-card')
|
|
);
|
|
var courseSelect = page.querySelector('[data-filter="course"]');
|
|
var skillSelect = page.querySelector('[data-filter="skill"]');
|
|
var batchSelect = page.querySelector('[data-filter="batch"]');
|
|
var resetButton = page.querySelector('.student-work__reset');
|
|
var count = page.querySelector('.student-work__count');
|
|
var emptyState = page.querySelector('.student-work__empty');
|
|
|
|
if (!cards.length || !courseSelect || !skillSelect || !batchSelect) {
|
|
return;
|
|
}
|
|
|
|
function getSkills(card) {
|
|
var raw = card.getAttribute('data-skills') || '';
|
|
if (!raw) {
|
|
return [];
|
|
}
|
|
return raw.split('|').filter(function (skill) {
|
|
return skill !== '';
|
|
});
|
|
}
|
|
|
|
function populateSelect(select, values, allLabel) {
|
|
var selected = select.value || 'all';
|
|
select.innerHTML = '';
|
|
|
|
var allOption = document.createElement('option');
|
|
allOption.value = 'all';
|
|
allOption.textContent = allLabel;
|
|
select.appendChild(allOption);
|
|
|
|
values.forEach(function (value) {
|
|
var option = document.createElement('option');
|
|
option.value = value;
|
|
option.textContent = value;
|
|
select.appendChild(option);
|
|
});
|
|
|
|
if (values.indexOf(selected) !== -1) {
|
|
select.value = selected;
|
|
}
|
|
}
|
|
|
|
function collectValues() {
|
|
var courses = [];
|
|
var skills = [];
|
|
var batches = [];
|
|
|
|
cards.forEach(function (card) {
|
|
var course = card.getAttribute('data-course') || '';
|
|
var batch = card.getAttribute('data-batch') || '';
|
|
|
|
if (course && courses.indexOf(course) === -1) {
|
|
courses.push(course);
|
|
}
|
|
if (batch && batches.indexOf(batch) === -1) {
|
|
batches.push(batch);
|
|
}
|
|
|
|
getSkills(card).forEach(function (skill) {
|
|
if (skills.indexOf(skill) === -1) {
|
|
skills.push(skill);
|
|
}
|
|
});
|
|
});
|
|
|
|
courses.sort();
|
|
skills.sort();
|
|
batches.sort();
|
|
|
|
populateSelect(courseSelect, courses, 'All courses');
|
|
populateSelect(skillSelect, skills, 'All skills');
|
|
populateSelect(batchSelect, batches, 'All batches');
|
|
}
|
|
|
|
function updateCount(visible) {
|
|
if (count) {
|
|
count.textContent = 'Showing ' + visible + ' illustrative concept' + (visible === 1 ? '' : 's');
|
|
}
|
|
}
|
|
|
|
function applyFilters() {
|
|
var course = courseSelect.value;
|
|
var skill = skillSelect.value;
|
|
var batch = batchSelect.value;
|
|
var visible = 0;
|
|
|
|
cards.forEach(function (card) {
|
|
var cardCourse = card.getAttribute('data-course') || '';
|
|
var cardBatch = card.getAttribute('data-batch') || '';
|
|
var cardSkills = getSkills(card);
|
|
var matchesCourse = course === 'all' || cardCourse === course;
|
|
var matchesSkill = skill === 'all' || cardSkills.indexOf(skill) !== -1;
|
|
var matchesBatch = batch === 'all' || cardBatch === batch;
|
|
var show = matchesCourse && matchesSkill && matchesBatch;
|
|
|
|
card.classList.toggle('is-hidden', !show);
|
|
if (show) {
|
|
visible += 1;
|
|
}
|
|
});
|
|
|
|
updateCount(visible);
|
|
|
|
if (emptyState) {
|
|
emptyState.hidden = visible !== 0;
|
|
}
|
|
}
|
|
|
|
collectValues();
|
|
applyFilters();
|
|
|
|
[courseSelect, skillSelect, batchSelect].forEach(function (select) {
|
|
select.addEventListener('change', applyFilters);
|
|
});
|
|
|
|
if (resetButton) {
|
|
resetButton.addEventListener('click', function () {
|
|
courseSelect.value = 'all';
|
|
skillSelect.value = 'all';
|
|
batchSelect.value = 'all';
|
|
applyFilters();
|
|
});
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initStudentWorkFilters);
|
|
} else {
|
|
initStudentWorkFilters();
|
|
}
|
|
})();
|
|
|
|
// ===== BLOG DETAIL PAGE =====
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initBlogDetail() {
|
|
var page = document.querySelector('.blog-detail');
|
|
if (!page || page.getAttribute('data-blog-detail-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
page.setAttribute('data-blog-detail-init', 'true');
|
|
|
|
var progressBar = page.querySelector('.reading-progress__bar');
|
|
function updateProgress() {
|
|
if (!progressBar) {
|
|
return;
|
|
}
|
|
|
|
var doc = document.documentElement;
|
|
var scrollTop = window.scrollY || doc.scrollTop || 0;
|
|
var scrollHeight = doc.scrollHeight - window.innerHeight;
|
|
var progress = scrollHeight > 0 ? (scrollTop / scrollHeight) * 100 : 0;
|
|
|
|
if (progress < 0) {
|
|
progress = 0;
|
|
}
|
|
if (progress > 100) {
|
|
progress = 100;
|
|
}
|
|
|
|
progressBar.style.width = progress + '%';
|
|
}
|
|
|
|
if (progressBar) {
|
|
updateProgress();
|
|
window.addEventListener('scroll', updateProgress, { passive: true });
|
|
window.addEventListener('resize', updateProgress);
|
|
}
|
|
|
|
var tocLinks = Array.prototype.slice.call(page.querySelectorAll('.blog-toc__link'));
|
|
var sections = [];
|
|
|
|
tocLinks.forEach(function (link) {
|
|
var href = link.getAttribute('href') || '';
|
|
if (href.charAt(0) !== '#') {
|
|
return;
|
|
}
|
|
|
|
var section = document.getElementById(href.slice(1));
|
|
if (section) {
|
|
sections.push({ link: link, section: section });
|
|
}
|
|
});
|
|
|
|
function setActiveLink(activeLink) {
|
|
tocLinks.forEach(function (link) {
|
|
link.classList.toggle('is-active', link === activeLink);
|
|
});
|
|
}
|
|
|
|
if (sections.length && 'IntersectionObserver' in window) {
|
|
var observer = new IntersectionObserver(function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
sections.forEach(function (item) {
|
|
if (item.section === entry.target) {
|
|
setActiveLink(item.link);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}, {
|
|
rootMargin: '-20% 0px -60% 0px',
|
|
threshold: 0.1
|
|
});
|
|
|
|
sections.forEach(function (item) {
|
|
observer.observe(item.section);
|
|
});
|
|
} else if (sections.length) {
|
|
setActiveLink(sections[0].link);
|
|
}
|
|
|
|
var form = page.querySelector('.blog-comment__form');
|
|
if (form) {
|
|
var status = form.querySelector('.blog-comment__status');
|
|
form.addEventListener('submit', function (event) {
|
|
event.preventDefault();
|
|
|
|
var requiredNames = ['comment', 'name', 'email'];
|
|
var isValid = true;
|
|
|
|
requiredNames.forEach(function (name) {
|
|
var field = form.querySelector('[name="' + name + '"]');
|
|
if (!field) {
|
|
return;
|
|
}
|
|
|
|
var value = (field.value || '').trim();
|
|
if (!value) {
|
|
isValid = false;
|
|
field.setAttribute('aria-invalid', 'true');
|
|
} else {
|
|
field.removeAttribute('aria-invalid');
|
|
}
|
|
});
|
|
|
|
if (status) {
|
|
status.textContent = isValid ? 'Comments are not enabled yet.' : 'Please fill in the required fields.';
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initBlogDetail);
|
|
} else {
|
|
initBlogDetail();
|
|
}
|
|
})();
|
|
|
|
// ===== TESTIMONIALS PAGE =====
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initTestimonialsPage() {
|
|
var page = document.querySelector('.testimonials');
|
|
if (!page || page.getAttribute('data-testimonials-init') === 'true') {
|
|
return;
|
|
}
|
|
|
|
page.setAttribute('data-testimonials-init', 'true');
|
|
|
|
var searchInput = page.querySelector('.testimonials__search-input');
|
|
var tabs = Array.prototype.slice.call(page.querySelectorAll('.testimonials__tab'));
|
|
var textPanel = document.getElementById('testimonials-panel-text');
|
|
var videoPanel = document.getElementById('testimonials-panel-video');
|
|
var grid = page.querySelector('.testimonials__grid');
|
|
var cards = grid ? Array.prototype.slice.call(grid.querySelectorAll('.testimonial-card')) : [];
|
|
var emptyState = page.querySelector('.testimonials__empty:not(.testimonials__empty--video)');
|
|
var loadMoreButton = page.querySelector('.testimonials__more');
|
|
var modal = document.getElementById('testimonial-modal');
|
|
|
|
var batchSize = 12;
|
|
var visibleCount = 0;
|
|
var matchingCards = cards.slice();
|
|
var reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
function setActiveTab(tabName) {
|
|
tabs.forEach(function (tab) {
|
|
var isActive = (tab.getAttribute('data-tab') || '') === tabName;
|
|
tab.classList.toggle('is-active', isActive);
|
|
tab.setAttribute('aria-selected', String(isActive));
|
|
tab.tabIndex = isActive ? 0 : -1;
|
|
});
|
|
|
|
if (textPanel) {
|
|
textPanel.hidden = tabName !== 'text';
|
|
}
|
|
if (videoPanel) {
|
|
videoPanel.hidden = tabName !== 'video';
|
|
}
|
|
}
|
|
|
|
function renderCards(resetCount) {
|
|
if (resetCount) {
|
|
visibleCount = Math.min(batchSize, matchingCards.length);
|
|
}
|
|
|
|
cards.forEach(function (card) {
|
|
card.hidden = true;
|
|
});
|
|
|
|
matchingCards.forEach(function (card, index) {
|
|
card.hidden = index >= visibleCount;
|
|
});
|
|
|
|
if (emptyState) {
|
|
emptyState.hidden = matchingCards.length !== 0;
|
|
}
|
|
|
|
if (loadMoreButton) {
|
|
loadMoreButton.hidden = matchingCards.length <= visibleCount;
|
|
}
|
|
}
|
|
|
|
function applySearch() {
|
|
var query = searchInput ? (searchInput.value || '').trim().toLowerCase() : '';
|
|
|
|
matchingCards = cards.filter(function (card) {
|
|
var name = (card.getAttribute('data-name') || '').toLowerCase();
|
|
var course = (card.getAttribute('data-course') || '').toLowerCase();
|
|
return query === '' || name.indexOf(query) !== -1 || course.indexOf(query) !== -1;
|
|
});
|
|
|
|
renderCards(true);
|
|
}
|
|
|
|
tabs.forEach(function (tab) {
|
|
tab.addEventListener('click', function () {
|
|
setActiveTab(tab.getAttribute('data-tab') || 'text');
|
|
});
|
|
});
|
|
|
|
if (searchInput) {
|
|
searchInput.addEventListener('input', applySearch);
|
|
}
|
|
|
|
if (loadMoreButton) {
|
|
loadMoreButton.addEventListener('click', function () {
|
|
visibleCount = Math.min(visibleCount + batchSize, matchingCards.length);
|
|
renderCards(false);
|
|
});
|
|
}
|
|
|
|
applySearch();
|
|
setActiveTab('text');
|
|
|
|
if (!modal) {
|
|
return;
|
|
}
|
|
|
|
var panel = modal.querySelector('.testimonial-modal__panel');
|
|
var closeButtons = Array.prototype.slice.call(modal.querySelectorAll('[data-modal-close]'));
|
|
var modalText = modal.querySelector('.testimonial-modal__text');
|
|
var modalName = modal.querySelector('.testimonial-modal__name');
|
|
var modalCourse = modal.querySelector('.testimonial-modal__course');
|
|
var modalDate = modal.querySelector('.testimonial-modal__date');
|
|
var modalAvatar = modal.querySelector('.testimonial-modal__avatar');
|
|
var lastFocused = null;
|
|
|
|
function getFocusableElements() {
|
|
if (!panel) {
|
|
return [];
|
|
}
|
|
return Array.prototype.slice.call(panel.querySelectorAll(
|
|
'a[href], button:not([disabled]), textarea, input, select, [tabindex]:not([tabindex="-1"])'
|
|
)).filter(function (el) {
|
|
return !el.hasAttribute('disabled') && el.getAttribute('aria-hidden') !== 'true';
|
|
});
|
|
}
|
|
|
|
function openModal(data, opener) {
|
|
lastFocused = opener || document.activeElement;
|
|
|
|
if (modalText) {
|
|
modalText.textContent = data.text || '';
|
|
}
|
|
if (modalName) {
|
|
modalName.textContent = data.name || '';
|
|
}
|
|
if (modalCourse) {
|
|
modalCourse.textContent = data.course || '';
|
|
}
|
|
if (modalDate) {
|
|
modalDate.textContent = data.date ? 'Posted on: ' + data.date : '';
|
|
}
|
|
if (modalAvatar) {
|
|
modalAvatar.textContent = data.initials || '';
|
|
}
|
|
|
|
modal.classList.add('is-open');
|
|
modal.setAttribute('aria-hidden', 'false');
|
|
document.body.classList.add('modal-open');
|
|
|
|
var focusables = getFocusableElements();
|
|
if (focusables.length) {
|
|
focusables[0].focus();
|
|
} else if (panel) {
|
|
panel.focus();
|
|
}
|
|
}
|
|
|
|
function closeModal() {
|
|
if (!modal.classList.contains('is-open')) {
|
|
return;
|
|
}
|
|
|
|
modal.classList.remove('is-open');
|
|
modal.setAttribute('aria-hidden', 'true');
|
|
document.body.classList.remove('modal-open');
|
|
|
|
if (lastFocused && typeof lastFocused.focus === 'function') {
|
|
lastFocused.focus();
|
|
}
|
|
}
|
|
|
|
cards.forEach(function (card) {
|
|
var button = card.querySelector('.testimonial-card__more');
|
|
if (!button) {
|
|
return;
|
|
}
|
|
|
|
button.addEventListener('click', function () {
|
|
openModal({
|
|
name: button.getAttribute('data-name') || '',
|
|
course: button.getAttribute('data-course') || '',
|
|
text: button.getAttribute('data-text') || '',
|
|
date: button.getAttribute('data-date') || '',
|
|
initials: button.getAttribute('data-initials') || ''
|
|
}, button);
|
|
});
|
|
});
|
|
|
|
closeButtons.forEach(function (button) {
|
|
button.addEventListener('click', closeModal);
|
|
});
|
|
|
|
modal.addEventListener('click', function (event) {
|
|
if (event.target && event.target.hasAttribute('data-modal-close')) {
|
|
closeModal();
|
|
}
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (!modal.classList.contains('is-open')) {
|
|
return;
|
|
}
|
|
|
|
if (event.key === 'Escape' || event.key === 'Esc') {
|
|
event.preventDefault();
|
|
closeModal();
|
|
return;
|
|
}
|
|
|
|
if (event.key === 'Tab') {
|
|
var focusables = getFocusableElements();
|
|
if (!focusables.length) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
|
|
var first = focusables[0];
|
|
var last = focusables[focusables.length - 1];
|
|
|
|
if (event.shiftKey && document.activeElement === first) {
|
|
event.preventDefault();
|
|
last.focus();
|
|
} else if (!event.shiftKey && document.activeElement === last) {
|
|
event.preventDefault();
|
|
first.focus();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initTestimonialsPage);
|
|
} else {
|
|
initTestimonialsPage();
|
|
}
|
|
})();
|