shkola/wp-content/themes/dekart/assets/js/single-teacher.js
2026-09-13 22:10:59 +00:00

59 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Личная страница преподавателя — кейсы (табы), sticky CTA (mobile).
* Reveal-анимации глобальные (add.js), здесь только интерактив страницы.
*/
(function () {
'use strict';
// ── Кейсы: табы 9/11 ──
var tabs = document.querySelectorAll('.teacher-single__case-tab');
var panels = document.querySelectorAll('.teacher-single__case-panel');
if (tabs.length && panels.length) {
Array.prototype.forEach.call(tabs, function (tab) {
tab.addEventListener('click', function () {
var value = tab.getAttribute('data-case-tab');
Array.prototype.forEach.call(tabs, function (t) {
var active = t === tab;
t.classList.toggle('is-active', active);
t.setAttribute('aria-selected', active ? 'true' : 'false');
});
Array.prototype.forEach.call(panels, function (panel) {
panel.classList.toggle('is-active', panel.getAttribute('data-case-panel') === value);
});
});
});
}
// ── Sticky CTA (mobile): показать после hero, скрыть у финального CTA ──
var sticky = document.querySelector('.teacher-single__sticky');
if (sticky) {
var hero = document.querySelector('.teacher-single__hero');
var finalCta = document.querySelector('.teacher-single__final');
if (hero) {
var showSticky = function () {
var afterHero = window.scrollY >= hero.offsetHeight - 80;
var finalVisible = false;
if (finalCta) {
var fr = finalCta.getBoundingClientRect();
finalVisible = fr.top < window.innerHeight && fr.bottom > 0;
}
sticky.hidden = !afterHero || finalVisible;
};
showSticky();
var ticking = false;
window.addEventListener('scroll', function () {
if (!ticking) {
window.requestAnimationFrame(function () {
showSticky();
ticking = false;
});
ticking = true;
}
}, { passive: true });
} else {
sticky.hidden = false;
}
}
})();