Changeset 4217
- Timestamp:
- 12/18/07 03:53:09 (1 year ago)
- Location:
- trunk/jquery
- Files:
-
- 3 modified
-
src/core.js (modified) (3 diffs)
-
test/index.html (modified) (1 diff)
-
test/unit/core.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/core.js
r4212 r4217 765 765 // A method for quickly swapping in/out CSS properties to get correct calculations 766 766 swap: function( elem, options, callback ) { 767 var old = {}; 767 768 // Remember the old values, and insert the new ones 768 769 for ( var name in options ) { 769 elem.style[ "old" +name ] = elem.style[ name ];770 old[ name ] = elem.style[ name ]; 770 771 elem.style[ name ] = options[ name ]; 771 772 } … … 775 776 // Revert the old values 776 777 for ( var name in options ) 777 elem.style[ name ] = elem.style[ "old" +name ];778 elem.style[ name ] = old[ name ]; 778 779 }, 779 780 780 781 css: function( elem, name, force ) { 781 782 if ( name == "width" || name == "height" ) { 782 var width, height, props = { position: "absolute", visibility: "hidden", display:"block" };783 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; 783 784 784 785 function getWH() { 785 width = elem.clientWidth; 786 height = elem.clientHeight; 786 val = name == "width" ? elem.offsetWidth : elem.offsetHeight; 787 var padding = 0, border = 0; 788 jQuery.each( which, function() { 789 padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; 790 border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; 791 }); 792 val -= Math.round(padding + border); 787 793 } 788 794 … … 791 797 else 792 798 jQuery.swap( elem, props, getWH ); 793 794 return name == "width" ? width : height;799 800 return val; 795 801 } 796 802 -
trunk/jquery/test/index.html
r4196 r4217 21 21 22 22 <!-- Test HTML --> 23 <div id="nothiddendiv" style="height:1px;background:white;"></div> 23 <div id="nothiddendiv" style="height:1px;background:white;"> 24 <div id="nothiddendivchild"></div> 25 </div> 24 26 <!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves --> 25 27 <iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe> -
trunk/jquery/test/unit/core.js
r4212 r4217 474 474 475 475 test("width()", function() { 476 expect(2); 477 478 $("#nothiddendiv").width(30); 479 equals($("#nothiddendiv").width(), 30, "Test set to 30 correctly"); 480 $("#nothiddendiv").width(-1); // handle negative numbers by ignoring #1599 481 equals($("#nothiddendiv").width(), 30, "Test negative width ignored"); 476 expect(9); 477 478 var $div = $("#nothiddendiv"); 479 $div.width(30); 480 equals($div.width(), 30, "Test set to 30 correctly"); 481 $div.width(-1); // handle negative numbers by ignoring #1599 482 equals($div.width(), 30, "Test negative width ignored"); 483 $div.css("padding", "20px"); 484 equals($div.width(), 30, "Test padding specified with pixels"); 485 $div.css("border", "2px solid #fff"); 486 equals($div.width(), 30, "Test border specified with pixels"); 487 $div.css("padding", "2em"); 488 equals($div.width(), 30, "Test padding specified with ems"); 489 $div.css("border", "1em solid #fff"); 490 equals($div.width(), 30, "Test border specified with ems"); 491 $div.css("padding", "2%"); 492 equals($div.width(), 30, "Test padding specified with percent"); 493 $div.hide(); 494 equals($div.width(), 30, "Test hidden div"); 495 496 $div.css({ display: "", border: "", padding: "" }); 497 498 $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" }); 499 equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding"); 500 $("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" }); 501 }); 502 503 test("height()", function() { 504 expect(8); 505 506 var $div = $("#nothiddendiv"); 507 $div.height(30); 508 equals($div.height(), 30, "Test set to 30 correctly"); 509 $div.height(-1); // handle negative numbers by ignoring #1599 510 equals($div.height(), 30, "Test negative height ignored"); 511 $div.css("padding", "20px"); 512 equals($div.height(), 30, "Test padding specified with pixels"); 513 $div.css("border", "2px solid #fff"); 514 equals($div.height(), 30, "Test border specified with pixels"); 515 $div.css("padding", "2em"); 516 equals($div.height(), 30, "Test padding specified with ems"); 517 $div.css("border", "1em solid #fff"); 518 equals($div.height(), 30, "Test border specified with ems"); 519 $div.css("padding", "2%"); 520 equals($div.height(), 30, "Test padding specified with percent"); 521 $div.hide(); 522 equals($div.height(), 30, "Test hidden div"); 523 524 $div.css({ display: "", border: "", padding: "", height: "1px" }); 482 525 }); 483 526
