motto
Version:
Show your motto in an amazing way!
1 lines • 1.58 kB
JavaScript
(function(c,a,d){var b=function(f,e){this.el=a.querySelectorAll(f)[0];this.config=e||{};this.lyric=e.lyric||"";this.newLyric="";this.showUpSpeed=e.showUpSpeed||0;this.flashSpeed=e.flashSpeed||0;this.flashTimeout=e.flashTimeout||0;this.showOut()};b.prototype={showOut:function(){var f=this,g=0,e,h="";if(f.flashSpeed){f.newLyric=e=f.replaceFun(f.lyric,f.lyric.split(""))}else{f.newLyric=e=f.lyric}if(f.showUpSpeed){var j=setInterval(function(){h+=e.split("")[g];g++;f.newLyric=h;f.el.innerHTML=h;f.el.dataset.text=h;if(f.lyric.split("").length===g){clearInterval(j);setTimeout(function(){f.flash(f.newLyric)},f.flashTimeout)}},f.showUpSpeed)}else{f.el.innerHTML=e;f.el.dataset.text=e;setTimeout(function(){f.flash(f.newLyric)},f.flashTimeout)}},replaceFun:function(f,e){return f.split("").map(function(h){var g=e.filter(function(j,i){return e.indexOf(j)==i});return h=g[Math.floor((Math.random()*g.length))]}).join("")},flash:function(){var f=this,e=f.lyric.split(""),h=f.newLyric.split(""),g=f.flashSpeed;var i=setInterval(function(){if(h.join("")!==e.join("")){for(var j in e){if(h[j]!==e[j]){var k=e.filter(function(m,l){return e.indexOf(m)==l});h[j]=k[Math.floor((Math.random()*k.length))];f.el.innerHTML=f.el.dataset.text=h.join("")}}}else{clearInterval(i);f.callback()}},g)},callback:function(){if(this.config.callback){this.config.callback()}}};if(typeof module==="object"&&typeof module.exports==="object"){module.exports=exports=b}else{if(typeof define==="function"&&define.amd){define(function(){return b})}else{if(typeof c==="object"){c.Motto=b}}}})(window,document);