ngx-hotkey
Version:
An easy way to use Hotkeys in Angular.
2 lines • 1.93 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("ngx-hotkey",["exports","@angular/core"],t):t(e["ngx-hotkey"]={},e.ng.core)}(this,function(e,t){"use strict";var o=function(e,t){this.shortcut=e,this.callback=t,this.altKey=!1,this.ctrlKey=!1,this.metaKey=!1,this.shiftKey=!1,this.aliases={ctrl:"control"};for(var o=e.replace(/ /g,"").toLowerCase().split("+"),r=0;r<o.length;r++){var i=o[r],i=this.aliases[i]||i;if(r!==o.length-1)switch(i){case"shift":this.shiftKey=!0;break;case"control":this.ctrlKey=!0;break;case"alt":this.altKey=!0;break;case"meta":this.metaKey=!0;break;default:console.error("They shortcut '"+e+"' is not valid!")}else this.key=i}},r=(i.prototype.add=function(e,t){this.hotkeys.push(new o(e,t))},i.prototype.remove=function(t){this.hotkeys=this.hotkeys.filter(function(e){return e.shortcut!==t})},i.prototype.checkKeyDown=function(e){for(var t=0;t<this.hotkeys.length;t++){var o=this.hotkeys[t];if(this.checkHotKey(e,o)&&!this.isTheSameLastHotkeyFired(o))return(this.lastHotkeyFired=o).callback(e)}return!1},i.prototype.onKeyUp=function(){return this.lastHotkeyFired=null,!1},i.prototype.checkHotKey=function(e,t){return e.altKey===t.altKey&&e.ctrlKey===t.ctrlKey&&e.metaKey===t.metaKey&&e.shiftKey===t.shiftKey&&e.key.toLowerCase()===t.key},i.prototype.isTheSameLastHotkeyFired=function(e){return e===this.lastHotkeyFired},i.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],i.ctorParameters=function(){return[]},i.ngInjectableDef=t.defineInjectable({factory:function(){return new i},token:i,providedIn:"root"}),i);function i(){this.hotkeys=[],document.addEventListener("keydown",this.checkKeyDown.bind(this),!1),document.addEventListener("keyup",this.onKeyUp.bind(this),!1)}e.NgxHotkeyService=r,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-hotkey.umd.min.js.map