Headless CMS and Content Managment Hub
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.
 
 
 
 
 

28 lines
695 B

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Injectable } from '@angular/core';
import * as Mousetrap from 'mousetrap';
@Injectable()
export class ShortcutService {
public listen(keys: string, callback: (e: KeyboardEvent, combo: string) => void): () => void {
const trimmed = keys.toLowerCase().replace(/\s/g, '').split(',');
Mousetrap.bind(trimmed, (event: any, combo: any) => {
return callback(event, combo);
});
return () => {
Mousetrap.unbind(trimmed);
};
}
public raise(keys: string) {
Mousetrap.trigger(keys);
}
}