diff options
author | Alexander Schmitz <arschmitz@gmail.com> | 2015-07-15 18:39:11 -0400 |
---|---|---|
committer | Alexander Schmitz <arschmitz@gmail.com> | 2015-08-08 00:29:36 -0400 |
commit | 2b84531ae9331f60e4d739fabca6d78abde89ae1 (patch) | |
tree | 9c2f073ceec9e187725ad2fe9b810a274ec38397 /ui | |
parent | 0a9df3af52a66fe5e8f23622503020f0bcc6ded9 (diff) | |
download | jquery-ui-2b84531ae9331f60e4d739fabca6d78abde89ae1.tar.gz jquery-ui-2b84531ae9331f60e4d739fabca6d78abde89ae1.zip |
Core: Move safeActiveElement into its own module
Ref #9647
Diffstat (limited to 'ui')
-rw-r--r-- | ui/autocomplete.js | 5 | ||||
-rw-r--r-- | ui/core.js | 30 | ||||
-rw-r--r-- | ui/dialog.js | 4 | ||||
-rw-r--r-- | ui/draggable.js | 1 | ||||
-rw-r--r-- | ui/menu.js | 5 | ||||
-rw-r--r-- | ui/safe-active-element.js | 40 | ||||
-rw-r--r-- | ui/spinner.js | 2 | ||||
-rw-r--r-- | ui/tabs.js | 1 |
8 files changed, 52 insertions, 36 deletions
diff --git a/ui/autocomplete.js b/ui/autocomplete.js index b535b3966..cf95b233a 100644 --- a/ui/autocomplete.js +++ b/ui/autocomplete.js @@ -23,11 +23,12 @@ define( [ "jquery", "./core", + "./version", "./keycode", "./widget", "./position", - "./version", - "./menu" + "./menu", + "./safe-active-element" ], factory ); } else { diff --git a/ui/core.js b/ui/core.js index beb3fcbcb..f0eef1328 100644 --- a/ui/core.js +++ b/ui/core.js @@ -29,6 +29,7 @@ "./labels", "./jquery-1-7", "./plugin", + "./safe-active-element", "./version" ], factory ); } else { @@ -41,35 +42,6 @@ $.extend( $.ui, { // Internal use only - 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; - }, - - // Internal use only safeBlur: function( element ) { // Support: IE9 - 10 only diff --git a/ui/dialog.js b/ui/dialog.js index f17aaccd1..e2369d0b0 100644 --- a/ui/dialog.js +++ b/ui/dialog.js @@ -22,7 +22,7 @@ // AMD. Register as an anonymous module. define( [ "jquery", - "./core", + "./version", "./keycode", "./widget", "./button", @@ -31,7 +31,7 @@ "./mouse", "./position", "./resizable", - "./version" + "./safe-active-element" ], factory ); } else { diff --git a/ui/draggable.js b/ui/draggable.js index 81cb7d6de..d3afc9add 100644 --- a/ui/draggable.js +++ b/ui/draggable.js @@ -24,6 +24,7 @@ "./data", "./mouse", "./plugin", + "./safe-active-element", "./version", "./widget" ], factory ); diff --git a/ui/menu.js b/ui/menu.js index be59e7322..c266840ee 100644 --- a/ui/menu.js +++ b/ui/menu.js @@ -25,8 +25,9 @@ "./core", "./version", "./keycode", - "./widget", - "./position" + "./position", + "./safe-active-element", + "./widget" ], factory ); } else { 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; +}; + +} ) ); diff --git a/ui/spinner.js b/ui/spinner.js index 665bf58d0..241dcaa51 100644 --- a/ui/spinner.js +++ b/ui/spinner.js @@ -22,9 +22,9 @@ // AMD. Register as an anonymous module. define( [ "jquery", - "./core", "./version", "./keycode", + "./safe-active-element", "./widget", "./button" ], factory ); diff --git a/ui/tabs.js b/ui/tabs.js index 526dc6e82..b5a776c48 100644 --- a/ui/tabs.js +++ b/ui/tabs.js @@ -25,6 +25,7 @@ "./core", "./escape-selector", "./keycode", + "./safe-active-element", "./version", "./widget" ], factory ); |