-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotkey.min.js
1 lines (1 loc) · 1.67 KB
/
hotkey.min.js
1
var KeyHandler,_KEY_NAME;_KEY_NAME=["ctrlKey","altKey","metaKey","shiftKey"],KeyHandler=function(){function a(a,b){var c,d,e,f,g;for(this.key=a,this.callback=b,e=this.key.toUpperCase().split("+"),c=e.pop(),1===c.length&&(this.keyCode=c.charCodeAt(0)),2===c.length&&(this.keyCode=c.charCodeAt(1)+63),this.ctrlKey=!1,this.altKey=!1,this.metaKey=!1,this.shiftKey=!1,f=0,g=e.length;g>f;f++)d=e[f],this.ctrlKey=d.indexOf("CTR")>=0||this.ctrlKey,this.altKey=d.indexOf("ALT")>=0||this.altKey,this.metaKey=d.indexOf("MET")>=0||this.metaKey,this.shiftKey=d.indexOf("SHI")>=0||this.shiftKey}return a.keys=[],a.bind=function(b,c){var d,e,f,g,h;for(0===a.keys.length&&document&&document.addEventListener("keyup",function(b){var c,d,e,f,g,h,i,j,k;for(j=a.keys,k=[],f=0,h=j.length;h>f;f++)if(d=j[f],d.keyCode===b.keyCode){for(c=!0,g=0,i=_KEY_NAME.length;i>g;g++)e=_KEY_NAME[g],d[e]!==b[e]&&(c=!1);k.push(c?d.callback():void 0)}else k.push(void 0);return k},!1),g=b.split(" "),h=[],e=0,f=g.length;f>e;e++)d=g[e],h.push(this.keys.push(new a(d,c)));return h},a}(),angular.module("hotkey",[]).factory("KeyHandler",function(){return{bind:function(a,b){return KeyHandler.bind(a,b)}}}).directive("hotkey",["KeyHandler",function(a){return{restrict:"A",link:function(b,c,d){return d.ngClick?a.bind(d.hotkey,function(){return b.$apply(d.ngClick)}):a.bind(d.hotkey,function(){return c[0].focus()})}}}]).directive("enter",function(){return function(a,b,c){return b.bind("keydown",function(b){var d;return 13===b.keyCode?c.enter?a.$apply(c.enter):(b.preventDefault(),d=$("input,select,button").index(this)+1,$("input,select,button").eq(d).focus()):void 0})}}).directive("focus",function(){return function(a,b){return b[0].focus()}});