2010-09-08 16:00:29 +00:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
// Create innerHeight, innerWidth, outerHeight and outerWidth methods
|
2009-12-22 00:58:13 +00:00
|
|
|
jQuery.each([ "Height", "Width" ], function( i, name ) {
|
2008-04-29 03:26:06 +00:00
|
|
|
|
2009-03-22 04:24:40 +00:00
|
|
|
var type = name.toLowerCase();
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
// innerHeight and innerWidth
|
2009-12-22 00:58:13 +00:00
|
|
|
jQuery.fn["inner" + name] = function() {
|
2011-05-25 23:49:50 +00:00
|
|
|
var ret;
|
|
|
|
return this[0] && !isNaN( ret = parseFloat(jQuery.css( this[0], type, "padding" )) ) ?
|
|
|
|
ret :
|
2009-02-13 22:58:57 +00:00
|
|
|
null;
|
2008-04-29 03:26:06 +00:00
|
|
|
};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
// outerHeight and outerWidth
|
2009-12-22 00:58:13 +00:00
|
|
|
jQuery.fn["outer" + name] = function( margin ) {
|
2011-05-25 23:49:50 +00:00
|
|
|
var ret;
|
|
|
|
return this[0] && !isNaN( ret = parseFloat(jQuery.css( this[0], type, margin ? "margin" : "border" )) ) ?
|
|
|
|
ret :
|
2009-02-13 22:58:57 +00:00
|
|
|
null;
|
2008-04-29 03:26:06 +00:00
|
|
|
};
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2008-12-21 21:22:44 +00:00
|
|
|
jQuery.fn[ type ] = function( size ) {
|
|
|
|
// Get window width or height
|
2009-04-22 00:55:44 +00:00
|
|
|
var elem = this[0];
|
2009-12-10 05:58:29 +00:00
|
|
|
if ( !elem ) {
|
|
|
|
return size == null ? null : this;
|
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-01-24 01:49:59 +00:00
|
|
|
if ( jQuery.isFunction( size ) ) {
|
|
|
|
return this.each(function( i ) {
|
|
|
|
var self = jQuery( this );
|
|
|
|
self[ type ]( size.call( this, i, self[ type ]() ) );
|
|
|
|
});
|
|
|
|
}
|
2009-12-10 05:58:29 +00:00
|
|
|
|
2010-10-22 06:39:06 +00:00
|
|
|
if ( jQuery.isWindow( elem ) ) {
|
2008-12-21 21:22:44 +00:00
|
|
|
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
|
2011-01-19 17:40:32 +00:00
|
|
|
// 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
|
|
|
|
var docElemProp = elem.document.documentElement[ "client" + name ];
|
|
|
|
return elem.document.compatMode === "CSS1Compat" && docElemProp ||
|
|
|
|
elem.document.body[ "client" + name ] || docElemProp;
|
2010-10-22 06:39:06 +00:00
|
|
|
|
|
|
|
// Get document width or height
|
|
|
|
} else if ( elem.nodeType === 9 ) {
|
|
|
|
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
|
|
|
|
return Math.max(
|
|
|
|
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
|
|
|
|
} else if ( size === undefined ) {
|
2010-11-09 16:09:07 +00:00
|
|
|
var orig = jQuery.css( elem, type ),
|
|
|
|
ret = parseFloat( orig );
|
|
|
|
|
2010-10-22 06:39:06 +00:00
|
|
|
return jQuery.isNaN( ret ) ? orig : ret;
|
|
|
|
|
|
|
|
// Set the width or height on the element (default to pixels if value is unitless)
|
|
|
|
} else {
|
|
|
|
return this.css( type, typeof size === "string" ? size : size + "px" );
|
|
|
|
}
|
2008-12-21 21:22:44 +00:00
|
|
|
};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-02-13 22:58:57 +00:00
|
|
|
});
|
2010-09-08 16:00:29 +00:00
|
|
|
|
|
|
|
})( jQuery );
|