-
Notifications
You must be signed in to change notification settings - Fork 0
/
nativeTypedJS.min.js
1 lines (1 loc) · 3.01 KB
/
nativeTypedJS.min.js
1
function nativeTypedJS(e){function t(t){function i(){whileLoopCount<=pElementsCount?(textItem=t[whileLoopCount],countPauses=(textItem.match(/~/g)||[]).length,0!=countPauses?makeAnimationLonger=countPauses*e.cursorPause:makeAnimationLonger=0,m(whileLoopCount),e.whileLoopCount=whileLoopCount++,setTimeout(i,e.animationTime+makeAnimationLonger)):e.loop&&(whileLoopCount=0,i())}n(),masterP=document.createElement("p"),parentDiv.appendChild(masterP),textSpan=document.createElement("span"),textSpan.id="ntjsText",parentDiv.firstChild.appendChild(textSpan),cursorSpan=document.createElement("span"),cursorSpan.id="ntjsCursor",cursorSpan.innerText="|",parentDiv.firstChild.appendChild(cursorSpan),pElementsCount=e.pElementsCount=t.length-1,whileLoopCount=0,makeAnimationLonger=0,e.shuffle&&l(t),setTimeout(i,e.firstTimeStart),o(),setInterval(o,e.cursorSpeed)}function n(){for(;parentDiv.firstChild;)parentDiv.removeChild(parentDiv.firstChild)}function o(){s(document.getElementById("ntjsCursor")),setTimeout(function(){r(document.getElementById("ntjsCursor"))},e.cursorSpeed/2)}function r(e){e.style.opacity=0,last=+new Date,tick=function(){e.style.opacity=+e.style.opacity+(new Date-last)/100,last=+new Date,+e.style.opacity<1&&(window.requestAnimationFrame&&requestAnimationFrame(tick)||setTimeout(tick,16))},tick()}function s(e){e.style.opacity=1,last=+new Date,tick=function(){e.style.opacity=+e.style.opacity-(new Date-last)/100,last=+new Date,+e.style.opacity>0&&(window.requestAnimationFrame&&requestAnimationFrame(tick)||setTimeout(tick,16))},tick()}function m(){"~"==textItem.substr(substrCount,1)&&(textItem=textItem.replace("~",""),e.extraTime+=e.cursorPause),document.getElementById("ntjsText").innerHTML=textItem.substr(0,substrCount++),timeNextLetter=(e.animationTime-e.timeBeforeDeleting-e.timeBeforeNext)/2/textItem.length,substrCount<textItem.length+1?(setTimeout(m,timeNextLetter+e.extraTime),e.extraTime=0):(e.whileLoopCount!=e.pElementsCount||e.loop)&&setTimeout(u,e.timeBeforeDeleting)}function u(){document.getElementById("ntjsText").innerHTML=textItem.substr(0,substrCount--),timeNextLetter=(e.animationTime-e.timeBeforeDeleting-e.timeBeforeNext)/2/textItem.length,substrCount>=0?setTimeout(u,timeNextLetter):(substrCount=0,textItem="")}function a(e,t){return"undefined"==typeof e?e=t:e}function l(e){for(i=e.length-1;i>0;i--)j=Math.floor(Math.random()*(i+1)),temp=e[i],e[i]=e[j],e[j]=temp;return e}e=a(e,{}),e.div=a(e.div,"ntjs"),e.firstTimeStart=a(e.firstTimeStart,0),e.timeBeforeDeleting=a(e.timeBeforeDeleting,2e3),e.timeBeforeNext=a(e.timeBeforeNext,1e3),e.animationTime=e.timeBeforeDeleting+e.timeBeforeNext+1+a(e.animationTime,2e3),e.cursorSpeed=a(e.cursorSpeed,1e3),e.shuffle=a(e.shuffle,!1),e.loop=a(e.loop,!1),e.cursorPause=a(e.cursorPause,1e3),e.extraTime=0,parentDiv=document.getElementById(e.div),divChildrens=Array.prototype.slice.call(parentDiv.childNodes),childrenCount=divChildrens.length-1,pElements=[],divChildrens.forEach(function(e,n){1===e.nodeType&&pElements.push(e.textContent),childrenCount===n&&t(pElements)})}var substrCount=0,textItem="";