Skip to content
Permalink
Browse files

Fixed #1599 as Brandon suggested to ignore negative values to width a…

…nd height css. The fix itself is slightly different as it was moved to .css() instead of staying in .attr() like in his patch. I decided there was less chance of incorrect behavior (like if someone had an XML file with a width attribute that could be negative). Also took out some unneeded white space while I was in there.
  • Loading branch information
davids549 committed Nov 28, 2007
1 parent 2ccd2cb commit 0a755f6ab38d36ffda02f9ff5a6d606c24a94baa
Showing with 16 additions and 3 deletions.
  1. +6 −3 src/core.js
  2. +1 −0 test/index.html
  3. +9 −0 test/unit/core.js
@@ -43,7 +43,7 @@ jQuery.fn = jQuery.prototype = {
return this;

// Handle HTML strings
} else if ( typeof selector == "string" ) {
} else if ( typeof selector == "string" ) {
// Are we dealing with HTML string or an ID?
var match = quickExpr.exec( selector );

@@ -194,6 +194,9 @@ jQuery.fn = jQuery.prototype = {
},

css: function( key, value ) {
// ignore negative width and height values
if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
value = undefined;
return this.attr( key, value, "curCSS" );
},

@@ -360,7 +363,7 @@ jQuery.fn = jQuery.prototype = {

if ( this.length ) {
var elem = this[0];

// We need to handle select boxes special
if ( jQuery.nodeName( elem, "select" ) ) {
var index = elem.selectedIndex,
@@ -1321,7 +1324,7 @@ jQuery.each([ "Height", "Width" ], function(i, name){
this[0] == document ?
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth)
Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) :

// Get or set width or height on the element
size == undefined ?
// Get width or height on the element
@@ -20,6 +20,7 @@ <h2 id="banner"></h2>
<h2 id="userAgent"></h2>

<!-- Test HTML -->
<div id="nothiddendiv" style="height:1px;background:white;"></div>
<dl id="dl" style="display:none;">
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
@@ -410,6 +410,15 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct
ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
});

test("width()", function() {
expect(2);

$("#nothiddendiv").width(30);
equals($("#nothiddendiv").width(), 30, "Test set to 30 correctly");
$("#nothiddendiv").width(-1); // handle negative numbers by ignoring #1599
equals($("#nothiddendiv").width(), 30, "Test negative width ignored");
});

test("text()", function() {
expect(1);
var expected = "This link has class=\"blog\": Simon Willison's Weblog";

0 comments on commit 0a755f6

Please sign in to comment.
You can’t perform that action at this time.