IE6 will shrink-wrap elements with layout instead of allowing content to flow outside of the border-box. Add a test for this and do not remove the overflow property after an animation in IE6.
This commit is contained in:
parent
329b750af6
commit
5057ff9f43
33
src/effects.js
vendored
33
src/effects.js
vendored
|
@ -36,17 +36,23 @@ jQuery.fn.extend({
|
||||||
return this.animate( genFx("show", 3), speed, easing, callback);
|
return this.animate( genFx("show", 3), speed, easing, callback);
|
||||||
} else {
|
} else {
|
||||||
for ( var i = 0, j = this.length; i < j; i++ ) {
|
for ( var i = 0, j = this.length; i < j; i++ ) {
|
||||||
|
// Reset the inline display of this element to learn if it is
|
||||||
|
// being hidden by cascaded rules or not
|
||||||
|
if ( !jQuery.data(this[i], "olddisplay") && this[i].style.display === "none" ) {
|
||||||
|
this[i].style.display = "";
|
||||||
|
}
|
||||||
|
|
||||||
// Set elements which have been overridden with display: none
|
// Set elements which have been overridden with display: none
|
||||||
// in a stylesheet to whatever the default browser style is
|
// in a stylesheet to whatever the default browser style is
|
||||||
// for such an element
|
// for such an element
|
||||||
if ( jQuery.css( this[i], "display" ) === "none" && this[i].style.display !== "none" ) {
|
if ( jQuery.css( this[i], "display" ) === "none" && this[i].style.display === "" ) {
|
||||||
jQuery.data(this[i], "olddisplay", defaultDisplay(this[i].nodeName));
|
jQuery.data(this[i], "olddisplay", defaultDisplay(this[i].nodeName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the display of the elements in a second loop
|
// Set the display of most of the elements in a second loop
|
||||||
// to avoid the constant reflow
|
// to avoid the constant reflow
|
||||||
for ( i = 0, j = this.length; i < j; i++ ) {
|
for ( i = 0; i < j; i++ ) {
|
||||||
this[i].style.display = jQuery.data(this[i], "olddisplay") || "";
|
this[i].style.display = jQuery.data(this[i], "olddisplay") || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,17 +65,17 @@ jQuery.fn.extend({
|
||||||
return this.animate( genFx("hide", 3), speed, easing, callback);
|
return this.animate( genFx("hide", 3), speed, easing, callback);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
for ( var i = 0, j = this.length; i < j; i++ ) {
|
||||||
var old = jQuery.data(this[i], "olddisplay");
|
var old = jQuery.data(this[i], "olddisplay");
|
||||||
if ( !old && old !== "none" ) {
|
if ( !old ) {
|
||||||
jQuery.data( this[i], "olddisplay", jQuery.css( this[i], "display" ) );
|
jQuery.data( this[i], "olddisplay", jQuery.css( this[i], "display" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the display of the elements in a second loop
|
// Set the display of the elements in a second loop
|
||||||
// to avoid the constant reflow
|
// to avoid the constant reflow
|
||||||
for ( var j = 0, k = this.length; j < k; j++ ) {
|
for ( i = 0; i < j; i++ ) {
|
||||||
this[j].style.display = "none";
|
this[i].style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -115,7 +121,8 @@ jQuery.fn.extend({
|
||||||
// test suite
|
// test suite
|
||||||
|
|
||||||
var opt = jQuery.extend({}, optall), p,
|
var opt = jQuery.extend({}, optall), p,
|
||||||
hidden = this.nodeType === 1 && jQuery(this).is(":hidden"),
|
isElement = this.nodeType === 1,
|
||||||
|
hidden = isElement && jQuery(this).is(":hidden"),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
for ( p in prop ) {
|
for ( p in prop ) {
|
||||||
|
@ -131,7 +138,7 @@ jQuery.fn.extend({
|
||||||
return opt.complete.call(this);
|
return opt.complete.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( p === "height" || p === "width" ) ) {
|
if ( isElement && ( p === "height" || p === "width" ) ) {
|
||||||
// Make sure that nothing sneaks out
|
// Make sure that nothing sneaks out
|
||||||
// Record all 3 overflow attributes because IE does not
|
// Record all 3 overflow attributes because IE does not
|
||||||
// change the overflow attribute when overflowX and
|
// change the overflow attribute when overflowX and
|
||||||
|
@ -141,8 +148,8 @@ jQuery.fn.extend({
|
||||||
// Set display property to inline-block for height/width
|
// Set display property to inline-block for height/width
|
||||||
// animations on inline elements that are having width/height
|
// animations on inline elements that are having width/height
|
||||||
// animated
|
// animated
|
||||||
if ( jQuery.curCSS( this, "display" ) === "inline" &&
|
if ( jQuery.css( this, "display" ) === "inline" &&
|
||||||
jQuery.curCSS( this, "float" ) === "none" ) {
|
jQuery.css( this, "float" ) === "none" ) {
|
||||||
if ( !jQuery.support.inlineBlockNeedsLayout ) {
|
if ( !jQuery.support.inlineBlockNeedsLayout ) {
|
||||||
this.style.display = "inline-block";
|
this.style.display = "inline-block";
|
||||||
} else {
|
} else {
|
||||||
|
@ -168,7 +175,7 @@ jQuery.fn.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( opt.overflow != null ) {
|
if ( opt.overflow != null || (jQuery.support.shrinkWrapBlocks && isElement) ) {
|
||||||
this.style.overflow = "hidden";
|
this.style.overflow = "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +408,7 @@ jQuery.fx.prototype = {
|
||||||
|
|
||||||
if ( done ) {
|
if ( done ) {
|
||||||
// Reset the overflow
|
// Reset the overflow
|
||||||
if ( this.options.overflow != null ) {
|
if ( this.options.overflow != null && (!jQuery.support.shrinkWrapBlocks || !jQuery.css( this.elem, "hasLayout" )) ) {
|
||||||
this.elem.style.overflow = this.options.overflow[0];
|
this.elem.style.overflow = this.options.overflow[0];
|
||||||
this.elem.style.overflowX = this.options.overflow[1];
|
this.elem.style.overflowX = this.options.overflow[1];
|
||||||
this.elem.style.overflowY = this.options.overflow[2];
|
this.elem.style.overflowY = this.options.overflow[2];
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
noCloneEvent: true,
|
noCloneEvent: true,
|
||||||
boxModel: null,
|
boxModel: null,
|
||||||
inlineBlockNeedsLayout: false,
|
inlineBlockNeedsLayout: false,
|
||||||
|
shrinkWrapBlocks: false,
|
||||||
reliableHiddenOffsets: true
|
reliableHiddenOffsets: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -120,17 +121,25 @@
|
||||||
document.body.appendChild( div );
|
document.body.appendChild( div );
|
||||||
jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
|
jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
|
||||||
|
|
||||||
// Check if natively block-level elements act like inline-block
|
|
||||||
// elements when setting their display to 'inline'
|
|
||||||
// (IE < 8 does this)
|
|
||||||
if ( 'zoom' in div.style ) {
|
if ( 'zoom' in div.style ) {
|
||||||
|
// Check if natively block-level elements act like inline-block
|
||||||
|
// elements when setting their display to 'inline' and giving
|
||||||
|
// them layout
|
||||||
|
// (IE < 8 does this)
|
||||||
div.style.display = 'inline';
|
div.style.display = 'inline';
|
||||||
|
|
||||||
// Layout is necessary to trigger this “feature”
|
|
||||||
div.style.zoom = 1;
|
div.style.zoom = 1;
|
||||||
jQuery.support.inlineBlockNeedsLayout = div.offsetWidth === 2;
|
jQuery.support.inlineBlockNeedsLayout = div.offsetWidth === 2;
|
||||||
|
|
||||||
|
// Check if elements with layout shrink-wrap their children
|
||||||
|
// (IE 6 does this)
|
||||||
|
div.style.display = '';
|
||||||
|
div.innerHTML = '<div style="width:4px;"></div>';
|
||||||
|
jQuery.support.shrinkWrapBlocks = div.offsetWidth !== 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.innerHTML = '<table><tr><td style="padding:0;display:none"></td><td>t</td></tr></table>';
|
||||||
|
var tds = div.getElementsByTagName('td');
|
||||||
|
|
||||||
// Check if table cells still have offsetWidth/Height when they are set
|
// Check if table cells still have offsetWidth/Height when they are set
|
||||||
// to display:none and there are still other visible table cells in a
|
// to display:none and there are still other visible table cells in a
|
||||||
// table row; if so, offsetWidth/Height are not reliable for use when
|
// table row; if so, offsetWidth/Height are not reliable for use when
|
||||||
|
@ -138,12 +147,18 @@
|
||||||
// display:none (it is still safe to use offsets if a parent element is
|
// display:none (it is still safe to use offsets if a parent element is
|
||||||
// hidden; don safety goggles and see bug #4512 for more information).
|
// hidden; don safety goggles and see bug #4512 for more information).
|
||||||
// (only IE 8 fails this test)
|
// (only IE 8 fails this test)
|
||||||
div.innerHTML = '<table><tr><td style="display:none"></td><td>t</td></tr></table>';
|
jQuery.support.reliableHiddenOffsets = tds[0].offsetHeight === 0;
|
||||||
jQuery.support.reliableHiddenOffsets = div.getElementsByTagName('td')[0].offsetHeight === 0;
|
|
||||||
|
tds[0].style.display = '';
|
||||||
|
tds[1].style.display = 'none';
|
||||||
|
|
||||||
|
// Check if empty table cells still have offsetWidth/Height
|
||||||
|
// (IE < 8 fail this test)
|
||||||
|
jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0;
|
||||||
div.innerHTML = '';
|
div.innerHTML = '';
|
||||||
|
|
||||||
document.body.removeChild( div ).style.display = 'none';
|
document.body.removeChild( div ).style.display = 'none';
|
||||||
div = null;
|
div = tds = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Technique from Juriy Zaytsev
|
// Technique from Juriy Zaytsev
|
||||||
|
|
47
test/unit/effects.js
vendored
47
test/unit/effects.js
vendored
|
@ -37,6 +37,7 @@ test("show()", function() {
|
||||||
ok( pass, "Show with " + name + " does not call animate callback" );
|
ok( pass, "Show with " + name + " does not call animate callback" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// #show-tests * is set display: none in CSS
|
||||||
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
|
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
|
||||||
|
|
||||||
var old = jQuery("#show-tests table").show().css("display") !== "table";
|
var old = jQuery("#show-tests table").show().css("display") !== "table";
|
||||||
|
@ -69,6 +70,7 @@ test("show(Number) - other displays", function() {
|
||||||
QUnit.reset();
|
QUnit.reset();
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
// #show-tests * is set display: none in CSS
|
||||||
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
|
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
|
||||||
|
|
||||||
var old = jQuery("#show-tests table").show().css("display") !== "table",
|
var old = jQuery("#show-tests table").show().css("display") !== "table",
|
||||||
|
@ -124,7 +126,7 @@ test("animate negative height", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("animate inline width/height", function() {
|
test("animate block as inline width/height", function() {
|
||||||
expect(3);
|
expect(3);
|
||||||
stop();
|
stop();
|
||||||
jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
|
jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
|
||||||
|
@ -135,6 +137,20 @@ test("animate inline width/height", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("animate native inline width/height", function() {
|
||||||
|
expect(3);
|
||||||
|
stop();
|
||||||
|
jQuery("#foo").css({ display: "", width: '', height: '' })
|
||||||
|
.append('<span>text</span>')
|
||||||
|
.children('span')
|
||||||
|
.animate({ width: 42, height: 42 }, 100, function() {
|
||||||
|
equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
|
||||||
|
equals( this.offsetWidth, 42, "width was animated" );
|
||||||
|
equals( this.offsetHeight, 42, "height was animated" );
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("animate block width/height", function() {
|
test("animate block width/height", function() {
|
||||||
expect(3);
|
expect(3);
|
||||||
stop();
|
stop();
|
||||||
|
@ -158,12 +174,31 @@ test("animate table width/height", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("animate table-row width/height", function() {
|
||||||
|
expect(3);
|
||||||
|
stop();
|
||||||
|
var tr = jQuery("#table")
|
||||||
|
.attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
|
||||||
|
.html("<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
|
||||||
|
.find("tr");
|
||||||
|
|
||||||
|
// IE<8 uses “block” instead of the correct display type
|
||||||
|
var displayMode = tr.css("display") !== "table-row" ? "block" : "table-row";
|
||||||
|
|
||||||
|
tr.animate({ width: 10, height: 10 }, 100, function() {
|
||||||
|
equals( jQuery(this).css("display"), displayMode, "display mode is correct" );
|
||||||
|
equals( this.offsetWidth, 20, "width animated to shrink wrap point" );
|
||||||
|
equals( this.offsetHeight, 20, "height animated to shrink wrap point" );
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("animate table-cell width/height", function() {
|
test("animate table-cell width/height", function() {
|
||||||
expect(3);
|
expect(3);
|
||||||
stop();
|
stop();
|
||||||
var td = jQuery("#table")
|
var td = jQuery("#table")
|
||||||
.attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
|
.attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
|
||||||
.append("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
|
.html("<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>")
|
||||||
.find("td");
|
.find("td");
|
||||||
|
|
||||||
// IE<8 uses “block” instead of the correct display type
|
// IE<8 uses “block” instead of the correct display type
|
||||||
|
@ -425,9 +460,10 @@ test("toggle()", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.checkOverflowDisplay = function(){
|
jQuery.checkOverflowDisplay = function(){
|
||||||
var o = jQuery.css( this, "overflow" );
|
var o = jQuery.css( this, "overflow" ),
|
||||||
|
expected = jQuery.support.shrinkWrapBlocks ? "hidden" : "visible";
|
||||||
|
|
||||||
equals(o, "visible", "Overflow should be visible: " + o);
|
equals(o, expected, "Overflow should be " + expected + ": " + o);
|
||||||
equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
|
equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
@ -617,6 +653,9 @@ jQuery.checkState = function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
jQuery.each(this.save, function(c,v){
|
jQuery.each(this.save, function(c,v){
|
||||||
var cur = self.style[ c ] || jQuery.css(self, c);
|
var cur = self.style[ c ] || jQuery.css(self, c);
|
||||||
|
if ( c === "overflow" && jQuery.support.shrinkWrapBlocks ) {
|
||||||
|
v = "hidden";
|
||||||
|
}
|
||||||
equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
|
equals( cur, v, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
|
||||||
});
|
});
|
||||||
start();
|
start();
|
||||||
|
|
Loading…
Reference in a new issue