forked from Jaware/angular-hotkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-hotkeys.min.js
3 lines (3 loc) · 2.45 KB
/
angular-hotkeys.min.js
1
2
3
/*! angular-hotkeys v0.2.1 */
!function(){"use strict";var a=angular.module("drahak.hotkeys",[]);a.directive("hotkey",["$parse","$hotkey","HotKeysElement",function(a,b,c){return{restrict:"AE",link:function(d,e,f){var g=d.$eval(f.hotkey||f.bind);if(angular.isUndefined(g)){var h=a(f.invoke);g={},g[f.hotkey||f.bind]=function(a){h(d,{$event:a})}}var i="hotkey"!==e[0].nodeName.toLowerCase(),j=i?c(e):b;angular.forEach(g,function(a,b){j.bind(b,a)})}}}]),a.factory("HotKeysElement",["$window","HotKeys",function(a,b){var c={93:91},d=null,e=function(a){return d=a.keyCode,"undefined"!=typeof c[d]?c[d]:d};return function(c){var d=[],f=null,g=angular.element(c),h=angular.element(a),i=g.scope(),j=b();return i&&(i.$hotKeys=j),h.bind("blur",function(){d=[]}),g.bind("keydown",function(a){f=e(a),-1===d.indexOf(f)&&d.push(f),j.trigger(d,[a])}),g.bind("keyup",function(a){d.splice(d.indexOf(e(a)),1)}),j}}]),a.factory("HotKeys",["ParseKey","$rootScope",function(a,b){var c=function(){this._hotKeys={}};return c.prototype._getHotKeyIndex=function(b){var c;if(angular.isString(b))c=a(b);else{if(!angular.isArray(b))throw new Error("HotKey expects hot key to be string expression or key codes array, "+typeof b+" given.");c=b}return c.sort().join("+")},c.prototype.bind=function(a,b){return a=this._getHotKeyIndex(a),this._hotKeys[a]||(this._hotKeys[a]=[]),this._hotKeys[a].push(b),this},c.prototype.unbind=function(a){return a=this._getHotKeyIndex(a),this._hotKeys[a]=[],this},c.prototype.trigger=function(a,c){c=c||[],a=this._getHotKeyIndex(a),angular.forEach(this._hotKeys[a],function(a){a.apply(a,c)}),b.$$phase||b.$apply()},function(){return new c}}]),a.factory("$hotkey",["$window","HotKeysElement",function(a,b){return b(a)}]),a.value("keyAlias",{backspace:8,"return":8,tab:9,tabulator:9,enter:13,shift:16,ctrl:17,control:17,alt:18,esc:27,escape:27,left:37,up:38,right:39,down:40,insert:45,del:46,"delete":46}),a.run(["$window","keyAlias",function(a,b){var c=a.navigator.userAgent.toLowerCase(),d=c.indexOf("firefox")>-1,e=c.indexOf("opera")>-1,f=d?224:e?17:91;b.command=f,b.cmd=f}]),a.service("ParseKey",["$window","keyAlias",function(a,b){return function(a){var c=[],d=a.split("+");return angular.forEach(d,function(a){if(a=a.trim().toLowerCase(),"undefined"!=typeof b[a])c.push(b[a]);else{if(1!==a.length)throw new Error('ParseKey expects one character or special expression like "Tab" or "Control", "'+a+'" given');c.push(a.toUpperCase().charCodeAt(0))}}),c}}])}();
//# sourceMappingURL=angular-hotkeys.js.map