Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81159 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule getEventModifierState
10
* @typechecks static-only
11
*/
12
13
"use strict";
14
15
/**
16
* Translation from modifier key to the associated property in the event.
17
* @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
18
*/
19
20
var modifierKeyToProp = {
21
'Alt': 'altKey',
22
'Control': 'ctrlKey',
23
'Meta': 'metaKey',
24
'Shift': 'shiftKey'
25
};
26
27
// IE8 does not implement getModifierState so we simply map it to the only
28
// modifier keys exposed by the event itself, does not support Lock-keys.
29
// Currently, all major browsers except Chrome seems to support Lock-keys.
30
function modifierStateGetter(keyArg) {
31
/*jshint validthis:true */
32
var syntheticEvent = this;
33
var nativeEvent = syntheticEvent.nativeEvent;
34
if (nativeEvent.getModifierState) {
35
return nativeEvent.getModifierState(keyArg);
36
}
37
var keyProp = modifierKeyToProp[keyArg];
38
return keyProp ? !!nativeEvent[keyProp] : false;
39
}
40
41
function getEventModifierState(nativeEvent) {
42
return modifierStateGetter;
43
}
44
45
module.exports = getEventModifierState;
46
47