2010-09-08 16:00:29 +00:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2011-06-07 03:35:16 +00:00
|
|
|
// Create width, height, 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
|
2011-06-07 03:35:16 +00:00
|
|
|
jQuery.fn[ "inner" + name ] = function() {
|
2011-05-25 23:59:29 +00:00
|
|
|
var elem = this[0];
|
2011-09-30 21:50:07 +00:00
|
|
|
return elem ?
|
|
|
|
elem.style ?
|
2011-05-25 23:59:29 +00:00
|
|
|
parseFloat( jQuery.css( elem, type, "padding" ) ) :
|
2011-09-30 21:50:07 +00:00
|
|
|
this[ type ]() :
|
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
|
2011-06-07 03:35:16 +00:00
|
|
|
jQuery.fn[ "outer" + name ] = function( margin ) {
|
2011-05-25 23:59:29 +00:00
|
|
|
var elem = this[0];
|
2011-09-30 21:50:07 +00:00
|
|
|
return elem ?
|
|
|
|
elem.style ?
|
2011-05-25 23:59:29 +00:00
|
|
|
parseFloat( jQuery.css( elem, type, margin ? "margin" : "border" ) ) :
|
2011-09-30 21:50:07 +00:00
|
|
|
this[ type ]() :
|
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
|
2011-08-02 22:38:35 +00:00
|
|
|
var docElemProp = elem.document.documentElement[ "client" + name ],
|
|
|
|
body = elem.document.body;
|
2011-01-19 17:40:32 +00:00
|
|
|
return elem.document.compatMode === "CSS1Compat" && docElemProp ||
|
2011-08-02 22:38:35 +00:00
|
|
|
body && 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 );
|
|
|
|
|
2011-10-12 01:04:22 +00:00
|
|
|
return jQuery.isNumeric( ret ) ? ret : orig;
|
2010-10-22 06:39:06 +00:00
|
|
|
|
|
|
|
// 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 );
|