This repository has been archived by the owner on May 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
t.min.js
2 lines (2 loc) · 7.23 KB
/
t.min.js
1
2
/*t.js-1.3.1;(c)2014-2018 - Mntn(r) <https://mn.tn/> c/o Benjamin Lips <g--[AT]--mn.tn>;MIT-Licensed <https://mit-license.org/>;For documentation, see <https://mntn-dev.github.io/t.js/>*/
;(function(c){c.fn.t=function(p,B){return this.each(function(){var a=B,l=p,b=c(this),r,t,u=-1,n=!1,y=-1,w="12qwertyuiop[]asdfghjkl;zxcvbnm,./~!@#$%^&*()_+:1234567890-=op".split([]),e=function(a,b){return c.type(a)[0]==(b||"n")},z=function(){g=c.grep(k,function(a){return"&"==a[0]||!a[1]}).length-1;return-1<g?g:0},x=function(b){y!=b&&a.blink&&(a.blink_perm||m.parent().data("blinking",y=b?1:0))},f={c:0,beep:function(){0==f.c&&(f.c=c("html").data().__TAC);f.o&&f.o.stop();f.o=f.c.createOscillator();f.o.frequency.setValueAtTime(1,f.c.currentTime);f.g=f.c.createGain();f.o.connect(f.g);f.g.connect(f.c.destination);f.o.start();f.o.stop(f.c.currentTime+.03)}};if("beep"==l&&!b.data().is_typing&&c("html").data().__TAC)return f.beep(),this;""===l&&(l="<del>*</del>");if(b.data().is_typing)return l=="paused".slice(0,-1)&&(b.data("paused",e(a,"b")?oo_=a:b.data("paused")?oo_=!1:oo_=!0),b.data().blink&&b.data("blinking",oo_)),this;if(l=="paused".slice(0,-1))return this;b.data("is_typing",1);e(l,"o")&&(a=l);if(/t\-/.test(b.attr("class")))return this;if("add"==l&&b.data().t){var q=a;a=c.extend({},b.data());var m=b=c(":first",b),A=e(a.typing,"f");q="<"+a.tag+' class="typing-add">'+q+"</"+a.tag+">"}else{"add"==l&&(l=a,a={});a=c.extend({t:!0,delay:!1,speed:50,speed_vary:!1,caret:"\u258e",tag:"span",blink:!0,beep:!1,blink_perm:!1,repeat:-3,pause_on_click:!1,pause_on_tab_switch:0,wrap:!1,mistype:!1,locale:"en",init:!1,typing:!1,fin:!1},a?a:b.data());q=t=!1;var d;b.data().t||(b.wrapInner(c("<"+a.tag+"/>",{"class":"t-container",style:"top:auto;bottom:auto;"})),/^[ar]/.test(b.css("position"))||b.css({position:"relative"}),b.css({overflow:"hidden"}));a.wrap&&!b.parent().data().t_wrap&&(b.wrap(c("<div/>",/[.#]/.test(a.wrap[0])?"#"==a.wrap[0]?{id:a.wrap.substr(1)}:{"class":a.wrap.substr(1)}:{style:a.wrap})),b.parent().data("t_wrap",1));e(a.beep,"b")||(a.beep=!1);!0===a.beep&&e(c("html").data().__TAC,"u")&&(c("html").data("__TAC",__TAC=(window.AudioContext=window.AudioContext||window.webkitAudioContext)?new AudioContext:!1),__TAC||(a.beep=!1));!1===a.repeat&&(a.repeat=-3);!0===a.caret&&(a.caret="\u258e");e(a.caret,"s")&&!c(".t-caret",b)[0]&&(!0===a.blink&&(a.blink=3*a.speed),e(a.blink)&&100>a.blink&&(a.blink=100),!e(a.blink)&&(a.blink=!1),t=c("<"+a.tag+"/>",{"class":"t-caret",html:a.caret}).appendTo(b),a.blink&&b.append("\u200b")&&b.data("bi",setInterval(function(){(m.parent().data().blinking|(v="h"==t.css("visibility")[0])||a.blink_perm)&&t.css({visibility:v?"visible":"hidden"})},a.blink)));a.blink||b.data().bi&&clearInterval(b.data().bi)&&b.removeData("bi");!e(a.blink_perm,"b")&&(a.blink_perm=!0);a.speed=!e(a.speed)||10>a.speed?10:a.speed;a.speed_vary&&(a.speed/=2.5);1<a.mistype||(a.mistype=!1);b.data(a);c(".typing-0",b).replaceWith(function(){return this.childNodes});c(".typing-add",b).remove();m=b=c(":first",b);var k=e(l,"s")?l:b.html();""==k&&(k="\u200b");b.empty();m.parent().show().css({visibility:"visible"});e(a.delay)&&0<a.delay&&(d=~~(1E3*a.delay/a.speed))&&a.blink_perm||x(1);A=e(a.typing,"f");!0===a.pause_on_click&&b.parent().off("click").click(function(a){"1"!=c(a.target).data().click&&c(this).t("pause")});!0===a.pause_on_tab_switch?e(c("html").data().__TAB,"u")&&(c("html").data("__TAB",1),c(document).on("visibilitychange",function(){c(".t-container").parent().each(function(){h=c(document).attr("visibilityState").charAt(0);"h"==h&&c(this).data().paused&&c(this).data("keep_paused",1);c(this).p("h"==h?!0:c(this).data().keep_paused&&c(this).removeData("keep_paused")?!0:!1)})})):!1===a.pause_on_tab_switch&&c("html").data().__TAB&&(c("html").removeData("__TAB"),c(document).off("visibilitychange"))}/<kbd.*?>/i.test(k=String(q||k))&&b.parent().data("kbd",j_=1)&&b.parent().data("mistype",b.parent().data("mistype")?_j=b.parent().data().mistype:_j=10)&&(a.mistype=_j)&&(a.kbd=j_?j_:!1);k=k.replace(/(.*?)[\u200b]+$/,"$1").replace(/<!\-\-([\s\S]+?)\-\->/g,"$1").replace(/<ins>([^0-9])<\/ins>/g,"$1").replace(/<(embed|command|col|wbr|img|br|input|hr|area|source|track|keygen|param)(.*?)[\/]?>/g,"<#$1$2/>").replace(/<ins>\s*(\d*[.]?\d*)\s*(<\/ins>)/g,'<ins data-ins="$1"></ins>').replace(/<ins(.*?)>([\s\S]*?)(<\/ins>)/g,function(a,b,c){return"<#ins"+b+">"+c.replace(/<(?!#)/g,"<#")+"<#/ins>"+(c?"":"</ins>")}).replace(/<(del.*?data-del=")(.*?)(".*?)><\/(del>)/g,"<#$1$2$3><#/$4$2</$4").replace(/<del(.*?)>([\s\S]*?)<\/del>/g,function(a,b,c,d){s=(s=c.match(/<s>\s*(.*?)\s*<\/s>/i))&&s[0]?' data-s="'+(s[1]||"1")+'"':"";i=(i=c.match(/data-ins="(.*?)"/))&&i[1]?i[1]:""==s?.25:.75;c=c.replace(/(<s>.*?<\/s>|<[\/]?.*?>)/g,"");return"<del"+b+s+' data-del="'+c.replace(/\n/,"\\n")+'" data-ins="'+i+'">'+("*"!=c?c:"")+"</del>"}).replace(/<(\w+)(.*?)>/g,"<$1$2><#/$1>").replace(/<\/(\w+)>/g,"</> ($1)").replace(/<[#]+/g,"<").replace(/(\/del>)\*</g,"$1<").match(/<ins.*?>[\s\S]*?<\/ins>|<[^<]+\/>|<\/> \(\w+\)|<[\s\S]+?><\/\w+>|&[#x]?[a-z0-9]+;|\r|\n|\t|\S|\s/ig);!e(d)&&(d=k.shift());k.push("\u200b");"de"==a.locale&&(w='12qwertzuiop\u00fc+asdfghjkl\u00f6\u00e4#<yxcvbnm,.-!"\u00a7$%&/(()=?1234567890\u00df*p+');var C=z()+1;!q&&e(a.init,"f")&&a.init(m.parent());var D=setInterval(function(){if(m.parent().data("paused"))u=1;else if(!n){n=!n;if(e(d)){if(0<--d){n=!n;x(.25>=b.data().ins?0:1==u?u=-1:1);return}d=b.data().ins?"</>":k.shift()}else if(a.speed_vary&&~~(4*Math.random())){n=!n;return}x(0);if(b.data().del&&(!0===m.parent().data().beep&&f.beep(),b.data().s&&!d[0]&&b.text(""),r=String(b.data().del),!e(d,"a")&&"/"==d[1]&&(d=r.replace(/\\n/g,"\n").split([])),e(d,"a"))){if(u=d.pop()){b.data().s?b.html(d.join([])+"<mark "+("."==(_=String(b.data().s))[0]?'class="'+_.substr(1)+'"':'style="background:'+("1"==_?"yellow":_.split(",")[0])+((_=_.split(",")[1])?";color:"+_:"")+';"')+">"+b.data().del.substr(d.length)+"</mark>"):b.text(d.join([]));n=!n;return}"*"==r&&(m.wrapInner(c("<"+a.tag+"/>",{"class":"typing-0",style:"display:none;"})),b=b.parent(),q&&(k=c.merge(["<"+a.tag+' class="typing-add"></'+a.tag+">"],k,["</"+a.tag+">"]),b=b.parent()));b=b.parent();"\u200b"==r&&b.find(":last").remove();d=""}for(;"/"==d[1];)b=b.parent(),d=k.shift()||"";for(;;)if(!0===m.parent().data().beep&&f.beep(),b.append(d),A&&a.typing(m.parent(),d,z(),C),!/<ins.*?>[\s\S]+</.test(d)&&/></.test(d)&&(b=b.find(":last")),k[0]&&/<\w+/.test(k[0]))d=k.shift();else break;(d=k.shift())?((a.mistype&&!a.kbd||a.kbd&&/kbd/i.test(b.prop("tagName")))&&d&&!d[1]&&"\u200b"!=b.data().del&&" "!=d&&!~~(Math.random()*a.mistype)&&-1<(__=c.inArray(d.toLowerCase(),w,2))&&(__+=~~(2*Math.random())+1,~~(2*Math.random())&&(__-=3),k=c.merge([90>d.charCodeAt(0)?w[__].toUpperCase():w[__],"</del>",d],k),d='<del data-ins=".25" data-del="\u200b"></del>'),d&&"/"==d[1]&&b.data().ins&&(d=~~(1E3*Number(b.data().ins)/a.speed)),n=!n):(clearInterval(D),m.parent().removeData(["is_typing","paused"]),e(a.repeat)&&--a.repeat,-1<a.repeat?(a.init=!1,m.parent().t(e(l,"o")?a:l,a)):(x(1),e(a.fin,"f")&&a.fin(m.parent())))}},a.speed)})};c.fn.a=function(p){return this.each(function(){c(this).data().t&&c(this).t("add",p)})};c.fn.p=function(p){return this.each(function(){c(this).data().is_typing&&c(this).t("pause",p?!1===p||!0===p?p:void 0:void 0)})};c.fn.b=function(p){return this.each(function(){c(this).t("beep")})}})(jQuery);