mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Core: Deprecate jQuery.isWindow
Fixes gh-3629 Close gh-3702
This commit is contained in:
parent
490db839fb
commit
c18d608537
@ -16,10 +16,11 @@ define( [
|
|||||||
"./var/fnToString",
|
"./var/fnToString",
|
||||||
"./var/ObjectFunctionString",
|
"./var/ObjectFunctionString",
|
||||||
"./var/support",
|
"./var/support",
|
||||||
|
"./var/isWindow",
|
||||||
"./core/DOMEval"
|
"./core/DOMEval"
|
||||||
], function( arr, document, getProto, slice, concat, push, indexOf,
|
], function( arr, document, getProto, slice, concat, push, indexOf,
|
||||||
class2type, toString, hasOwn, fnToString, ObjectFunctionString,
|
class2type, toString, hasOwn, fnToString, ObjectFunctionString,
|
||||||
support, DOMEval ) {
|
support, isWindow, DOMEval ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -220,10 +221,6 @@ jQuery.extend( {
|
|||||||
return typeof obj === "function" && typeof obj.nodeType !== "number";
|
return typeof obj === "function" && typeof obj.nodeType !== "number";
|
||||||
},
|
},
|
||||||
|
|
||||||
isWindow: function( obj ) {
|
|
||||||
return obj != null && obj === obj.window;
|
|
||||||
},
|
|
||||||
|
|
||||||
isNumeric: function( obj ) {
|
isNumeric: function( obj ) {
|
||||||
|
|
||||||
// As of jQuery 3.0, isNumeric is limited to
|
// As of jQuery 3.0, isNumeric is limited to
|
||||||
@ -469,7 +466,7 @@ function isArrayLike( obj ) {
|
|||||||
var length = !!obj && "length" in obj && obj.length,
|
var length = !!obj && "length" in obj && obj.length,
|
||||||
type = jQuery.type( obj );
|
type = jQuery.type( obj );
|
||||||
|
|
||||||
if ( jQuery.isFunction( obj ) || jQuery.isWindow( obj ) ) {
|
if ( jQuery.isFunction( obj ) || isWindow( obj ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
"./core/nodeName"
|
"./core/nodeName",
|
||||||
], function( jQuery, nodeName ) {
|
"./var/isWindow"
|
||||||
|
], function( jQuery, nodeName, isWindow ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -36,5 +37,6 @@ jQuery.holdReady = function( hold ) {
|
|||||||
jQuery.isArray = Array.isArray;
|
jQuery.isArray = Array.isArray;
|
||||||
jQuery.parseJSON = JSON.parse;
|
jQuery.parseJSON = JSON.parse;
|
||||||
jQuery.nodeName = nodeName;
|
jQuery.nodeName = nodeName;
|
||||||
|
jQuery.isWindow = isWindow;
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
define( [
|
define( [
|
||||||
"./core",
|
"./core",
|
||||||
"./core/access",
|
"./core/access",
|
||||||
|
"./var/isWindow",
|
||||||
"./css"
|
"./css"
|
||||||
], function( jQuery, access ) {
|
], function( jQuery, access, isWindow ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
|
|||||||
return access( this, function( elem, type, value ) {
|
return access( this, function( elem, type, value ) {
|
||||||
var doc;
|
var doc;
|
||||||
|
|
||||||
if ( jQuery.isWindow( elem ) ) {
|
if ( isWindow( elem ) ) {
|
||||||
|
|
||||||
// $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)
|
// $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)
|
||||||
return funcName.indexOf( "outer" ) === 0 ?
|
return funcName.indexOf( "outer" ) === 0 ?
|
||||||
|
@ -4,9 +4,9 @@ define( [
|
|||||||
"../data/var/dataPriv",
|
"../data/var/dataPriv",
|
||||||
"../data/var/acceptData",
|
"../data/var/acceptData",
|
||||||
"../var/hasOwn",
|
"../var/hasOwn",
|
||||||
|
"../var/isWindow",
|
||||||
"../event"
|
"../event"
|
||||||
], function( jQuery, document, dataPriv, acceptData, hasOwn ) {
|
], function( jQuery, document, dataPriv, acceptData, hasOwn, isWindow ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ jQuery.extend( jQuery.event, {
|
|||||||
|
|
||||||
// Determine event propagation path in advance, per W3C events spec (#9951)
|
// Determine event propagation path in advance, per W3C events spec (#9951)
|
||||||
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
|
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
|
||||||
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
|
if ( !onlyHandlers && !special.noBubble && !isWindow( elem ) ) {
|
||||||
|
|
||||||
bubbleType = special.delegateType || type;
|
bubbleType = special.delegateType || type;
|
||||||
if ( !rfocusMorph.test( bubbleType + type ) ) {
|
if ( !rfocusMorph.test( bubbleType + type ) ) {
|
||||||
@ -128,7 +128,7 @@ jQuery.extend( jQuery.event, {
|
|||||||
|
|
||||||
// Call a native DOM method on the target with the same name as the event.
|
// Call a native DOM method on the target with the same name as the event.
|
||||||
// Don't do default actions on window, that's where global variables be (#6170)
|
// Don't do default actions on window, that's where global variables be (#6170)
|
||||||
if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
|
if ( ontype && jQuery.isFunction( elem[ type ] ) && !isWindow( elem ) ) {
|
||||||
|
|
||||||
// Don't re-trigger an onFOO event when we call its FOO() method
|
// Don't re-trigger an onFOO event when we call its FOO() method
|
||||||
tmp = elem[ ontype ];
|
tmp = elem[ ontype ];
|
||||||
|
@ -7,12 +7,12 @@ define( [
|
|||||||
"./css/curCSS",
|
"./css/curCSS",
|
||||||
"./css/addGetHookIf",
|
"./css/addGetHookIf",
|
||||||
"./css/support",
|
"./css/support",
|
||||||
|
"./var/isWindow",
|
||||||
"./core/init",
|
"./core/init",
|
||||||
"./css",
|
"./css",
|
||||||
"./selector" // contains
|
"./selector" // contains
|
||||||
], function( jQuery, access, document, documentElement, rnumnonpx,
|
], function( jQuery, access, document, documentElement, rnumnonpx,
|
||||||
curCSS, addGetHookIf, support ) {
|
curCSS, addGetHookIf, support, isWindow ) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function(
|
|||||||
|
|
||||||
// Coalesce documents and windows
|
// Coalesce documents and windows
|
||||||
var win;
|
var win;
|
||||||
if ( jQuery.isWindow( elem ) ) {
|
if ( isWindow( elem ) ) {
|
||||||
win = elem;
|
win = elem;
|
||||||
} else if ( elem.nodeType === 9 ) {
|
} else if ( elem.nodeType === 9 ) {
|
||||||
win = elem.defaultView;
|
win = elem.defaultView;
|
||||||
|
8
src/var/isWindow.js
Normal file
8
src/var/isWindow.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
define( function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return function isWindow( obj ) {
|
||||||
|
return obj != null && obj === obj.window;
|
||||||
|
};
|
||||||
|
|
||||||
|
} );
|
@ -76,7 +76,7 @@ QUnit.test( "show/hide", function( assert ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QUnit.test( "core", function( assert ) {
|
QUnit.test( "core", function( assert ) {
|
||||||
assert.expect( 27 );
|
assert.expect( 25 );
|
||||||
|
|
||||||
var elem = jQuery( "<div></div><span></span>" );
|
var elem = jQuery( "<div></div><span></span>" );
|
||||||
|
|
||||||
@ -100,9 +100,6 @@ QUnit.test( "core", function( assert ) {
|
|||||||
"<?xml version='1.0' encoding='UTF-8'?><foo bar='baz'></foo>"
|
"<?xml version='1.0' encoding='UTF-8'?><foo bar='baz'></foo>"
|
||||||
) ), "jQuery.isXMLDoc" );
|
) ), "jQuery.isXMLDoc" );
|
||||||
|
|
||||||
assert.ok( jQuery.isWindow( window ), "jQuery.isWindow(window)" );
|
|
||||||
assert.ok( !jQuery.isWindow( 2 ), "jQuery.isWindow(Number)" );
|
|
||||||
|
|
||||||
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, 3, {} ] ), 3, "jQuery.inArray - true" );
|
assert.strictEqual( jQuery.inArray( 3, [ "a", 6, false, 3, {} ] ), 3, "jQuery.inArray - true" );
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
jQuery.inArray( 3, [ "a", 6, false, "3", {} ] ),
|
jQuery.inArray( 3, [ "a", 6, false, "3", {} ] ),
|
||||||
|
@ -680,25 +680,6 @@ QUnit.test( "isXMLDoc - XML", function( assert ) {
|
|||||||
assert.ok( jQuery.isXMLDoc( jQuery( "tab", xml )[ 0 ] ), "XML Tab Element" );
|
assert.ok( jQuery.isXMLDoc( jQuery( "tab", xml )[ 0 ] ), "XML Tab Element" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "isWindow", function( assert ) {
|
|
||||||
assert.expect( 14 );
|
|
||||||
|
|
||||||
assert.ok( jQuery.isWindow( window ), "window" );
|
|
||||||
assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" );
|
|
||||||
assert.ok( !jQuery.isWindow(), "empty" );
|
|
||||||
assert.ok( !jQuery.isWindow( null ), "null" );
|
|
||||||
assert.ok( !jQuery.isWindow( undefined ), "undefined" );
|
|
||||||
assert.ok( !jQuery.isWindow( document ), "document" );
|
|
||||||
assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" );
|
|
||||||
assert.ok( !jQuery.isWindow( "" ), "string" );
|
|
||||||
assert.ok( !jQuery.isWindow( 1 ), "number" );
|
|
||||||
assert.ok( !jQuery.isWindow( true ), "boolean" );
|
|
||||||
assert.ok( !jQuery.isWindow( {} ), "object" );
|
|
||||||
assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" );
|
|
||||||
assert.ok( !jQuery.isWindow( /window/ ), "regexp" );
|
|
||||||
assert.ok( !jQuery.isWindow( function() {} ), "function" );
|
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "jQuery('html')", function( assert ) {
|
QUnit.test( "jQuery('html')", function( assert ) {
|
||||||
assert.expect( 18 );
|
assert.expect( 18 );
|
||||||
|
|
||||||
|
@ -164,3 +164,22 @@ QUnit.test( "jQuery.nodeName", function( assert ) {
|
|||||||
"Works on custom elements (true)"
|
"Works on custom elements (true)"
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
QUnit.test( "jQuery.isWindow", function( assert ) {
|
||||||
|
assert.expect( 14 );
|
||||||
|
|
||||||
|
assert.ok( jQuery.isWindow( window ), "window" );
|
||||||
|
assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" );
|
||||||
|
assert.ok( !jQuery.isWindow(), "empty" );
|
||||||
|
assert.ok( !jQuery.isWindow( null ), "null" );
|
||||||
|
assert.ok( !jQuery.isWindow( undefined ), "undefined" );
|
||||||
|
assert.ok( !jQuery.isWindow( document ), "document" );
|
||||||
|
assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" );
|
||||||
|
assert.ok( !jQuery.isWindow( "" ), "string" );
|
||||||
|
assert.ok( !jQuery.isWindow( 1 ), "number" );
|
||||||
|
assert.ok( !jQuery.isWindow( true ), "boolean" );
|
||||||
|
assert.ok( !jQuery.isWindow( {} ), "object" );
|
||||||
|
assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" );
|
||||||
|
assert.ok( !jQuery.isWindow( /window/ ), "regexp" );
|
||||||
|
assert.ok( !jQuery.isWindow( function() {} ), "function" );
|
||||||
|
} );
|
||||||
|
Loading…
Reference in New Issue
Block a user