var API,Q,E,D,global=this;if(API&&API.attachListener&&Function.prototype.apply){(function(){var C=API.attachListener;var J=API.cancelDefault;var I=[];var G=[];var B;var A;var H={"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};var F=function(N,X){var R=X.onchar;var P=X.onkey;var L=X.onshortcutchar;var T=X.onnavkeypress;var M=X.callbackContext;var O=X.suppressControlKeyAutoRepeat;var U,W=0,V,K=0;C(N,"keypress",function(a){var Y,b,Z;if(!a){a=(((this.ownerDocument&&this.ownerDocument.parentWindow)||this.parentWindow)||global.window).event}b=a.which;Z=a.keyCode;Y=typeof b=="number"?b:Z;if(a.charCode===0&&Y!=8&&Y!=13){Y=0}I[Y]=true;if(Y>31||Y==13||Y==8){if(L&&(a.ctrlKey||a.metaKey)&&(a.ctrlKey!==a.metaKey)&&!a.altKey&&!a.shiftKey){A=true;L.apply(M||this,[a,(Y>96&&Y<123)?Y-32:Y]);return }if(!a.ctrlKey&&!a.altKey&&!a.metaKey){if(U!=Y||(Y!=35&&Y!=36&&Y!=45&&Y!=46)){if(R.apply(M||this,[a,Y])===false){return J(a)}return }}}else{if(!Y&&!O){if(Z!=27&&Z!=9){if(V==Z){K++}if(typeof B=="undefined"){if(W){B=K?"both":"down"}else{if(K){B="press"}}}}if(B=="press"&&K>1){P.apply(M||this,[a,Z])}if(Z!=27&&Z!=9){V=Z}if(Z>36&&Z<41||(Z==33||Z==34)||Z==27){if(T){if(T.apply(M||this,[a,Z])===false){return J(a)}}}}}});var S=function(c){var Z,b,Y;if(!c){c=(((this.ownerDocument&&this.ownerDocument.parentWindow)||this.parentWindow)||global.window).event}Z=typeof c.which=="number"?c.which:c.keyCode;Z=H[Z]||Z;if(c.type=="keyup"){if(Z==8&&!I[8]||Z==13&&!I[13]){R.apply(M||this,[c,Z])}else{if(!c.shiftKey&&!c.ctrlKey&&!c.metaKey&&((Z==189&&!I[45])||(Z==190&&!I[46]))){R.apply(M||this,[c,Z-144])}else{if(!A&&(c.ctrlKey||c.metaKey)&&(c.ctrlKey!==c.metaKey)&&(Z>47&&Z<91||Z==13)&&!c.altKey&&!c.shiftKey){L.apply(M||this,[c,Z])}}}if(G[Z]){b=new Date().getTime()-G[Z]}}else{var a=new Date().getTime();if(O){if(G[Z]){return }}else{if(U===Z&&Z!=27&&Z!=9){W++}}if(B=="press"){K=0}if(U!==Z||!W){G[Z]=a}U=Z}if(!W||B!="press"||c.type=="keyup"){Y=P.apply(M||this,[c,Z,b])}if(c.type=="keyup"){G[Z]=U=V=W=K=0}if(Y===false){return J(c)}};C(N,"keyup",S);C(N,"keydown",S);N=null};API.attachKeyboardListeners=F;if(E&&E.prototype){E.prototype.onKeyboard=function(K){F(this.element(),K)}}if(D&&D.prototype){D.prototype.onKeyboard=function(K){F(this.node(),K)}}if(Q&&Q.prototype){Q.prototype.onKeyboard=function(K){this.forEach(function(L){F(L,K)})}}})()}