Skip to content

Commit 2b84531

Browse files
committed
Core: Move safeActiveElement into its own module
Ref #9647
1 parent 0a9df3a commit 2b84531

8 files changed

Lines changed: 52 additions & 36 deletions

File tree

ui/autocomplete.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
define( [
2424
"jquery",
2525
"./core",
26+
"./version",
2627
"./keycode",
2728
"./widget",
2829
"./position",
29-
"./version",
30-
"./menu"
30+
"./menu",
31+
"./safe-active-element"
3132
], factory );
3233
} else {
3334

ui/core.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"./labels",
3030
"./jquery-1-7",
3131
"./plugin",
32+
"./safe-active-element",
3233
"./version"
3334
], factory );
3435
} else {
@@ -40,35 +41,6 @@
4041

4142
$.extend( $.ui, {
4243

43-
// Internal use only
44-
safeActiveElement: function( document ) {
45-
var activeElement;
46-
47-
// Support: IE 9 only
48-
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
49-
try {
50-
activeElement = document.activeElement;
51-
} catch ( error ) {
52-
activeElement = document.body;
53-
}
54-
55-
// Support: IE 9 - 11 only
56-
// IE may return null instead of an element
57-
// Interestingly, this only seems to occur when NOT in an iframe
58-
if ( !activeElement ) {
59-
activeElement = document.body;
60-
}
61-
62-
// Support: IE 11 only
63-
// IE11 returns a seemingly empty object in some cases when accessing
64-
// document.activeElement from an <iframe>
65-
if ( !activeElement.nodeName ) {
66-
activeElement = document.body;
67-
}
68-
69-
return activeElement;
70-
},
71-
7244
// Internal use only
7345
safeBlur: function( element ) {
7446

ui/dialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// AMD. Register as an anonymous module.
2323
define( [
2424
"jquery",
25-
"./core",
25+
"./version",
2626
"./keycode",
2727
"./widget",
2828
"./button",
@@ -31,7 +31,7 @@
3131
"./mouse",
3232
"./position",
3333
"./resizable",
34-
"./version"
34+
"./safe-active-element"
3535
], factory );
3636
} else {
3737

ui/draggable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"./data",
2525
"./mouse",
2626
"./plugin",
27+
"./safe-active-element",
2728
"./version",
2829
"./widget"
2930
], factory );

ui/menu.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
"./core",
2626
"./version",
2727
"./keycode",
28-
"./widget",
29-
"./position"
28+
"./position",
29+
"./safe-active-element",
30+
"./widget"
3031
], factory );
3132
} else {
3233

ui/safe-active-element.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
( function( factory ) {
2+
if ( typeof define === "function" && define.amd ) {
3+
4+
// AMD. Register as an anonymous module.
5+
define( [ "jquery", "./version" ], factory );
6+
} else {
7+
8+
// Browser globals
9+
factory( jQuery );
10+
}
11+
} ( function( $ ) {
12+
return $.ui.safeActiveElement = function( document ) {
13+
var activeElement;
14+
15+
// Support: IE 9 only
16+
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
17+
try {
18+
activeElement = document.activeElement;
19+
} catch ( error ) {
20+
activeElement = document.body;
21+
}
22+
23+
// Support: IE 9 - 11 only
24+
// IE may return null instead of an element
25+
// Interestingly, this only seems to occur when NOT in an iframe
26+
if ( !activeElement ) {
27+
activeElement = document.body;
28+
}
29+
30+
// Support: IE 11 only
31+
// IE11 returns a seemingly empty object in some cases when accessing
32+
// document.activeElement from an <iframe>
33+
if ( !activeElement.nodeName ) {
34+
activeElement = document.body;
35+
}
36+
37+
return activeElement;
38+
};
39+
40+
} ) );

ui/spinner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
// AMD. Register as an anonymous module.
2323
define( [
2424
"jquery",
25-
"./core",
2625
"./version",
2726
"./keycode",
27+
"./safe-active-element",
2828
"./widget",
2929
"./button"
3030
], factory );

ui/tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"./core",
2626
"./escape-selector",
2727
"./keycode",
28+
"./safe-active-element",
2829
"./version",
2930
"./widget"
3031
], factory );

0 commit comments

Comments
 (0)