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
|
2011-12-06 20:25:38 +00:00
|
|
|
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
|
|
|
|
var clientProp = "client" + name,
|
|
|
|
scrollProp = "scroll" + name,
|
|
|
|
offsetProp = "offset" + name;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2012-05-21 17:44:19 +00:00
|
|
|
// height, width, innerHeight and innerWidth
|
|
|
|
jQuery.each( { padding: "inner" + name, content: type }, function( extra, funcName ) {
|
|
|
|
jQuery.fn[ funcName ] = function( value ) {
|
|
|
|
var args = [ type, extra ];
|
|
|
|
if ( arguments.length ) {
|
|
|
|
args.push( value );
|
|
|
|
}
|
|
|
|
return getDimension.apply( this, args );
|
|
|
|
};
|
|
|
|
});
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
// outerHeight and outerWidth
|
2012-05-21 17:44:19 +00:00
|
|
|
jQuery.fn[ "outer" + name ] = function( margin, value ) {
|
|
|
|
var args = [ type, ( margin === true || value === true ) ? "margin" : "border" ];
|
|
|
|
if ( arguments.length && typeof margin !== "boolean" ) {
|
|
|
|
args.push( margin );
|
|
|
|
}
|
|
|
|
return getDimension.apply( this, args );
|
2008-04-29 03:26:06 +00:00
|
|
|
};
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2012-05-21 17:44:19 +00:00
|
|
|
function getDimension( type, extra, value ) {
|
2011-12-06 20:25:38 +00:00
|
|
|
return jQuery.access( this, function( elem, type, value ) {
|
2012-05-14 18:12:14 +00:00
|
|
|
var doc, orig, ret;
|
2009-12-10 05:58:29 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
if ( jQuery.isWindow( elem ) ) {
|
2012-05-14 18:12:14 +00:00
|
|
|
// As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
|
|
|
|
// isn't a whole lot we can do. See pull request at this URL for discussion:
|
|
|
|
// https://github.com/jquery/jquery/pull/764
|
|
|
|
return elem.document.documentElement[ clientProp ];
|
2011-12-06 20:25:38 +00:00
|
|
|
}
|
2010-10-22 06:39:06 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
// Get document width or height
|
|
|
|
if ( elem.nodeType === 9 ) {
|
|
|
|
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
|
|
|
|
doc = elem.documentElement;
|
2012-02-25 18:13:16 +00:00
|
|
|
|
|
|
|
// when a window > document, IE6 reports a offset[Width/Height] > client[Width/Height]
|
|
|
|
// so we can't use max, as it'll choose the incorrect offset[Width/Height]
|
|
|
|
// instead we use the correct client[Width/Height]
|
|
|
|
// support:IE6
|
|
|
|
if ( doc[ clientProp ] >= doc[ scrollProp ] ) {
|
|
|
|
return doc[ clientProp ];
|
|
|
|
}
|
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
return Math.max(
|
|
|
|
elem.body[ scrollProp ], doc[ scrollProp ],
|
|
|
|
elem.body[ offsetProp ], doc[ offsetProp ]
|
|
|
|
);
|
|
|
|
}
|
2010-10-22 06:39:06 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
// Get width or height on the element
|
|
|
|
if ( value === undefined ) {
|
2012-05-21 17:44:19 +00:00
|
|
|
orig = jQuery.css( elem, type, extra );
|
2010-11-09 16:09:07 +00:00
|
|
|
ret = parseFloat( orig );
|
2011-12-06 20:25:38 +00:00
|
|
|
return jQuery.isNumeric( ret ) ? ret : orig;
|
|
|
|
}
|
2010-11-09 16:09:07 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
// Set the width or height on the element
|
2012-05-21 17:44:19 +00:00
|
|
|
jQuery.style( elem, type, value, extra );
|
|
|
|
}, type, value, arguments.length > 2, null );
|
|
|
|
}
|
2009-02-13 22:58:57 +00:00
|
|
|
});
|
2010-09-08 16:00:29 +00:00
|
|
|
|
|
|
|
})( jQuery );
|