UNPKG

1.1 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2013-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 */
8
9'use strict';
10
11/**
12 * Translation from modifier key to the associated property in the event.
13 * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
14 */
15
16var modifierKeyToProp = {
17 Alt: 'altKey',
18 Control: 'ctrlKey',
19 Meta: 'metaKey',
20 Shift: 'shiftKey'
21};
22
23// IE8 does not implement getModifierState so we simply map it to the only
24// modifier keys exposed by the event itself, does not support Lock-keys.
25// Currently, all major browsers except Chrome seems to support Lock-keys.
26function modifierStateGetter(keyArg) {
27 var syntheticEvent = this;
28 var nativeEvent = syntheticEvent.nativeEvent;
29 if (nativeEvent.getModifierState) {
30 return nativeEvent.getModifierState(keyArg);
31 }
32 var keyProp = modifierKeyToProp[keyArg];
33 return keyProp ? !!nativeEvent[keyProp] : false;
34}
35
36function getEventModifierState(nativeEvent) {
37 return modifierStateGetter;
38}
39
40module.exports = getEventModifierState;
\No newline at end of file