Skip to content

Commit edb2286

Browse files
author
timmywil
committed
Return null for outer/inner width/height calls on window/document. Fixes #7557.
1 parent 1d1cb58 commit edb2286

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

src/css.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ jQuery.each(["height", "width"], function( i, name ) {
170170
get: function( elem, computed, extra ) {
171171
var val;
172172

173+
// Tests for window/document
174+
if ( !elem.style ) {
175+
return null;
176+
}
177+
173178
if ( computed ) {
174179
if ( elem.offsetWidth !== 0 ) {
175180
val = getWH( elem, name, extra );
@@ -196,7 +201,6 @@ jQuery.each(["height", "width"], function( i, name ) {
196201

197202
if ( val < 0 || val == null ) {
198203
val = elem.style[ name ];
199-
200204
// Should return "auto" instead of 0, use 0 for
201205
// temporary backwards-compat
202206
return val === "" || val === "auto" ? "0px" : val;

src/dimensions.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
77

88
// innerHeight and innerWidth
99
jQuery.fn["inner" + name] = function() {
10-
return this[0] ?
11-
parseFloat( jQuery.css( this[0], type, "padding" ) ) :
10+
var ret;
11+
return this[0] && !isNaN( ret = parseFloat(jQuery.css( this[0], type, "padding" )) ) ?
12+
ret :
1213
null;
1314
};
1415

1516
// outerHeight and outerWidth
1617
jQuery.fn["outer" + name] = function( margin ) {
17-
return this[0] ?
18-
parseFloat( jQuery.css( this[0], type, margin ? "margin" : "border" ) ) :
18+
var ret;
19+
return this[0] && !isNaN( ret = parseFloat(jQuery.css( this[0], type, margin ? "margin" : "border" )) ) ?
20+
ret :
1921
null;
2022
};
2123

test/unit/dimensions.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ test("height() with function args", function() {
107107
});
108108

109109
test("innerWidth()", function() {
110-
expect(4);
110+
expect(8);
111+
112+
equals(jQuery(window).innerWidth(), null, "Test on window without margin option");
113+
equals(jQuery(window).innerWidth(true), null, "Test on window with margin option");
114+
115+
equals(jQuery(document).innerWidth(), null, "Test on document without margin option");
116+
equals(jQuery(document).innerWidth(true), null, "Test on document with margin option");
111117

112118
var $div = jQuery("#nothiddendiv");
113119
// set styles
@@ -136,7 +142,13 @@ test("innerWidth()", function() {
136142
});
137143

138144
test("innerHeight()", function() {
139-
expect(4);
145+
expect(8);
146+
147+
equals(jQuery(window).innerHeight(), null, "Test on window without margin option");
148+
equals(jQuery(window).innerHeight(true), null, "Test on window with margin option");
149+
150+
equals(jQuery(document).innerHeight(), null, "Test on document without margin option");
151+
equals(jQuery(document).innerHeight(true), null, "Test on document with margin option");
140152

141153
var $div = jQuery("#nothiddendiv");
142154
// set styles
@@ -165,7 +177,12 @@ test("innerHeight()", function() {
165177
});
166178

167179
test("outerWidth()", function() {
168-
expect(7);
180+
expect(11);
181+
182+
equal( jQuery( window ).outerWidth(), null, "Test on window without margin option" );
183+
equal( jQuery( window ).outerWidth( true ), null, "Test on window with margin option" );
184+
equal( jQuery( document ).outerWidth(), null, "Test on document without margin option" );
185+
equal( jQuery( document ).outerWidth( true ), null, "Test on document with margin option" );
169186

170187
var $div = jQuery("#nothiddendiv");
171188
$div.css("width", 30);
@@ -195,7 +212,12 @@ test("outerWidth()", function() {
195212
});
196213

197214
test("outerHeight()", function() {
198-
expect(7);
215+
expect(11);
216+
217+
equal( jQuery( window ).outerHeight(), null, "Test on window without margin option" );
218+
equal( jQuery( window ).outerHeight( true ), null, "Test on window with margin option" );
219+
equal( jQuery( document ).outerHeight(), null, "Test on document without margin option" );
220+
equal( jQuery( document ).outerHeight( true ), null, "Test on document with margin option" );
199221

200222
var $div = jQuery("#nothiddendiv");
201223
$div.css("height", 30);

0 commit comments

Comments
 (0)