typing-animations.js
1 lines
| 1 | (()=>{"use strict";var e;function t(e){!function(e){var t=e.querySelectorAll(".spbadd-anim-char");t.length&&(t.forEach((function(e){var t=document.createTextNode(e.textContent);e.parentNode.replaceChild(t,e)})),e.normalize())}(e);for(var t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1),n=[];t.nextNode();)n.push(t.currentNode);n.forEach((function(e){var t=e.textContent;if(t){for(var n=document.createDocumentFragment(),a=0;a<t.length;a++){var r=t[a],i=document.createElement("span");i.className="spbadd-anim-char",i.style.opacity="0",i.style.display="inline",i.textContent=r,n.appendChild(i)}e.parentNode.replaceChild(n,e)}}))}function n(e,n){var a,r=n||{},i=(a=parseFloat(e.getAttribute("data-spbadd-anim-typing-speed")),Math.max(.25,Math.min(3,a||1))),o=function(e){return Math.max(0,Math.min(99999,e||0))}(parseInt(e.getAttribute("data-spbadd-anim-typing-delay"),10)),c=!r.once&&"true"===e.getAttribute("data-spbadd-anim-typing-loop");t(e);var s=e.querySelectorAll(".spbadd-anim-char");if(s.length){var d=1e3/(10*i),l=0;setTimeout((function(){u()}),o)}function u(){l<s.length?(s[l].style.opacity="1",s[l].classList.add("spbadd-anim-typing-cursor"),l>0&&s[l-1].classList.remove("spbadd-anim-typing-cursor"),l++,setTimeout(u,d)):(s.length>0&&s[s.length-1].classList.remove("spbadd-anim-typing-cursor"),c&&setTimeout((function(){s.forEach((function(e){e.style.opacity="0",e.classList.remove("spbadd-anim-typing-cursor")})),l=0,setTimeout(u,d)}),1500))}}(e=document.querySelectorAll(".spbadd-anim-typing")).length&&(window.matchMedia("(prefers-reduced-motion: reduce)").matches||e.forEach((function(e){var t=new IntersectionObserver((function(a){a.forEach((function(a){a.isIntersecting&&(n(e),t.unobserve(e))}))}),{threshold:.5});t.observe(e)})))})(); |