aboutsummaryrefslogtreecommitdiffstats
path: root/src/dimensions.js
diff options
context:
space:
mode:
authorBrandon Aaron <brandon.aaron@gmail.com>2009-04-22 00:55:44 +0000
committerBrandon Aaron <brandon.aaron@gmail.com>2009-04-22 00:55:44 +0000
commit2adb9b2a0fab55301f66d1a293823ffa6649bdc9 (patch)
tree3d030f5a39e40e13bc2f51926a8e0a8823760791 /src/dimensions.js
parenta0d079f430db0c67a2af60bd4e01da02e711d372 (diff)
downloadjquery-2adb9b2a0fab55301f66d1a293823ffa6649bdc9.tar.gz
jquery-2adb9b2a0fab55301f66d1a293823ffa6649bdc9.zip
width, height, scrollLeft, and scrollTop now work with windows and documents other than just the one it was loaded in (like iframes and popups)
Diffstat (limited to 'src/dimensions.js')
-rw-r--r--src/dimensions.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/dimensions.js b/src/dimensions.js
index 606b105eb..69cfc4513 100644
--- a/src/dimensions.js
+++ b/src/dimensions.js
@@ -19,24 +19,26 @@ jQuery.each([ "Height", "Width" ], function(i, name){
jQuery.fn[ type ] = function( size ) {
// Get window width or height
- return this[0] == window ?
+ var elem = this[0];
+ if ( !elem ) return null;
+ return ("scrollTo" in elem && elem.document) ? // does it walk and quack like a window?
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
- document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] ||
- document.body[ "client" + name ] :
+ elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
+ elem.document.body[ "client" + name ] :
// Get document width or height
- this[0] == document ?
+ (elem.nodeName === "#document") ? // is it a document
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
Math.max(
- document.documentElement["client" + name],
- document.body["scroll" + name], document.documentElement["scroll" + name],
- document.body["offset" + name], document.documentElement["offset" + name]
+ elem.documentElement["client" + name],
+ elem.body["scroll" + name], elem.documentElement["scroll" + name],
+ elem.body["offset" + name], elem.documentElement["offset" + name]
) :
// Get or set width or height on the element
size === undefined ?
// Get width or height on the element
- (this.length ? jQuery.css( this[0], type ) : null) :
+ jQuery.css( elem, type ) :
// Set the width or height on the element (default to pixels if value is unitless)
this.css( type, typeof size === "string" ? size : size + "px" );