mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Sebastian Stehle. All rights reserved
|
|
*/
|
|
|
|
import { Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output } from '@angular/core';
|
|
|
|
import { ShortcutService } from './../services/shortcut.service';
|
|
|
|
@Component({
|
|
selector: 'sqx-shortcut',
|
|
template: ''
|
|
})
|
|
export class ShortcutComponent implements OnInit, OnDestroy {
|
|
@Input()
|
|
public keys: string;
|
|
|
|
@Input()
|
|
public disabled: boolean;
|
|
|
|
@Output()
|
|
public trigger = new EventEmitter();
|
|
|
|
private lastKeys: string;
|
|
|
|
constructor(
|
|
private readonly shortcutService: ShortcutService,
|
|
private readonly zone: NgZone
|
|
) {
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.lastKeys = this.keys;
|
|
|
|
if (this.lastKeys) {
|
|
this.shortcutService.on(this.lastKeys, e => {
|
|
if (!this.disabled) {
|
|
this.zone.run(() => {
|
|
this.trigger.next(e);
|
|
});
|
|
}
|
|
|
|
return false;
|
|
});
|
|
}
|
|
}
|
|
public ngOnDestroy() {
|
|
if (this.lastKeys) {
|
|
this.shortcutService.off(this.lastKeys);
|
|
}
|
|
}
|
|
}
|