-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
platform.ts
49 lines (44 loc) · 1.45 KB
/
platform.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
/**
* The namespace for platform related utilities.
*/
export namespace Platform {
/**
* A flag indicating whether the platform is Mac.
*/
export const IS_MAC = !!navigator.platform.match(/Mac/i);
/**
* A flag indicating whether the platform is Windows.
*/
export const IS_WIN = !!navigator.platform.match(/Win/i);
/**
* A flag indicating whether the browser is IE.
*/
export const IS_IE = /Trident/.test(navigator.userAgent);
/**
* A flag indicating whether the browser is Edge.
*/
export const IS_EDGE = /Edge/.test(navigator.userAgent);
/**
* Test whether the `accel` key is pressed.
*
* @param event - The keyboard or mouse event of interest.
*
* @returns Whether the `accel` key is pressed.
*
* #### Notes
* On Mac the `accel` key is the command key. On all other
* platforms the `accel` key is the control key.
*/
export function accelKey(event: KeyboardEvent | MouseEvent): boolean {
return IS_MAC ? event.metaKey : event.ctrlKey;
}
}