-
Notifications
You must be signed in to change notification settings - Fork 5
/
WriteIt.min.js
17 lines (17 loc) · 8.07 KB
/
WriteIt.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var d;function f(){this.T="writeit-animate";this.U="writeit-autostart";this.J="writeit-char";this.o="writeit-replace-next";this.L="writeit-speed";this.M="writeit-speed-fixed";this.V="writeit-has-prev";this.N="writeit-start-delay";this.D="writeit-loop";this.v="writeit-next";this.K="writeit-hidden";this.W="writeit-no-blink";this.u="writeit-loop-reverse";this.X="writeit-wait-in-reverse";this.O="writeit-write-all-in-reverse";this.count=0;this.G=[];this.s();this.I=[]}d=f.prototype;
d.j=function(){var a=this;this.G.forEach(function(b){b=new h(b,a.count++);a.I.push(b);b.j()})};d.B=function(a){(a=k(this,a))&&a.B()};function k(a,b){b=document.querySelector(b);var c=null;a.I.forEach(function(e){return e.node==b?(c=e,!1):!0});return c}d.C=function(a){(a=k(this,a))&&a.C()};d.S=function(a,b){var c=k(this,a);c?(l(c),c.s()):(c=new h(a,this.count++),this.I.push(c));b&&(c.P=!0);c.j()};d.s=function(){this.G=Array.from(document.querySelectorAll("*["+this.T+"]"));m(this)};
function m(a){a.G.forEach(function(b){var c=b.cloneNode(!0);c.id="seo_"+b.id;c.style.display="none";b.parentNode.appendChild(c)})}function h(a,b){this.H=!1;this.Z=/,(?!\\)/;if(void 0==a||null==a)throw Error("Node must be a valid HTML tag");this.node=a;this.P=!1;this.m=[];this.i=[];this.m["default"]=[];this.i["default"]=[];this.wait=!1;this.id=b;this.interval=this.timeout=0;this.innerHTML=this.node.innerHTML;this.l=[];this.g=-1;this.s()}d=h.prototype;
d.s=function(){this.node.hasAttribute(n.K)&&(this.$=this.node.style.display,this.node.style.display="none");this.node.hasAttribute(n.J)?this.h=this.node.getAttribute(n.J):this.h="|";this.node.hasAttribute(n.o)?(this.R=this.node.getAttribute(n.o).replace(/[\s]+/g," ").split("").reverse().join("").split(this.Z).map(function(w){return w.split("").reverse().join("").replace("\\,",",")}).reverse(),this.text=this.node.innerHTML.replace(/[\s]+/g," "),this.g=-1):this.text=this.node.innerHTML.replace(/[\s]+/g,
" ");this.text=this.text.trim();for(var a=0,b;-1!=this.text.indexOf("${",a)||-1!=this.text.indexOf("$`",a);){b=this.text.indexOf("${",a);var c=this.text.indexOf("$`",a);if(-1<b&&(b<c||-1==c))c=this.text.substring(b+2,this.text.indexOf("}",b)),this.m["default"][b]=Number(c),this.text=this.text.replace(this.text.substring(b,this.text.indexOf("}",b)+1),""),a+=1;else if(-1<c&&(c<b||-1==b)&&(b=c,c=this.text.indexOf("`",b+2),-1!=c)){var e=c-b-2;this.i["default"][b]=c-1;this.node.hasAttribute(n.O)&&(this.i["default"][b+
e]=b);this.text=this.text.replace(this.text.substring(b,c+1),this.text.substring(b+2,c));a+=c}}if(this.node.hasAttribute(n.o))for(a=0;a<this.R.length;a++){b=this.R[a];this.m[a]=[];this.i[a]=[];c=0;for(e=void 0;-1!=b.indexOf("${",c)||-1!=b.indexOf("$`",c);){e=b.indexOf("${",c);var g=b.indexOf("$`",c);-1<e&&(e<g||-1==g)?(g=b.substring(e+2,b.indexOf("}",e)),this.m[a][e]=g,b=b.replace(b.substring(e,b.indexOf("}",e)+1)," "),c+=2):-1<g&&(g<e||-1==e)&&(e=g,g=b.indexOf("`",e+2),this.i[a][e+1]=g-1,this.node.hasAttribute(n.O)&&
(this.i[a][g]=e+1),b=b.replace(b.substring(e,g+1),b.substring(e+2,g)),c+=g+1)}this.l[a]=b+" "}this.index=this.speed=0;this.reverse=!1;p(this)};function p(a){a.speed=1E3/(2*Math.random()+5.5);a.node.hasAttribute(n.M)?a.speed=1E3/parseFloat(a.node.getAttribute(n.M)):a.node.hasAttribute(n.L)&&(a.speed=1E3/(3*Math.random()+(parseFloat(a.node.getAttribute(n.L))-1)))}
d.j=function(){var a=this,b=0;if(this.P||!this.node.hasAttribute(n.V))this.node.innerHTML=" ",this.node.hasAttribute(n.N)&&(b=1E3*parseFloat(this.node.getAttribute(n.N))),this.node.hasAttribute(n.K)&&(this.node.style.display=this.$),this.node.hasAttribute(n.v)&&this.node.getAttribute(n.v).split(",").forEach(function(c){(c=k(n,c))&&c.H&&(l(c),c.s())}),q(this,b,function(){a.animate();a.H=!0})};
function l(a){clearTimeout(a.timeout);clearInterval(a.interval);a.timeout=-1;a.node.innerHTML=a.innerHTML;a.H=!1}d.B=function(){clearTimeout(this.timeout);this.timeout=-1};d.C=function(){p(this);this.timeout=this.setTimeout(this.animate,this.speed)};
d.animate=function(){var a=this;if(-1!=this.timeout)if(void 0!=this.m[0>this.g?"default":this.g][this.index]&&!this.wait){var b=this.m[0>this.g?"default":this.g][this.index];this.node.innerHTML=this.text.substring(0,this.index)+" ";this.reverse&&this.node.hasAttribute(n.X)?(b*=1E3,this.index--):this.reverse?(b=0,this.index--):(b*=1E3,this.index++);0>=this.index||this.index>=this.text.length?r(this):q(this,b,function(){a.animate()})}else if(!this.wait)if(void 0!=this.i[0>this.g?"default":this.g][this.index])b=
this.i[0>this.g?"default":this.g][this.index],this.reverse&&b<this.index?(this.node.innerHTML=this.text.substring(0,b),this.index=b-1):!this.reverse&&b>this.index&&(this.node.innerHTML=this.text.substring(0,b),this.index=b+1),0>=this.index||this.index>=this.text.length?r(this):(this.node.innerHTML+=this.h,t(this));else{b=this.text.substring(0,this.index);this.node.innerHTML=0!=b.trim().length?b:" ";if(this.reverse){if(0>=b.length){r(this);return}var c=b.substr(b.length-1,1);">"==c?(c=this.text.substring(b.length,
b.lastIndexOf("<",b.length)),b=b.substr(0,b.length-c.length),this.index-=c.length):";"==c?(c=this.text.substring(b.length,b.lastIndexOf("&",b.length)),b=b.substr(0,b.length-c.length),this.index-=c.length):(b=b.substring(0,b.length-1),this.index--)}else{if(b.length>=this.text.length){r(this);return}c=this.text.substr(b.length,1);"<"==c?c=this.text.substring(b.length,this.text.indexOf(">",b.length)+1):"&"==c&&(c=this.text.substring(b.length,this.text.indexOf(";",b.length)+1));this.index+=c.length;b+=
c}b+=this.h;this.node.innerHTML=b;t(this)}};
function r(a){a.reverse?a.node.hasAttribute(n.o)?a.g+1>=a.l.length?a.node.hasAttribute(n.u)&&(a.g=0,a.text=a.l[a.g],u(a,!1,0,!0)):(a.text=a.l[++a.g],u(a,!1,0,!0)):a.node.hasAttribute(n.u)&&u(a,!1,0,!0):a.node.hasAttribute(n.o)?a.g>=a.l.length-1&&!a.node.hasAttribute(n.D)&&!a.node.hasAttribute(n.u)?v(a):a.g>=a.l.length-1&&a.node.hasAttribute(n.D)?(a.g=0,a.text=a.l[a.g],u(a,!1,0,!0)):u(a,!0):a.node.hasAttribute(n.D)?u(a,!1,0,!0):a.node.hasAttribute(n.u)?(a.node.innerHTML+=a.h,u(a,!0)):v(a)}
function v(a){a.node.hasAttribute(n.v)?a.node.getAttribute(n.v).split(",").forEach(function(b){n.j(b,!0)}):a.node.hasAttribute(n.W)||x(a)}function u(a,b,c,e){a.reverse=b;a.index=void 0!=c?c:a.index;a.node.innerHTML=e?a.h:a.node.innerHTML;a.timeout=a.setTimeout(a.animate,a.speed)}function x(a){a.interval=a.setInterval(function(){a.node.innerHTML.replace(/'/g,'"')!=(a.text+a.h).replace(/'/g,'"')?a.node.innerHTML=a.text+a.h:a.node.innerHTML=a.text+"\u00a0".repeat(a.h.length)},500)}
function q(a,b,c){a.F=a.node.innerHTML;a.Y=a.setInterval(function(){a.node.innerHTML.replace(/'/g,'"')!=(a.F+a.h).replace(/'/g,'"')?a.node.innerHTML=a.F+a.h:a.node.innerHTML=a.F+"\u00a0".repeat(a.h.length)},500);a.setTimeout(function(){clearInterval(a.Y);c()},b)}function t(a){p(a);a.timeout=a.setTimeout(a.animate,a.speed)}d.setInterval=function(a,b){return setInterval(a.bind(this),b)};d.setTimeout=function(a,b){return setTimeout(a.bind(this),b)};var n=new f;document.querySelector("*["+n.U+"]")&&n.j();
window.A=n;window.A.j=n.j;window.A.B=n.B;window.A.C=n.C;window.A.S=n.S;console.log("WriteIt.js v2.0 loaded!, visit https://github.com/khushit-shah/WriteIt.js");