-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleTyper.min.js
4 lines (4 loc) · 1.71 KB
/
simpleTyper.min.js
1
2
3
4
(function(b){"function"===typeof define&&define.amd?define(["jquery"],b):"object"===typeof exports?module.exports=b(require("jquery")):jQuery?window.simpleTyper=b(jQuery):console.log("Could not detect jQuery. Exiting.")})(function(b){function d(a,b){return function(){b.call(a)}}var f={speed:100,cursorSpeed:500,cursorStopDelay:1E3,delay:0,random:.1},c={init:function(){b(".simpleTyper").each(function(a,c){c=b(c);a=Object.create(g);a.settings=b.extend({},f);a.elem=c;a.text=a.elem.attr("data-typer-text")||
"";for(var d in a.settings)(c=parseFloat(a.elem.attr("data-typer-"+d)))&&(a.settings[d]=c);a.id=e.length;a.elem.attr("data-typer-id",a.id);e.push(a)});return c},startAll:function(){for(var a=0;a<e.length;a++)e[a].startType();return c},settings:function(a){b.extend(f,a);return c},start:function(a){e[b(a).attr("data-typer-id")].startType();return c},stop:function(a){e[b(a).attr("data-typer-id")].stopType();return c}},e=[],g={chars:0,text:"",textTimer:void 0,cursorTimer:void 0,settings:{},startType:function(){this.startCursor();
setTimeout(d(this,this.type),this.settings.delay)},type:function(){this.chars++;this.elem.text(this.text.slice(0,this.chars+1));if(this.chars<=this.text.length){var a=this.settings.speed*(this.settings.random*(Math.random()-.5)+1);this.textTimer=setTimeout(d(this,this.type),a)}else setTimeout(d(this,this.stopCursor),this.settings.cursorStopDelay)},startCursor:function(){var a=this;a.elem.toggleClass("simpleTyperCursor");this.cursorTimer=setInterval(function(){a.elem.toggleClass("simpleTyperCursor")},
this.settings.cursorSpeed)},stopCursor:function(){clearInterval(this.cursorTimer);this.elem.removeClass("simpleTyperCursor")},stopType:function(){clearTimeout(this.textTimer);this.stopCursor()}};return c});