2010-09-08 18:00:29 +02:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
// Create innerHeight, innerWidth, outerHeight and outerWidth methods
|
2009-12-22 01:58:13 +01:00
|
|
|
jQuery.each([ "Height", "Width" ], function( i, name ) {
|
2008-04-29 05:26:06 +02:00
|
|
|
|
2009-03-22 05:24:40 +01:00
|
|
|
var type = name.toLowerCase();
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
// innerHeight and innerWidth
|
2009-12-22 01:58:13 +01:00
|
|
|
jQuery.fn["inner" + name] = function() {
|
2009-02-13 23:58:57 +01:00
|
|
|
return this[0] ?
|
2010-09-17 23:02:03 +02:00
|
|
|
parseFloat( jQuery.css( this[0], type, "padding" ) ) :
|
2009-02-13 23:58:57 +01:00
|
|
|
null;
|
2008-04-29 05:26:06 +02:00
|
|
|
};
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
// outerHeight and outerWidth
|
2009-12-22 01:58:13 +01:00
|
|
|
jQuery.fn["outer" + name] = function( margin ) {
|
2009-02-13 23:58:57 +01:00
|
|
|
return this[0] ?
|
2010-09-17 23:02:03 +02:00
|
|
|
parseFloat( jQuery.css( this[0], type, margin ? "margin" : "border" ) ) :
|
2009-02-13 23:58:57 +01:00
|
|
|
null;
|
2008-04-29 05:26:06 +02:00
|
|
|
};
|
2009-03-23 02:55:17 +01:00
|
|
|
|
2008-12-21 22:22:44 +01:00
|
|
|
jQuery.fn[ type ] = function( size ) {
|
|
|
|
// Get window width or height
|
2009-04-22 02:55:44 +02:00
|
|
|
var elem = this[0];
|
2009-12-10 06:58:29 +01:00
|
|
|
if ( !elem ) {
|
|
|
|
return size == null ? null : this;
|
|
|
|
}
|
2010-12-30 07:34:48 +01:00
|
|
|
|
2010-01-24 02:49:59 +01: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 06:58:29 +01:00
|
|
|
|
2010-10-22 08:39:06 +02:00
|
|
|
if ( jQuery.isWindow( elem ) ) {
|
2008-12-21 22:22:44 +01:00
|
|
|
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
|
2011-01-19 18:40:32 +01: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 08:39:06 +02: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 17:09:07 +01:00
|
|
|
var orig = jQuery.css( elem, type ),
|
|
|
|
ret = parseFloat( orig );
|
|
|
|
|
2010-10-22 08:39:06 +02: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 22:22:44 +01:00
|
|
|
};
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2009-02-13 23:58:57 +01:00
|
|
|
});
|
2010-09-08 18:00:29 +02:00
|
|
|
|
|
|
|
})( jQuery );
|