Commit a5f8a144 authored by John Resig's avatar John Resig

Make sure that calling .width(num) or .height(num) on an empty set returns the...

Make sure that calling .width(num) or .height(num) on an empty set returns the empty set. Fixes #5600.
parent 715d1c5a
...@@ -20,7 +20,10 @@ jQuery.each([ "Height", "Width" ], function(i, name){ ...@@ -20,7 +20,10 @@ jQuery.each([ "Height", "Width" ], function(i, name){
jQuery.fn[ type ] = function( size ) { jQuery.fn[ type ] = function( size ) {
// Get window width or height // Get window width or height
var elem = this[0]; var elem = this[0];
if ( !elem ) { return null; } if ( !elem ) {
return size == null ? null : this;
}
return ("scrollTo" in elem && elem.document) ? // does it walk and quack like a window? return ("scrollTo" in elem && elem.document) ? // does it walk and quack like a window?
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] || elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
......
module("dimensions"); module("dimensions");
test("width()", function() { test("width()", function() {
expect(6); expect(7);
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.width(30); $div.width(30);
...@@ -28,10 +28,13 @@ test("width()", function() { ...@@ -28,10 +28,13 @@ test("width()", function() {
jQuery("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" }); jQuery("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding"); equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" }); jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
var blah = jQuery("blah");
equals( blah.width(10), blah, "Make sure that setting a width on an empty set returns the set." );
}); });
test("height()", function() { test("height()", function() {
expect(5); expect(6);
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.height(30); $div.height(30);
...@@ -54,6 +57,9 @@ test("height()", function() { ...@@ -54,6 +57,9 @@ test("height()", function() {
//equals($div.height(), 30, "Test padding specified with percent"); //equals($div.height(), 30, "Test padding specified with percent");
$div.css({ display: "", border: "", padding: "", height: "1px" }); $div.css({ display: "", border: "", padding: "", height: "1px" });
var blah = jQuery("blah");
equals( blah.height(10), blah, "Make sure that setting a height on an empty set returns the set." );
}); });
test("innerWidth()", function() { test("innerWidth()", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment