🌐 AI搜索 & 代理 主页
Skip to content

Commit c18d608

Browse files
ShashankaNatarajtimmywil
authored andcommitted
Core: Deprecate jQuery.isWindow
Fixes gh-3629 Close gh-3702
1 parent 490db83 commit c18d608

File tree

9 files changed

+45
-40
lines changed

9 files changed

+45
-40
lines changed

src/core.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ define( [
1616
"./var/fnToString",
1717
"./var/ObjectFunctionString",
1818
"./var/support",
19+
"./var/isWindow",
1920
"./core/DOMEval"
2021
], function( arr, document, getProto, slice, concat, push, indexOf,
2122
class2type, toString, hasOwn, fnToString, ObjectFunctionString,
22-
support, DOMEval ) {
23+
support, isWindow, DOMEval ) {
2324

2425
"use strict";
2526

@@ -220,10 +221,6 @@ jQuery.extend( {
220221
return typeof obj === "function" && typeof obj.nodeType !== "number";
221222
},
222223

223-
isWindow: function( obj ) {
224-
return obj != null && obj === obj.window;
225-
},
226-
227224
isNumeric: function( obj ) {
228225

229226
// As of jQuery 3.0, isNumeric is limited to
@@ -469,7 +466,7 @@ function isArrayLike( obj ) {
469466
var length = !!obj && "length" in obj && obj.length,
470467
type = jQuery.type( obj );
471468

472-
if ( jQuery.isFunction( obj ) || jQuery.isWindow( obj ) ) {
469+
if ( jQuery.isFunction( obj ) || isWindow( obj ) ) {
473470
return false;
474471
}
475472

src/deprecated.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define( [
22
"./core",
3-
"./core/nodeName"
4-
], function( jQuery, nodeName ) {
3+
"./core/nodeName",
4+
"./var/isWindow"
5+
], function( jQuery, nodeName, isWindow ) {
56

67
"use strict";
78

@@ -36,5 +37,6 @@ jQuery.holdReady = function( hold ) {
3637
jQuery.isArray = Array.isArray;
3738
jQuery.parseJSON = JSON.parse;
3839
jQuery.nodeName = nodeName;
40+
jQuery.isWindow = isWindow;
3941

4042
} );

src/dimensions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
define( [
22
"./core",
33
"./core/access",
4+
"./var/isWindow",
45
"./css"
5-
], function( jQuery, access ) {
6+
], function( jQuery, access, isWindow ) {
67

78
"use strict";
89

@@ -19,7 +20,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
1920
return access( this, function( elem, type, value ) {
2021
var doc;
2122

22-
if ( jQuery.isWindow( elem ) ) {
23+
if ( isWindow( elem ) ) {
2324

2425
// $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)
2526
return funcName.indexOf( "outer" ) === 0 ?

src/event/trigger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ define( [
44
"../data/var/dataPriv",
55
"../data/var/acceptData",
66
"../var/hasOwn",
7-
7+
"../var/isWindow",
88
"../event"
9-
], function( jQuery, document, dataPriv, acceptData, hasOwn ) {
9+
], function( jQuery, document, dataPriv, acceptData, hasOwn, isWindow ) {
1010

1111
"use strict";
1212

@@ -76,7 +76,7 @@ jQuery.extend( jQuery.event, {
7676

7777
// Determine event propagation path in advance, per W3C events spec (#9951)
7878
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
79-
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
79+
if ( !onlyHandlers && !special.noBubble && !isWindow( elem ) ) {
8080

8181
bubbleType = special.delegateType || type;
8282
if ( !rfocusMorph.test( bubbleType + type ) ) {
@@ -128,7 +128,7 @@ jQuery.extend( jQuery.event, {
128128

129129
// Call a native DOM method on the target with the same name as the event.
130130
// Don't do default actions on window, that's where global variables be (#6170)
131-
if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
131+
if ( ontype && jQuery.isFunction( elem[ type ] ) && !isWindow( elem ) ) {
132132

133133
// Don't re-trigger an onFOO event when we call its FOO() method
134134
tmp = elem[ ontype ];

src/offset.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ define( [
77
"./css/curCSS",
88
"./css/addGetHookIf",
99
"./css/support",
10-
10+
"./var/isWindow",
1111
"./core/init",
1212
"./css",
1313
"./selector" // contains
1414
], function( jQuery, access, document, documentElement, rnumnonpx,
15-
curCSS, addGetHookIf, support ) {
15+
curCSS, addGetHookIf, support, isWindow ) {
1616

1717
"use strict";
1818

@@ -186,7 +186,7 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function(
186186

187187
// Coalesce documents and windows
188188
var win;
189-
if ( jQuery.isWindow( elem ) ) {
189+
if ( isWindow( elem ) ) {
190190
win = elem;
191191
} else if ( elem.nodeType === 9 ) {
192192
win = elem.defaultView;

src/var/isWindow.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define( function() {
2+
"use strict";
3+
4+
return function isWindow( obj ) {
5+
return obj != null && obj === obj.window;
6+
};
7+
8+
} );

test/unit/basic.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ QUnit.test( "show/hide", function( assert ) {
7676
}
7777

7878
QUnit.test( "core", function( assert ) {
79-
assert.expect( 27 );
79+
assert.expect( 25 );
8080

8181
var elem = jQuery( "<div></div><span></span>" );
8282

@@ -100,9 +100,6 @@ QUnit.test( "core", function( assert ) {
100100
"<?xml version='1.0' encoding='UTF-8'?><foo bar='baz'></foo>"
101101
) ), "jQuery.isXMLDoc" );
102102

103-
assert.ok( jQuery.isWindow( window ), "jQuery.isWindow(window)" );
104-
assert.ok( !jQuery.isWindow( 2 ), "jQuery.isWindow(Number)" );
105-
106103
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, 3, {} ] ), 3, "jQuery.inArray - true" );
107104
assert.strictEqual(
108105
jQuery.inArray( 3, [ "a", 6, false, "3", {} ] ),

test/unit/core.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -680,25 +680,6 @@ QUnit.test( "isXMLDoc - XML", function( assert ) {
680680
assert.ok( jQuery.isXMLDoc( jQuery( "tab", xml )[ 0 ] ), "XML Tab Element" );
681681
} );
682682

683-
QUnit.test( "isWindow", function( assert ) {
684-
assert.expect( 14 );
685-
686-
assert.ok( jQuery.isWindow( window ), "window" );
687-
assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" );
688-
assert.ok( !jQuery.isWindow(), "empty" );
689-
assert.ok( !jQuery.isWindow( null ), "null" );
690-
assert.ok( !jQuery.isWindow( undefined ), "undefined" );
691-
assert.ok( !jQuery.isWindow( document ), "document" );
692-
assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" );
693-
assert.ok( !jQuery.isWindow( "" ), "string" );
694-
assert.ok( !jQuery.isWindow( 1 ), "number" );
695-
assert.ok( !jQuery.isWindow( true ), "boolean" );
696-
assert.ok( !jQuery.isWindow( {} ), "object" );
697-
assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" );
698-
assert.ok( !jQuery.isWindow( /window/ ), "regexp" );
699-
assert.ok( !jQuery.isWindow( function() {} ), "function" );
700-
} );
701-
702683
QUnit.test( "jQuery('html')", function( assert ) {
703684
assert.expect( 18 );
704685

test/unit/deprecated.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,22 @@ QUnit.test( "jQuery.nodeName", function( assert ) {
164164
"Works on custom elements (true)"
165165
);
166166
} );
167+
168+
QUnit.test( "jQuery.isWindow", function( assert ) {
169+
assert.expect( 14 );
170+
171+
assert.ok( jQuery.isWindow( window ), "window" );
172+
assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" );
173+
assert.ok( !jQuery.isWindow(), "empty" );
174+
assert.ok( !jQuery.isWindow( null ), "null" );
175+
assert.ok( !jQuery.isWindow( undefined ), "undefined" );
176+
assert.ok( !jQuery.isWindow( document ), "document" );
177+
assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" );
178+
assert.ok( !jQuery.isWindow( "" ), "string" );
179+
assert.ok( !jQuery.isWindow( 1 ), "number" );
180+
assert.ok( !jQuery.isWindow( true ), "boolean" );
181+
assert.ok( !jQuery.isWindow( {} ), "object" );
182+
assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" );
183+
assert.ok( !jQuery.isWindow( /window/ ), "regexp" );
184+
assert.ok( !jQuery.isWindow( function() {} ), "function" );
185+
} );

0 commit comments

Comments
 (0)