-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathturingtype.min.js
1 lines (1 loc) · 1.93 KB
/
turingtype.min.js
1
(function(){var t,i,e,n=function(t,i){return function(){return t.apply(i,arguments)}};e=Math.random,i=Math.floor,t=function(){function t(i,e,s){var h,r,o,l;return this.el=i,this.text=e,this.options=null!=s?s:{},this.clear=n(this.clear,this),this.type=n(this.type,this),this instanceof t?("string"==typeof this.el&&(this.el=document.querySelector(this.el)),this.len=this.text.length,this.i=0,o=this.options,h=o.accuracy,r=o.interval,this.callback=o.callback,this.accuracy=null!=h?h:this.accuracy,this["int"]=null!=r?r:this["int"],(l="textarea"===this.el.tagName.toLowerCase()||"input"===l)?(this.attr="value",this.el.focus()):this.attr="innerText",void this.type()):new t(this.el,this.text,this.options)}return t.prototype["int"]=100,t.prototype.accuracy=.95,t.prototype.keys="qwertyuiopasdfghjklzxcvbnm,./;-=[]".split(""),t.prototype.type=function(){return this.i===this.len+1?"function"==typeof this.callback?this.callback():void 0:e()>this.accuracy?(this.el[this.attr]=this.text.slice(0,this.i)+this.keys[i(e()*this.keys.length)],this.timer=setTimeout(function(t){return function(){return t.el[t.attr]=t.text.slice(0,t.i),t.timer=setTimeout(t.type,e()*t["int"]+.8*t["int"])}}(this),1.5*this["int"])):(this.el[this.attr]=this.text.slice(0,this.i++),this.timer=setTimeout(this.type,function(t){return function(){var i;return i=e()*t["int"]+.1*t["int"]," "===t.text[t.i]&&(i+=e()*t["int"]),"."!==t.text[t.i]&&","!==t.text[t.i]||(i+=e()*t["int"]*3),e()>.97&&(i+=2*t["int"]),e()>.95&&(i+=t["int"]),i}}(this)()))},t.prototype.pause=function(){return clearTimeout(this.timer),this.el[this.attr]},t.prototype.clear=function(t){if(null==t&&(t=this.len),t!==-2)return this.el[this.attr]=this.text.slice(0,this.i--),setTimeout(this.clear.bind(this,--t),e()*this["int"])},t}(),("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t:("undefined"!=typeof define&&null!==define?define.amd:void 0)?define(function(){return t}):window.TuringType=t}).call(this);