aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-09-22 16:41:51 -0400
committerjeresig <jeresig@gmail.com>2010-09-22 16:41:51 -0400
commitc8dd49f756562fef68f664869952e4f5aab08acd (patch)
tree171989c57a01f0c84c7d0486645ac434a8d92472
parentab454d9526445fa025b9c897ec2b21aa89babc8d (diff)
downloadjquery-c8dd49f756562fef68f664869952e4f5aab08acd.tar.gz
jquery-c8dd49f756562fef68f664869952e4f5aab08acd.zip
Unify the means of detecting a window across the library. Fixes jQuery UI bug #5438 and jQuery bugs #6575 and 6088.
-rw-r--r--src/core.js9
-rw-r--r--src/dimensions.js2
-rw-r--r--src/event.js4
-rw-r--r--src/offset.js2
4 files changed, 11 insertions, 6 deletions
diff --git a/src/core.js b/src/core.js
index 227dc30d9..9cb519be5 100644
--- a/src/core.js
+++ b/src/core.js
@@ -474,6 +474,11 @@ jQuery.extend({
return jQuery.type(obj) === "array";
},
+ // A crude way of determining if an object is a window
+ isWindow: function( obj ) {
+ return "setInterval" in obj;
+ },
+
type: function( obj ) {
return obj == null ?
String( obj ) :
@@ -484,7 +489,7 @@ jQuery.extend({
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
- if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || obj.setInterval ) {
+ if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
return false;
}
@@ -632,7 +637,7 @@ jQuery.extend({
// Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
var type = jQuery.type(array);
- if ( array.length == null || type === "string" || type === "function" || type === "regexp" || "setInterval" in array ) {
+ if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
push.call( ret, array );
} else {
jQuery.merge( ret, array );
diff --git a/src/dimensions.js b/src/dimensions.js
index 7ca33794c..5aafbf41e 100644
--- a/src/dimensions.js
+++ b/src/dimensions.js
@@ -33,7 +33,7 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
});
}
- return ("scrollTo" in elem && elem.document) ? // does it walk and quack like a window?
+ return jQuery.isWindow( elem ) ?
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
elem.document.body[ "client" + name ] :
diff --git a/src/event.js b/src/event.js
index 169760a8b..e63b9c074 100644
--- a/src/event.js
+++ b/src/event.js
@@ -25,7 +25,7 @@ jQuery.event = {
// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
- if ( elem.setInterval && ( elem !== window && !elem.frameElement ) ) {
+ if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) {
elem = window;
}
@@ -515,7 +515,7 @@ jQuery.event = {
beforeunload: {
setup: function( data, namespaces, eventHandle ) {
// We only want to do this special case on windows
- if ( this.setInterval ) {
+ if ( jQuery.isWindow( this ) ) {
this.onbeforeunload = eventHandle;
}
},
diff --git a/src/offset.js b/src/offset.js
index a3776c201..650cc08e9 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -280,7 +280,7 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
});
function getWindow( elem ) {
- return ("scrollTo" in elem && elem.document) ?
+ return jQuery.isWindow( elem ) ?
elem :
elem.nodeType === 9 ?
elem.defaultView || elem.parentWindow :