aboutsummaryrefslogtreecommitdiff
path: root/node_modules/react-dom/lib/getEventModifierState.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/react-dom/lib/getEventModifierState.js')
-rw-r--r--node_modules/react-dom/lib/getEventModifierState.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/node_modules/react-dom/lib/getEventModifierState.js b/node_modules/react-dom/lib/getEventModifierState.js
new file mode 100644
index 000000000..c8a68fcb9
--- /dev/null
+++ b/node_modules/react-dom/lib/getEventModifierState.js
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2013-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ *
+ */
+
+'use strict';
+
+/**
+ * Translation from modifier key to the associated property in the event.
+ * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
+ */
+
+var modifierKeyToProp = {
+ 'Alt': 'altKey',
+ 'Control': 'ctrlKey',
+ 'Meta': 'metaKey',
+ 'Shift': 'shiftKey'
+};
+
+// IE8 does not implement getModifierState so we simply map it to the only
+// modifier keys exposed by the event itself, does not support Lock-keys.
+// Currently, all major browsers except Chrome seems to support Lock-keys.
+function modifierStateGetter(keyArg) {
+ var syntheticEvent = this;
+ var nativeEvent = syntheticEvent.nativeEvent;
+ if (nativeEvent.getModifierState) {
+ return nativeEvent.getModifierState(keyArg);
+ }
+ var keyProp = modifierKeyToProp[keyArg];
+ return keyProp ? !!nativeEvent[keyProp] : false;
+}
+
+function getEventModifierState(nativeEvent) {
+ return modifierStateGetter;
+}
+
+module.exports = getEventModifierState; \ No newline at end of file