Skip to content

Commit 1f85ded

Browse files
committed
Effects: add back support.shrinkWrapBlocks() for ie6
1 parent 24ada82 commit 1f85ded

File tree

7 files changed

+148
-27
lines changed

7 files changed

+148
-27
lines changed

src/effects.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define( [
22
"./core",
3-
"./support",
3+
"./effects/support",
44
"./var/rcssNum",
55
"./var/rnotwhite",
66
"./css/var/cssExpand",
@@ -133,11 +133,13 @@ function defaultPrefilter( elem, props, opts ) {
133133

134134
if ( opts.overflow ) {
135135
style.overflow = "hidden";
136-
anim.always( function() {
137-
style.overflow = opts.overflow[ 0 ];
138-
style.overflowX = opts.overflow[ 1 ];
139-
style.overflowY = opts.overflow[ 2 ];
140-
} );
136+
if ( !support.shrinkWrapBlocks() ) {
137+
anim.always( function() {
138+
style.overflow = opts.overflow[ 0 ];
139+
style.overflowX = opts.overflow[ 1 ];
140+
style.overflowY = opts.overflow[ 2 ];
141+
} );
142+
}
141143
}
142144

143145
// show/hide pass

src/effects/support.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
define( [
2+
"../var/support",
3+
"../var/document"
4+
], function( support, document ) {
5+
6+
( function() {
7+
var shrinkWrapBlocksVal;
8+
9+
support.shrinkWrapBlocks = function() {
10+
if ( shrinkWrapBlocksVal != null ) {
11+
return shrinkWrapBlocksVal;
12+
}
13+
14+
// Will be changed later if needed.
15+
shrinkWrapBlocksVal = false;
16+
17+
// Minified: var b,c,d
18+
var div, body, container;
19+
20+
body = document.getElementsByTagName( "body" )[ 0 ];
21+
if ( !body || !body.style ) {
22+
23+
// Test fired too early or in an unsupported environment, exit.
24+
return;
25+
}
26+
27+
// Setup
28+
div = document.createElement( "div" );
29+
container = document.createElement( "div" );
30+
container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px";
31+
body.appendChild( container ).appendChild( div );
32+
33+
// Support: IE6
34+
// Check if elements with layout shrink-wrap their children
35+
if ( typeof div.style.zoom !== "undefined" ) {
36+
37+
// Reset CSS: box-sizing; display; margin; border
38+
div.style.cssText =
39+
40+
// Support: Firefox<29, Android 2.3
41+
// Vendor-prefix box-sizing
42+
"-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
43+
"box-sizing:content-box;display:block;margin:0;border:0;" +
44+
"padding:1px;width:1px;zoom:1";
45+
div.appendChild( document.createElement( "div" ) ).style.width = "5px";
46+
shrinkWrapBlocksVal = div.offsetWidth !== 3;
47+
}
48+
49+
body.removeChild( container );
50+
51+
return shrinkWrapBlocksVal;
52+
};
53+
54+
} )();
55+
56+
return support;
57+
58+
} );

src/offset.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ define( [
1616
// BuildExclude
1717
curCSS = curCSS.curCSS;
1818

19-
var docElem = window.document.documentElement;
20-
2119
/**
2220
* Gets a window from an element
2321
*/
@@ -162,13 +160,13 @@ jQuery.fn.extend( {
162160

163161
offsetParent: function() {
164162
return this.map( function() {
165-
var offsetParent = this.offsetParent || docElem;
163+
var offsetParent = this.offsetParent;
166164

167165
while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) &&
168166
jQuery.css( offsetParent, "position" ) === "static" ) ) {
169167
offsetParent = offsetParent.offsetParent;
170168
}
171-
return offsetParent || docElem;
169+
return offsetParent || documentElement;
172170
} );
173171
}
174172
} );
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<style>
6+
* {
7+
-webkit-box-sizing: border-box;
8+
-moz-box-sizing: border-box;
9+
box-sizing: border-box;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<div>
15+
<script src="../../jquery.js"></script>
16+
</div>
17+
<script>
18+
jQuery(function() {
19+
window.parent.iframeCallback( jQuery.support.shrinkWrapBlocks() );
20+
});
21+
</script>
22+
</body>
23+
</html>

test/unit/basic.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ QUnit.test( "manipulation", function( assert ) {
209209
QUnit.test( "offset", function( assert ) {
210210
assert.expect( 3 );
211211

212-
var parent = jQuery( "<div style='position:fixed;top:20px;'/>" ).appendTo( "#qunit-fixture" ),
212+
var parent =
213+
jQuery( "<div style='position:fixed;_position:absolute;top:20px;'/>" )
214+
.appendTo( "body" ),
213215
elem = jQuery( "<div style='position:absolute;top:5px;'/>" ).appendTo( parent );
214216

215217
assert.strictEqual( elem.offset().top, 25, ".offset getter" );

test/unit/effects.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,10 +1049,11 @@ jQuery.each( {
10491049

10501050
QUnit.test( "Effects chaining", function() {
10511051
var remaining = 16,
1052+
shrinkwrap = jQuery.support.shrinkWrapBlocks(),
10521053
props = [ "opacity", "height", "width", "display", "overflow" ],
1053-
setup = function( name, selector ) {
1054+
setup = function( name, selector, hiddenOverflow ) {
10541055
var $el = jQuery( selector );
1055-
return $el.data( getProps( $el[0] ) ).data( "name", name );
1056+
return $el.data( getProps( $el[0], hiddenOverflow ) ).data( "name", name );
10561057
},
10571058
assert = function() {
10581059
var data = jQuery.data( this ),
@@ -1073,19 +1074,21 @@ QUnit.test( "Effects chaining", function() {
10731074

10741075
expect( remaining );
10751076

1077+
// We need to pass jQuery.support.shrinkWrapBlocks for all methods that
1078+
// set overflow hidden (slide* and show/hide with speed)
10761079
setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", assert );
10771080
setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", assert );
1078-
setup( ".hide().show()", "#show div" ).hide("fast").show( "fast", assert );
1079-
setup( ".show().hide()", "#hide div" ).show("fast").hide( "fast", assert );
1080-
setup( ".show().hide(easing)", "#easehide div" ).show("fast").hide( "fast", "linear", assert );
1081-
setup( ".toggle().toggle() - in", "#togglein div" ).toggle("fast").toggle( "fast", assert );
1082-
setup( ".toggle().toggle() - out", "#toggleout div" ).toggle("fast").toggle( "fast", assert );
1083-
setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle("fast").toggle( "fast", "linear", assert );
1084-
setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown("fast").slideUp( "fast", assert );
1085-
setup( ".slideUp().slideDown()", "#slideup div" ).slideUp("fast").slideDown( "fast", assert );
1086-
setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp("fast").slideDown( "fast", "linear", assert );
1087-
setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle("fast").slideToggle( "fast", assert );
1088-
setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle("fast").slideToggle( "fast", assert );
1081+
setup( ".hide().show()", "#show div", shrinkwrap ).hide("fast").show( "fast", assert );
1082+
setup( ".show().hide()", "#hide div", shrinkwrap ).show("fast").hide( "fast", assert );
1083+
setup( ".show().hide(easing)", "#easehide div", shrinkwrap ).show("fast").hide( "fast", "linear", assert );
1084+
setup( ".toggle().toggle() - in", "#togglein div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
1085+
setup( ".toggle().toggle() - out", "#toggleout div", shrinkwrap ).toggle("fast").toggle( "fast", assert );
1086+
setup( ".toggle().toggle(easing) - out", "#easetoggleout div", shrinkwrap ).toggle("fast").toggle( "fast", "linear", assert );
1087+
setup( ".slideDown().slideUp()", "#slidedown div", shrinkwrap ).slideDown("fast").slideUp( "fast", assert );
1088+
setup( ".slideUp().slideDown()", "#slideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", assert );
1089+
setup( ".slideUp().slideDown(easing)", "#easeslideup div", shrinkwrap ).slideUp("fast").slideDown( "fast", "linear", assert );
1090+
setup( ".slideToggle().slideToggle() - in", "#slidetogglein div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
1091+
setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div", shrinkwrap ).slideToggle("fast").slideToggle( "fast", assert );
10891092
setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert );
10901093
setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert );
10911094
setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert );
@@ -1919,8 +1922,12 @@ QUnit.test( "Animate properly sets overflow hidden when animating width/height (
19191922
equal( div.css( "overflow" ), "hidden",
19201923
"overflow: hidden set when animating " + prop + " to " + value );
19211924
div.stop();
1922-
equal( div.css( "overflow" ), "auto",
1923-
"overflow: auto restored after animating " + prop + " to " + value );
1925+
if ( jQuery.support.shrinkWrapBlocks() ) {
1926+
ok( true, "cannot restore overflow, shrinkWrapBlocks" );
1927+
} else {
1928+
equal( div.css( "overflow" ), "auto",
1929+
"overflow: auto restored after animating " + prop + " to " + value );
1930+
}
19241931
} );
19251932
} );
19261933
} );

test/unit/support.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ QUnit.test( "zoom of doom (#13089)", function( assert ) {
2525
} else {
2626
ok( !document.body.style.zoom, "No zoom added to the body" );
2727
}
28-
});
28+
} );
2929

3030
if ( jQuery.css ) {
3131
testIframeWithCallback(
@@ -48,6 +48,18 @@ if ( jQuery.css ) {
4848
} );
4949
}
5050
);
51+
52+
testIframeWithCallback(
53+
"box-sizing does not affect jQuery.support.shrinkWrapBlocks",
54+
"support/shrinkWrapBlocks.html",
55+
function( shrinkWrapBlocks, assert ) {
56+
assert.expect( 1 );
57+
assert.strictEqual(
58+
shrinkWrapBlocks,
59+
computedSupport.shrinkWrapBlocks,
60+
"jQuery.support.shrinkWrapBlocks properties are the same"
61+
);
62+
} );
5163
}
5264

5365
testIframeWithCallback(
@@ -116,6 +128,7 @@ testIframeWithCallback(
116128
"reliableHiddenOffsets": true,
117129
"reliableMarginRight": true,
118130
"reliableMarginLeft": true,
131+
"shrinkWrapBlocks": false,
119132
"style": true,
120133
"submit": true,
121134
"tbody": true
@@ -156,6 +169,7 @@ testIframeWithCallback(
156169
"reliableHiddenOffsets": true,
157170
"reliableMarginRight": true,
158171
"reliableMarginLeft": false,
172+
"shrinkWrapBlocks": false,
159173
"style": true,
160174
"submit": true,
161175
"tbody": true
@@ -196,6 +210,7 @@ testIframeWithCallback(
196210
"reliableHiddenOffsets": true,
197211
"reliableMarginRight": true,
198212
"reliableMarginLeft": true,
213+
"shrinkWrapBlocks": false,
199214
"style": true,
200215
"submit": true,
201216
"tbody": true
@@ -236,6 +251,7 @@ testIframeWithCallback(
236251
"reliableHiddenOffsets": true,
237252
"reliableMarginRight": true,
238253
"reliableMarginLeft": true,
254+
"shrinkWrapBlocks": false,
239255
"style": true,
240256
"submit": true,
241257
"tbody": true
@@ -276,6 +292,7 @@ testIframeWithCallback(
276292
"reliableHiddenOffsets": false,
277293
"reliableMarginRight": true,
278294
"reliableMarginLeft": false,
295+
"shrinkWrapBlocks": false,
279296
"style": false,
280297
"submit": false,
281298
"tbody": true
@@ -316,6 +333,7 @@ testIframeWithCallback(
316333
"reliableHiddenOffsets": false,
317334
"reliableMarginRight": true,
318335
"reliableMarginLeft": false,
336+
"shrinkWrapBlocks": false,
319337
"style": false,
320338
"submit": false,
321339
"tbody": false
@@ -356,6 +374,7 @@ testIframeWithCallback(
356374
"reliableHiddenOffsets": false,
357375
"reliableMarginRight": true,
358376
"reliableMarginLeft": false,
377+
"shrinkWrapBlocks": true,
359378
"style": false,
360379
"submit": false,
361380
"tbody": false
@@ -399,6 +418,7 @@ testIframeWithCallback(
399418
"reliableHiddenOffsets": true,
400419
"reliableMarginRight": true,
401420
"reliableMarginLeft": true,
421+
"shrinkWrapBlocks": false,
402422
"style": true,
403423
"submit": true,
404424
"tbody": true
@@ -439,6 +459,7 @@ testIframeWithCallback(
439459
"reliableHiddenOffsets": true,
440460
"reliableMarginRight": true,
441461
"reliableMarginLeft": true,
462+
"shrinkWrapBlocks": false,
442463
"style": true,
443464
"submit": true,
444465
"tbody": true
@@ -479,6 +500,7 @@ testIframeWithCallback(
479500
"reliableHiddenOffsets": true,
480501
"reliableMarginRight": true,
481502
"reliableMarginLeft": true,
503+
"shrinkWrapBlocks": false,
482504
"style": true,
483505
"submit": true,
484506
"tbody": true
@@ -519,6 +541,7 @@ testIframeWithCallback(
519541
"reliableHiddenOffsets": true,
520542
"reliableMarginRight": true,
521543
"reliableMarginLeft": false,
544+
"shrinkWrapBlocks": false,
522545
"style": true,
523546
"submit": true,
524547
"tbody": true
@@ -559,6 +582,7 @@ testIframeWithCallback(
559582
"reliableHiddenOffsets": true,
560583
"reliableMarginRight": true,
561584
"reliableMarginLeft": true,
585+
"shrinkWrapBlocks": false,
562586
"style": true,
563587
"submit": true,
564588
"tbody": true
@@ -599,6 +623,7 @@ testIframeWithCallback(
599623
"reliableHiddenOffsets": true,
600624
"reliableMarginRight": true,
601625
"reliableMarginLeft": false,
626+
"shrinkWrapBlocks": false,
602627
"style": true,
603628
"submit": true,
604629
"tbody": true
@@ -639,6 +664,7 @@ testIframeWithCallback(
639664
"reliableHiddenOffsets": true,
640665
"reliableMarginRight": true,
641666
"reliableMarginLeft": true,
667+
"shrinkWrapBlocks": false,
642668
"style": true,
643669
"submit": true,
644670
"tbody": true
@@ -679,6 +705,7 @@ testIframeWithCallback(
679705
"reliableHiddenOffsets": true,
680706
"reliableMarginRight": true,
681707
"reliableMarginLeft": true,
708+
"shrinkWrapBlocks": false,
682709
"style": true,
683710
"submit": true,
684711
"tbody": true
@@ -719,6 +746,7 @@ testIframeWithCallback(
719746
"reliableHiddenOffsets": true,
720747
"reliableMarginRight": true,
721748
"reliableMarginLeft": true,
749+
"shrinkWrapBlocks": false,
722750
"style": true,
723751
"submit": true,
724752
"tbody": true
@@ -759,6 +787,7 @@ testIframeWithCallback(
759787
"reliableHiddenOffsets": true,
760788
"reliableMarginRight": true,
761789
"reliableMarginLeft": true,
790+
"shrinkWrapBlocks": false,
762791
"style": true,
763792
"submit": true,
764793
"tbody": true
@@ -799,6 +828,7 @@ testIframeWithCallback(
799828
"reliableHiddenOffsets": true,
800829
"reliableMarginRight": true,
801830
"reliableMarginLeft": true,
831+
"shrinkWrapBlocks": false,
802832
"style": true,
803833
"submit": true,
804834
"tbody": true
@@ -839,6 +869,7 @@ testIframeWithCallback(
839869
"reliableHiddenOffsets": true,
840870
"reliableMarginRight": true,
841871
"reliableMarginLeft": true,
872+
"shrinkWrapBlocks": false,
842873
"style": true,
843874
"submit": true,
844875
"tbody": true

0 commit comments

Comments
 (0)