UNPKG

897 BJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5exports.__esModule = true;
6exports.default = activeElement;
7
8var _ownerDocument = _interopRequireDefault(require("./ownerDocument"));
9
10/**
11 * Returns the actively focused element safely.
12 *
13 * @param doc the document to check
14 */
15function activeElement(doc) {
16 if (doc === void 0) {
17 doc = (0, _ownerDocument.default)();
18 }
19
20 // Support: IE 9 only
21 // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
22 try {
23 var active = doc.activeElement; // IE11 returns a seemingly empty object in some cases when accessing
24 // document.activeElement from an <iframe>
25
26 if (!active || !active.nodeName) return null;
27 return active;
28 } catch (e) {
29 /* ie throws if no active element */
30 return doc.body;
31 }
32}
33
34module.exports = exports["default"];
\No newline at end of file