aboutsummaryrefslogtreecommitdiffstats
path: root/src/dimensions.js
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2012-05-24 21:52:35 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-05-24 21:54:04 -0400
commitbc7231e3230b8f2c59b3370e7cae6b8a30d53c1e (patch)
tree560968befb66dad801249db5f27128e7a1cadf1c /src/dimensions.js
parentd5e5ce5bd006ae94e9d85949b4f7141642cebf81 (diff)
downloadjquery-bc7231e3230b8f2c59b3370e7cae6b8a30d53c1e.tar.gz
jquery-bc7231e3230b8f2c59b3370e7cae6b8a30d53c1e.zip
Apply a GibsonTransform(-55) to the #10877 fix. Closes gh-788.
Diffstat (limited to 'src/dimensions.js')
-rw-r--r--src/dimensions.js106
1 files changed, 44 insertions, 62 deletions
diff --git a/src/dimensions.js b/src/dimensions.js
index 79d7c22bc..bbfc62ad8 100644
--- a/src/dimensions.js
+++ b/src/dimensions.js
@@ -1,72 +1,54 @@
(function( jQuery ) {
-// Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
+// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
- var clientProp = "client" + name,
- scrollProp = "scroll" + name,
- offsetProp = "offset" + name;
-
- // 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 );
- };
- });
-
- // outerHeight and outerWidth
- 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 );
- };
-
- function getDimension( type, extra, value ) {
- return jQuery.access( this, function( elem, type, value ) {
- var doc, orig, ret;
-
- if ( jQuery.isWindow( elem ) ) {
- // 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 ];
- }
-
- // Get document width or height
- if ( elem.nodeType === 9 ) {
- // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
- doc = elem.documentElement;
-
- // 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 ];
+ jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
+ // margin is only for outerHeight, outerWidth
+ jQuery.fn[ funcName ] = function( margin, value ) {
+ var clientProp = "client" + name,
+ scrollProp = "scroll" + name,
+ offsetProp = "offset" + name,
+ chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
+ extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
+
+ return jQuery.access( this, function( elem, type, value ) {
+ var doc;
+
+ if ( jQuery.isWindow( elem ) ) {
+ // 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 ];
}
- return Math.max(
- elem.body[ scrollProp ], doc[ scrollProp ],
- elem.body[ offsetProp ], doc[ offsetProp ]
- );
- }
+ // Get document width or height
+ if ( elem.nodeType === 9 ) {
+ // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
+ doc = elem.documentElement;
+
+ // 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 ];
+ }
+
+ return Math.max(
+ elem.body[ scrollProp ], doc[ scrollProp ],
+ elem.body[ offsetProp ], doc[ offsetProp ]
+ );
+ }
- // Get width or height on the element
- if ( value === undefined ) {
- orig = jQuery.css( elem, type, extra );
- ret = parseFloat( orig );
- return jQuery.isNumeric( ret ) ? ret : orig;
- }
+ return value === undefined ?
+ // Get width or height on the element, requesting but not forcing parseFloat
+ jQuery.css( elem, type, value, extra ) :
- // Set the width or height on the element
- jQuery.style( elem, type, value, extra );
- }, type, value, arguments.length > 2, null );
- }
+ // Set width or height on the element
+ jQuery.style( elem, type, value, extra );
+ }, type, chainable ? margin : undefined, chainable );
+ };
+ });
});
})( jQuery );