-
Notifications
You must be signed in to change notification settings - Fork 14
/
mylib-keyboard-min.js
1 lines (1 loc) · 2.45 KB
/
mylib-keyboard-min.js
1
var API,Q,E,D,global=this;if(API&&API.attachListener&&Function.prototype.apply){(function(){var G=API.attachListener;var J=API.cancelDefault;var F=[];var A=[];var I;var B;var K={"63232":38,"63233":40,"63234":37,"63235":39,"63236":112,"63237":113,"63238":114,"63239":115,"63240":116,"63241":117,"63242":118,"63243":119,"63244":120,"63245":121,"63246":122,"63247":123,"63273":36,"63275":35,"63276":33,"63277":34};function H(N,M,L,O){return((N.ctrlKey||N.metaKey)&&(N.ctrlKey!==N.metaKey)&&((M>47&&M<91)||M==13)&&(O||!N.altKey)&&(L||!N.shiftKey))}var C=function(P,c){var S=c.onchar,R=c.onkey;var M=c.onshortcutchar;var b=c.onbeforeshortcutchar;var X=c.onnavkeypress;var N=c.callbackContext;var O=c.suppressControlKeyAutoRepeat;var U=c.allowShiftCombinations,W=c.allowAltCombinations;var Y,a=0,Z,L=0;var V;G(P,"keypress",function(g){var d;var h=g.which;var f=g.keyCode;d=typeof h=="number"?h:f;if(g.charCode===0&&d!=8&&d!=13){d=0}F[d]=true;if(d>31||d==13||d==8){if(M&&H(g,(V=(d>96&&d<123)?d-32:d),U,W)){B=true;M.apply(N||this,[g,V]);return }if(!g.ctrlKey&&!g.altKey&&!g.metaKey){if(Y!=d||(d!=35&&d!=36&&d!=45&&d!=46)){if(S.apply(N||this,[g,d])===false){return J(g)}return }}}else{if(!d&&!O){if(f!=27&&f!=9){if(Z==f){L++}if(typeof I=="undefined"){if(a){I=L?"both":"down"}else{if(L){I="press"}}}}if(I=="press"&&L>1){R.apply(N||this,[g,f])}if(f!=27&&f!=9){Z=f}if(f>36&&f<41||(f==33||f==34)||f==27){if(X){if(X.apply(N||this,[g,f])===false){return J(g)}}}}}});var T=function(i){var f,h,d;f=typeof i.which=="number"?i.which:i.keyCode;f=K[f]||f;if(i.type=="keyup"){if((f==8&&!F[8]||f==13&&!F[13])&&!i.shiftKey&&!i.ctrlKey&&!i.metaKey&&!i.altKey){S.apply(N||this,[i,f])}else{if(((f==189&&!F[45])||(f==190&&!F[46]))&&!i.shiftKey&&!i.ctrlKey&&!i.metaKey&&!i.altKey){S.apply(N||this,[i,f-144])}else{if(M&&!B&&H(i,f,U,W)){M.apply(N||this,[i,f])}}}if(A[f]){h=new Date().getTime()-A[f]}}else{var g=new Date().getTime();if(O){if(A[f]){return }}else{if(Y===f&&f!=27&&f!=9){a++}}if(I=="press"){L=0}if(Y!==f||!a){A[f]=g}Y=f}if(!a||I!="press"||i.type=="keyup"){d=R.apply(N||this,[i,f,h])}if(i.type=="keyup"){A[f]=Y=Z=a=L=0}else{if(b&&H(i,f,U,W)){if(b.apply(N||this,[i,f])===false){d=false}}}if(d===false){return J(i)}};G(P,"keyup",T);G(P,"keydown",T);P=null};API.attachKeyboardListeners=C;if(E&&E.prototype){E.prototype.onKeyboard=function(L){C(this.element(),L)}}if(D&&D.prototype){D.prototype.onKeyboard=function(L){C(this.node(),L)}}if(Q&&Q.prototype){Q.prototype.onKeyboard=function(L){this.forEach(function(M){C(M,L)})}}})()}