aboutsummaryrefslogtreecommitdiffstats
path: root/ui/safe-active-element.js
diff options
context:
space:
mode:
authorAlexander Schmitz <arschmitz@gmail.com>2015-07-15 18:39:11 -0400
committerAlexander Schmitz <arschmitz@gmail.com>2015-08-08 00:29:36 -0400
commit2b84531ae9331f60e4d739fabca6d78abde89ae1 (patch)
tree9c2f073ceec9e187725ad2fe9b810a274ec38397 /ui/safe-active-element.js
parent0a9df3af52a66fe5e8f23622503020f0bcc6ded9 (diff)
downloadjquery-ui-2b84531ae9331f60e4d739fabca6d78abde89ae1.tar.gz
jquery-ui-2b84531ae9331f60e4d739fabca6d78abde89ae1.zip
Core: Move safeActiveElement into its own module
Ref #9647
Diffstat (limited to 'ui/safe-active-element.js')
-rw-r--r--ui/safe-active-element.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/ui/safe-active-element.js b/ui/safe-active-element.js
new file mode 100644
index 000000000..4d04add5f
--- /dev/null
+++ b/ui/safe-active-element.js
@@ -0,0 +1,40 @@
+( function( factory ) {
+ if ( typeof define === "function" && define.amd ) {
+
+ // AMD. Register as an anonymous module.
+ define( [ "jquery", "./version" ], factory );
+ } else {
+
+ // Browser globals
+ factory( jQuery );
+ }
+} ( function( $ ) {
+return $.ui.safeActiveElement = function( document ) {
+ var activeElement;
+
+ // Support: IE 9 only
+ // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
+ try {
+ activeElement = document.activeElement;
+ } catch ( error ) {
+ activeElement = document.body;
+ }
+
+ // Support: IE 9 - 11 only
+ // IE may return null instead of an element
+ // Interestingly, this only seems to occur when NOT in an iframe
+ if ( !activeElement ) {
+ activeElement = document.body;
+ }
+
+ // Support: IE 11 only
+ // IE11 returns a seemingly empty object in some cases when accessing
+ // document.activeElement from an <iframe>
+ if ( !activeElement.nodeName ) {
+ activeElement = document.body;
+ }
+
+ return activeElement;
+};
+
+} ) );