Skip to content

Commit

Permalink
Merge pull request #51 from AnBauer/master
Browse files Browse the repository at this point in the history
#39: Add option to close cheat sheet on ESC
  • Loading branch information
nlmueng authored Jul 28, 2017
2 parents 3cd62e1 + 9becfaf commit 7ab2a2e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export interface IHotkeyOptions {
* Key combination to trigger the cheat sheet. Default: '?'
*/
cheatSheetHotkey?: string;
/**
* Use also ESC for closing the cheat sheet. Default: false
*/
cheatSheetCloseEsc?: boolean;
/**
* Description for the cheat sheet hot key in the cheat sheet. Default: 'Show / hide this help menu'
*/
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-hotkeys",
"version": "2.0.1",
"version": "2.0.2",
"scripts": {
"lint": "tslint src/**/*.ts",
"test": "tsc && karma start",
Expand Down Expand Up @@ -33,16 +33,16 @@
"mousetrap": "^1.6.0"
},
"devDependencies": {
"@angular/common": "4.0.0-beta.6",
"@angular/compiler": "4.0.0-beta.6",
"@angular/compiler-cli": "4.0.0-beta.6",
"@angular/core": "4.0.0-beta.6",
"@types/core-js": "^0.9.35",
"codelyzer": "^0.0.28",
"rxjs": "^5.0.1",
"@angular/common": "4.2.5",
"@angular/compiler": "4.2.5",
"@angular/compiler-cli": "4.2.5",
"@angular/core": "4.2.5",
"@types/core-js": "0.9.41",
"codelyzer": "~3.0.1",
"rxjs": "^5.4.0",
"tslint": "^3.15.1",
"typescript": "2.1.5",
"zone.js": "0.7.2"
"typescript": "~2.3.3",
"zone.js": "^0.8.4"
},
"engines": {
"node": ">=0.8.0"
Expand Down
13 changes: 10 additions & 3 deletions src/cheatsheet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,16 @@ export class CheatSheetComponent implements OnInit, OnDestroy {
}

public ngOnInit(): void {
this.subscription = this.hotkeysService.cheatSheetToggle.subscribe(() => {
this.hotkeys = this.hotkeysService.hotkeys.filter(hotkey => hotkey.description);
this.toggleCheatSheet();
this.subscription = this.hotkeysService.cheatSheetToggle.subscribe((isOpen) => {
if(isOpen !== false) {
this.hotkeys = this.hotkeysService.hotkeys.filter(hotkey => hotkey.description);
}

if(isOpen === false) {
this.helpVisible = false;
} else {
this.toggleCheatSheet();
}
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/hotkey.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export interface IHotkeyOptions {
* Key combination to trigger the cheat sheet. Default: '?'
*/
cheatSheetHotkey?: string;

/**
* Use also ESC for closing the cheat sheet. Default: false
*/
cheatSheetCloseEsc?: boolean;
/**
* Description for the cheat sheet hot key in the cheat sheet. Default: 'Show / hide this help menu'
*/
Expand Down
14 changes: 13 additions & 1 deletion src/hotkeys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ export class HotkeysService {
this.add(new Hotkey(
this.options.cheatSheetHotkey || '?',
function (event: KeyboardEvent) {
this.cheatSheetToggle.next({});
this.cheatSheetToggle.next();
}.bind(this),
[],
this.options.cheatSheetDescription || 'Show / hide this help menu',
));
}

if(this.options.cheatSheetCloseEsc) {
this.add(new Hotkey(
'esc',
function (event: KeyboardEvent) {
this.cheatSheetToggle.next(false);
}.bind(this),
['HOTKEYS-CHEATSHEET'],
'Hide this help menu',
));
}

}

add(hotkey: Hotkey | Hotkey[], specificEvent?: string): Hotkey | Hotkey[] {
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true
"declaration": true,
"lib": [
"es2016",
"dom"
]
},
"angularCompilerOptions": {
"genDir": "compiled"
Expand Down

0 comments on commit 7ab2a2e

Please sign in to comment.