1/** 2 * Copyright 2013-2014, 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 getActiveElement 10 * @typechecks 11 */ 12 13/** 14 * Same as document.activeElement but wraps in a try-catch block. In IE it is 15 * not safe to call document.activeElement if there is nothing focused. 16 * 17 * The activeElement will be null only if the document body is not yet defined. 18 */ 19function getActiveElement() /*?DOMElement*/ { 20 try { 21 return document.activeElement || document.body; 22 } catch (e) { 23 return document.body; 24 } 25} 26 27module.exports = getActiveElement; 28 29