hesabixWpTheme/assets/js/android-page.js

79 lines
2 KiB
JavaScript

/**
* صفحهٔ اپلیکیشن اندروید — FAQ و reveal
*/
(function () {
'use strict';
function initFaq() {
var items = document.querySelectorAll('.hx-android-faq__item');
items.forEach(function (item) {
var btn = item.querySelector('.hx-android-faq__q');
var panel = item.querySelector('.hx-android-faq__a');
if (!btn || !panel) return;
btn.addEventListener('click', function () {
var open = btn.getAttribute('aria-expanded') === 'true';
items.forEach(function (other) {
var ob = other.querySelector('.hx-android-faq__q');
var op = other.querySelector('.hx-android-faq__a');
if (!ob || !op) return;
ob.setAttribute('aria-expanded', 'false');
op.hidden = true;
});
if (!open) {
btn.setAttribute('aria-expanded', 'true');
panel.hidden = false;
}
});
});
}
function initReveal() {
var nodes = document.querySelectorAll('.hx-android-reveal');
if (!nodes.length) return;
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
nodes.forEach(function (n) {
n.classList.add('is-visible');
});
return;
}
if (!('IntersectionObserver' in window)) {
nodes.forEach(function (n) {
n.classList.add('is-visible');
});
return;
}
var io = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
io.unobserve(entry.target);
}
});
},
{ rootMargin: '0px 0px -8% 0px', threshold: 0.12 }
);
nodes.forEach(function (n) {
io.observe(n);
});
}
function ready(fn) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', fn);
} else {
fn();
}
}
ready(function () {
if (!document.querySelector('.hx-android')) return;
initFaq();
initReveal();
});
})();