1325 lines
43 KiB
JavaScript
1325 lines
43 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);
|
|
})();
|