|
1 | | -import { ie, ie_version, ios } from "./browser" |
| 1 | +import { ie, ios } from "./browser" |
2 | 2 |
|
3 | 3 | export function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") } |
4 | 4 |
|
@@ -58,18 +58,20 @@ export function contains(parent, child) { |
58 | 58 | } while (child = child.parentNode) |
59 | 59 | } |
60 | 60 |
|
61 | | -export let activeElt = function() { |
62 | | - let activeElement = document.activeElement |
| 61 | +export function activeElt() { |
| 62 | + // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement. |
| 63 | + // IE < 10 will throw when accessed while the page is loading or in an iframe. |
| 64 | + // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable. |
| 65 | + let activeElement |
| 66 | + try { |
| 67 | + activeElement = document.activeElement |
| 68 | + } catch(e) { |
| 69 | + activeElement = document.body || null |
| 70 | + } |
63 | 71 | while (activeElement && activeElement.root && activeElement.root.activeElement) |
64 | 72 | activeElement = activeElement.root.activeElement |
65 | 73 | return activeElement |
66 | 74 | } |
67 | | -// Older versions of IE throws unspecified error when touching |
68 | | -// document.activeElement in some cases (during loading, in iframe) |
69 | | -if (ie && ie_version < 11) activeElt = function() { |
70 | | - try { return document.activeElement } |
71 | | - catch(e) { return document.body } |
72 | | -} |
73 | 75 |
|
74 | 76 | export function addClass(node, cls) { |
75 | 77 | let current = node.className |
|
0 commit comments