This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kbd.min.js
2 lines (2 loc) · 5.86 KB
/
kbd.min.js
1
2
/*$.kbd-0.5.1;(c)2018 - Mntn(r) <https://mn.tn/> c/o Benjamin Lips <g--[AT]--mn.tn>;MIT-Licensed <https://mit-license.org/>;For documentation, see <https://github.com/mntn-dev/kbd/>*/
;(function(b){b.kbd=function(d){if(void 0!==b("#_kbd")[0])return b.kbd.show();b("body").append('<div id="_kbd"><span id="_kbd_wrap"></span>'+(d.coffee?'<div id="_kbd_coffee"'+(!1!==d.white?"":' style="display:none;"')+"></div>":"")+'<div id="kbd-lock"></div></div>');!0===d.white&&b("#_kbd").addClass("_kbd_white");!0===d.toggle_btn&&(b("#_kbd_wrap").prepend('<button id="_kbd_btn">⌨</button>'),b("#_kbd_btn").click(function(){b("#_kbd").offset().top>b(document).height()?b.kbd.show():b.kbd.hide()}));var e=!1,l=!1,f="",m=function(b){c=b.data().c;cc=b.text();b.text(c);b.data("c",cc)},h=function(d){f=b("#__q").text();return 0===d?f.toLowerCase():f},g=function(){return void 0!==window.ontouchstart},k=function(d){g()&&setTimeout(function(d){d.removeClass("_kbd-h"+(b("#_kbd").hasClass("_kbd_white")?"-w":""))},100,d)};_k='q1w2e3r4t5y6u7i8o9p0__a@s#d$f_g&h-j+k(l)__{{\u25b2|data-c="\u25bc" class="l _caps"}}z/x%c*v,b"n!m?{{\u25c4|class="l" data-k="8"}}__{{123|data-c="ABC" class="l _alt"}}{{ |class="xl" data-k="32"}}{{OK|class="l" data-k="13"}}';_e={q:"1",w:"2",r:"4",t:"5",y:"6",i:"8",p:"0",a:"\u00e1\u00e0\u00e4",e:"\u00e9\u00e8\u00eb3",o:"\u00f3\u00f2\u00f69",u:"\u00fa\u00f9\u00fc7",d:"#\u00a5\u00a3\u20ac",s:"\u00df",z:"#\\",k:"#{[<",l:"#}]>",v:"#;:.",b:"#'"};!0===d.qwertz&&(_k=_k.replace("y","Z").replace("z","y").replace("Z","z"),__=_e.z,_e.z=_e.y,_e.y=__);_k=_k.split("__");for(j=0;j<_k.length;j++)for(__k=_k[j].match(/\{\{(.*?)\}\}|[\S]{2}/g),ii=__k.length,i=0;i<ii;i++)K=__k[i],"{"==K[0]&&(K=K.replace(/[\{\}]/g,"").split("|")),b("#_kbd_wrap").append("<button "+("o"!=(typeof K)[0]?'data-a="'+('"'==K[1]?""":K[1])+'"':K[1])+("q"==K[0]?' id="__q"':"")+">"+K[0]+"</button>"),void 0!==_e[K[0]]&&b("#_kbd_wrap button:last").wrap('<span class="_ext'+("#"!=_e[K[0]][0]?" _ext-"+(b.isNumeric(_e[K[0]])?"0":"1"):"")+'"></span>').parent().prepend('<span class="_ext-box" style="top:-'+(_e[K[0]]=_e[K[0]].replace("#","")).length+'00%;">'+_e[K[0]].replace(/([\S\s])/g,"<button>$1</button>")+"</span>");b("._caps").bind("mousedown touchstart",function(d){d.preventDefault();"q"==(f=h()).toLowerCase()&&(g()&&b(this).trigger("mouseenter",!0),e=setTimeout(function(b){b.addClass("_ext-caps");b.trigger("mouseup");e="%"},750,b(this)))}).bind("mouseup touchend",function(d){d.preventDefault();k(b(this));if("q"!=(f=h()).toLowerCase()||"%"==e)return e=!1;e&&clearTimeout(e);m(b(this));"Q"==f&&b(this).hasClass("_ext-caps")&&b(this).removeClass("_ext-caps");C="Q"==f?!1:!0;b("#_kbd button").each(function(){(void 0!==b(this).data().a||b(this).parent().hasClass("_ext-box"))&&b(this).text(C?b(this).text().toUpperCase():"SS"==b(this).text()?"\u00df":b(this).text().toLowerCase())})});b("._alt").click(function(){m(b(this));"Q"==h()&&(m(b("._caps")),b("._caps").removeClass("_ext-caps"));g()&&(b(this).trigger("mouseenter",!0),k(b(this)));b("#_kbd button").each(function(){void 0!==(a=b(this).data().a)&&(b(this).data("a",b(this).text().toLowerCase()),b(this).text(a))});b("._ext:not(._ext-0)").toggleClass("_ext-1")}).bind("touchstart",function(){b(this).trigger("mouseenter",!0)});b(__="button[data-a],button[data-k],._ext-box button").bind("mouseup touchend",function(n,p){n.preventDefault();e&&!p&&(clearTimeout(e),clearInterval(e));g()&&b(this).prev("._ext-box").is(":visible")||("f"==(typeof d.input)[0]&&d.input(b(this).data().k?String.fromCharCode(b(this).data().k):b(this).text()),"Q"!=h()||b("._caps").hasClass("_ext-caps")||b("._caps").trigger("mouseup"),k(b(this)))}).bind("touchstart",function(){b(this).trigger("mouseenter",!0)});b(__+",._caps,._alt").hover(function(d,e){g()&&void 0===e||b(this).addClass("_kbd-h"+(b("#_kbd").hasClass("_kbd_white")?"-w":""))},function(){g()||b(this).removeClass("_kbd-h"+(b("#_kbd").hasClass("_kbd_white")?"-w":""))});b("button[data-k]").bind("mousedown touchstart",function(d){d.preventDefault();e=setTimeout(function(b){e=setInterval(function(){b.trigger("mouseup",!0)},50,b)},200,b(this))});b("._ext").bind("mousedown touchstart",function(d){d.preventDefault();if(b(this).hasClass("_ext-1")||b(this).hasClass("_ext-0")&&"q"==h(0))e=setTimeout(function(b){b.find("._ext-box").show()},750,b(this)),g()&&(l=setTimeout(function(b){b.find("._ext-box").hide();k(b.children("button"))},3E3,b(this)))}).bind("mouseup mouseleave",function(d){d.preventDefault();b(this).find("._ext-box:visible").hide();e&&clearTimeout(e)});b("._ext-box button").bind("touchend",function(){l&&clearTimeout(l);b(this).parent().hide();k(b(this).parent().parent().children("button"))});!0!==d.hidden&&b.kbd.show()};b.kbd.hide=function(){b("#_kbd").stop().animate({bottom:"-100%"},250);void 0!==b("#_kbd_btn")[0]&&b("#_kbd_btn").css({position:"fixed",top:"auto",bottom:0})};b.kbd.show=function(){void 0!==b("#_kbd_btn")[0]&&0!==parseInt(b("#_kbd").css("bottom"))&&b("#_kbd_btn").css({position:"absolute",bottom:"auto",top:"-25%"});b("#_kbd").stop().animate({bottom:0},250)};b.kbd.white=function(d){!0!==d&&void 0!==d||b("#_kbd").hasClass("_kbd_white")?!1===d&&b("#_kbd").hasClass("_kbd_white")&&(b("#_kbd").removeClass("_kbd_white"),void 0!==b("#_kbd_coffee")[0]&&b("#_kbd_coffee").css({display:"none"})):(b("#_kbd").addClass("_kbd_white"),void 0!==b("#_kbd_coffee")[0]&&b("#_kbd_coffee").css({display:"block"}))};b.kbd.caps=function(d){q=b("#__q").text();!0===d&&"q"==q?b("._caps").addClass("_ext-caps").trigger("mouseup"):!1===d&&"Q"==q?b("._caps").removeClass("_ext-caps").trigger("mouseup"):void 0===d&&b("._caps").trigger("mouseup")};b.kbd.alt=function(d){q=b("#__q").text();!0===d&&"q"==q.toLowerCase()?b("._alt").trigger("click"):!1===d&&"1"==q?b("._alt").trigger("click"):void 0===d&&b("._alt").trigger("click")};b.kbd.lock=function(d){!0===d||void 0===d?b("#kbd-lock").show():!1===d&&b("#kbd-lock").hide()};b.BS=String.fromCharCode(8);b.OK=String.fromCharCode(13)})(jQuery);