Files
lettersail/assets/site/faq.js
T

52 lines
2.7 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.
(()=>{
const G={
" ":[30,""],
"В":[50,"M12 98C9 66 10 34 13 4C34 2 40 14 38 24C36 36 24 44 14 46C40 44 48 58 46 74C44 92 30 98 12 96"],
"О":[50,"M22 6C40 2 46 28 45 52C44 78 38 98 26 98C13 98 6 78 6 52C6 28 12 8 30 4"],
"П":[52,"M10 98C8 66 9 34 11 6C24 4 34 4 44 6M44 6C43 40 43 70 45 98"],
"Р":[44,"M10 98C8 70 9 30 12 4M12 6C34 2 42 14 40 26C38 38 26 44 11 44"],
"С":[48,"M42 14C36 6 28 3 22 5C10 10 6 30 6 52C6 78 12 96 26 97C34 98 40 92 43 86"],
"Ы":[56,"M8 6C6 40 7 70 9 96C30 98 36 84 34 72C32 58 22 52 9 54M48 6C47 40 47 70 49 98"]
};
document.querySelectorAll("[data-tall]").forEach(el=>{
let cx=0,h="";
[...el.dataset.tall].forEach((ch,i)=>{
const k=ch.toUpperCase(),g=G[k]||window.brushGlyphs[k];
if(!g)return;
if(g[1])h+=`<g class="faq__letter" style="--i:${i}"><path d="${g[1]}" transform="translate(${cx.toFixed(1)} 0) scale(.85 1.45)"/></g>`;
cx+=g[0]*.85+14;
});
el.querySelectorAll("svg").forEach(node=>node.remove());
el.insertAdjacentHTML("beforeend",`<svg viewBox="-12 -16 ${(cx+10).toFixed(0)} 180" aria-hidden="true">${h}</svg>`);
});
const reduce=matchMedia("(prefers-reduced-motion: reduce)").matches;
const section=document.querySelector("[data-faq]");
if(section&&!document.querySelector("[data-stage]")){
const io=new IntersectionObserver(entries=>entries.forEach(e=>{if(e.isIntersecting){section.classList.add("faq--play");io.disconnect()}}),{threshold:.2});
io.observe(section);
}
document.querySelectorAll(".faq__cloud").forEach(cloud=>{
const answer=cloud.querySelector(".faq__a");
let closing=false;
cloud.querySelector(".faq__q").addEventListener("click",e=>{
if(reduce||!answer.animate)return;
e.preventDefault();
const from=cloud.open?answer.getBoundingClientRect().height:0;
const fromOpacity=cloud.open?getComputedStyle(answer).opacity:0;
answer.getAnimations().forEach(a=>a.cancel());
if(cloud.open&&!closing){
closing=true;
cloud.classList.add("faq__cloud--closing");
const anim=answer.animate([{height:`${from}px`,opacity:fromOpacity},{height:"0px",paddingTop:"0px",opacity:0}],{duration:260,easing:"ease-in",fill:"forwards"});
anim.onfinish=()=>{closing=false;cloud.open=false;cloud.classList.remove("faq__cloud--closing");anim.cancel()};
}else{
closing=false;
cloud.classList.remove("faq__cloud--closing");
cloud.open=true;
const h=answer.offsetHeight;
answer.animate([{height:`${from}px`,paddingTop:from?getComputedStyle(answer).paddingTop:"0px",opacity:fromOpacity},{height:`${h}px`,opacity:1}],{duration:380,easing:"cubic-bezier(.3,1.1,.5,1)"});
}
});
});
})();