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] ?
|
2009-03-06 05:23:44 +01:00
|
|
|
jQuery.css( this[0], type, false, "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] ?
|
2009-03-06 05:23:44 +01:00
|
|
|
jQuery.css( this[0], type, false, 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-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
|
|
|
|
2009-04-22 02:55:44 +02:00
|
|
|
return ("scrollTo" in elem && elem.document) ? // does it walk and quack like a window?
|
2008-12-21 22:22:44 +01:00
|
|
|
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
|
2009-04-22 02:55:44 +02:00
|
|
|
elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
|
|
|
|
elem.document.body[ "client" + name ] :
|
2008-12-21 22:22:44 +01:00
|
|
|
|
|
|
|
// Get document width or height
|
2009-07-18 21:44:15 +02:00
|
|
|
(elem.nodeType === 9) ? // is it a document
|
2008-12-21 22:22:44 +01:00
|
|
|
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
|
|
|
|
Math.max(
|
2009-04-22 02:55:44 +02:00
|
|
|
elem.documentElement["client" + name],
|
|
|
|
elem.body["scroll" + name], elem.documentElement["scroll" + name],
|
|
|
|
elem.body["offset" + name], elem.documentElement["offset" + name]
|
2008-12-21 22:22:44 +01:00
|
|
|
) :
|
|
|
|
|
|
|
|
// Get or set width or height on the element
|
|
|
|
size === undefined ?
|
|
|
|
// Get width or height on the element
|
2009-04-22 02:55:44 +02:00
|
|
|
jQuery.css( elem, type ) :
|
2008-12-21 22:22:44 +01:00
|
|
|
|
|
|
|
// Set the width or height on the element (default to pixels if value is unitless)
|
|
|
|
this.css( type, typeof size === "string" ? size : size + "px" );
|
|
|
|
};
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2009-02-13 23:58:57 +01:00
|
|
|
});
|