1
1
( function ( jQuery ) {
2
2
3
3
// Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
4
- jQuery . each ( [ "Height" , "Width" ] , function ( i , name ) {
5
-
6
- var type = name . toLowerCase ( ) ;
4
+ jQuery . each ( { Height : "height" , Width : "width" } , function ( name , type ) {
5
+ var clientProp = "client" + name ,
6
+ scrollProp = "scroll" + name ,
7
+ offsetProp = "offset" + name ;
7
8
8
9
// innerHeight and innerWidth
9
10
jQuery . fn [ "inner" + name ] = function ( ) {
@@ -25,50 +26,40 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
25
26
null ;
26
27
} ;
27
28
28
- jQuery . fn [ type ] = function ( size ) {
29
- // Get window width or height
30
- var elem = this [ 0 ] ;
31
- if ( ! elem ) {
32
- return size == null ? null : this ;
33
- }
34
-
35
- if ( jQuery . isFunction ( size ) ) {
36
- return this . each ( function ( i ) {
37
- var self = jQuery ( this ) ;
38
- self [ type ] ( size . call ( this , i , self [ type ] ( ) ) ) ;
39
- } ) ;
40
- }
29
+ jQuery . fn [ type ] = function ( value ) {
30
+ return jQuery . access ( this , function ( elem , type , value ) {
31
+ var doc , docElemProp , orig , ret ;
41
32
42
- if ( jQuery . isWindow ( elem ) ) {
43
- // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
44
- // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
45
- var docElemProp = elem . document . documentElement [ "client" + name ] ,
46
- body = elem . document . body ;
47
- return elem . document . compatMode === "CSS1Compat" && docElemProp ||
48
- body && body [ "client" + name ] || docElemProp ;
33
+ if ( jQuery . isWindow ( elem ) ) {
34
+ // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
35
+ doc = elem . document ;
36
+ docElemProp = doc . documentElement [ clientProp ] ;
37
+ return doc . compatMode === "CSS1Compat" && docElemProp ||
38
+ doc . body && doc . body [ clientProp ] || docElemProp ;
39
+ }
49
40
50
- // Get document width or height
51
- } else if ( elem . nodeType === 9 ) {
52
- // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
53
- return Math . max (
54
- elem . documentElement [ "client" + name ] ,
55
- elem . body [ "scroll" + name ] , elem . documentElement [ "scroll" + name ] ,
56
- elem . body [ "offset" + name ] , elem . documentElement [ "offset" + name ]
57
- ) ;
41
+ // Get document width or height
42
+ if ( elem . nodeType === 9 ) {
43
+ // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
44
+ doc = elem . documentElement ;
45
+ return Math . max (
46
+ doc [ clientProp ] ,
47
+ elem . body [ scrollProp ] , doc [ scrollProp ] ,
48
+ elem . body [ offsetProp ] , doc [ offsetProp ]
49
+ ) ;
50
+ }
58
51
59
- // Get or set width or height on the element
60
- } else if ( size === undefined ) {
61
- var orig = jQuery . css ( elem , type ) ,
52
+ // Get width or height on the element
53
+ if ( value === undefined ) {
54
+ orig = jQuery . css ( elem , type ) ;
62
55
ret = parseFloat ( orig ) ;
56
+ return jQuery . isNumeric ( ret ) ? ret : orig ;
57
+ }
63
58
64
- return jQuery . isNumeric ( ret ) ? ret : orig ;
65
-
66
- // Set the width or height on the element (default to pixels if value is unitless)
67
- } else {
68
- return this . css ( type , typeof size === "string" ? size : size + "px" ) ;
69
- }
59
+ // Set the width or height on the element
60
+ jQuery ( elem ) . css ( type , value ) ;
61
+ } , type , value , arguments . length , null ) ;
70
62
} ;
71
-
72
63
} ) ;
73
64
74
65
} ) ( jQuery ) ;
0 commit comments