Bug Tracker

Changeset 3959

Show
Ignore:
Timestamp:
11/28/07 01:01:49 (11 months ago)
Author:
davidserduke
Message:

Fixed #1599 as Brandon suggested to ignore negative values to width and 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.

Location:
trunk/jquery
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r3958 r3959  
    4444 
    4545        // Handle HTML strings 
    46         } else if ( typeof selector == "string" ) { 
     46        } else if ( typeof selector == "string" ) { 
    4747            // Are we dealing with HTML string or an ID? 
    4848            var match = quickExpr.exec( selector ); 
     
    195195 
    196196    css: function( key, value ) { 
     197        // ignore negative width and height values 
     198        if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) 
     199            value = undefined; 
    197200        return this.attr( key, value, "curCSS" ); 
    198201    }, 
     
    361364            if ( this.length ) { 
    362365                var elem = this[0]; 
    363                  
     366 
    364367                // We need to handle select boxes special 
    365368                if ( jQuery.nodeName( elem, "select" ) ) { 
     
    13221325                // Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth) 
    13231326                Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) : 
    1324          
     1327 
    13251328                // Get or set width or height on the element 
    13261329                size == undefined ? 
  • trunk/jquery/test/index.html

    r3856 r3959  
    2121     
    2222    <!-- Test HTML --> 
     23    <div id="nothiddendiv" style="height:1px;background:white;"></div> 
    2324    <dl id="dl" style="display:none;"> 
    2425    <div id="main" style="display: none;"> 
  • trunk/jquery/test/unit/core.js

    r3856 r3959  
    409409    ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." ); 
    410410    ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." ); 
     411}); 
     412 
     413test("width()", function() { 
     414    expect(2); 
     415 
     416    $("#nothiddendiv").width(30); 
     417    equals($("#nothiddendiv").width(), 30, "Test set to 30 correctly"); 
     418    $("#nothiddendiv").width(-1); // handle negative numbers by ignoring #1599 
     419    equals($("#nothiddendiv").width(), 30, "Test negative width ignored"); 
    411420}); 
    412421