Skip to content

Commit afb34fe

Browse files
gibson042dmethvin
authored andcommitted
Scalarize [value, easing] before css-expanding; closes jquerygh-750.
1 parent 56d5c1c commit afb34fe

File tree

2 files changed

+77
-34
lines changed

2 files changed

+77
-34
lines changed

src/effects.js

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var fxNow, timerId, iframe, iframeDoc,
55
rfxtypes = /^(?:toggle|show|hide)$/,
66
rfxnum = /^([\-+]=)?((?:\d*\.)?\d+)([a-z%]*)$/i,
77
rrun = /\.run$/,
8-
animationPrefilters = [],
8+
animationPrefilters = [ defaultPrefilter ],
99
tweeners = {
1010
"*": [function( prop, value ) {
1111
var end, unit,
@@ -73,10 +73,10 @@ function Animation( elem, properties, options ) {
7373
}),
7474
animation = deferred.promise({
7575
elem: elem,
76+
props: jQuery.extend( {}, properties ),
77+
opts: jQuery.extend( true, { specialEasing: {} }, options ),
7678
originalProperties: properties,
7779
originalOptions: options,
78-
props: jQuery.extend( {}, properties ),
79-
opts: jQuery.extend( {}, options ),
8080
startTime: fxNow || createFxNow(),
8181
duration: options.duration,
8282
finish: finished.done,
@@ -120,7 +120,7 @@ function Animation( elem, properties, options ) {
120120
}),
121121
props = animation.props;
122122

123-
propFilter( props );
123+
propFilter( props, animation.opts.specialEasing );
124124

125125
for ( ; index < length ; index++ ) {
126126
result = animationPrefilters[ index ].call( animation,
@@ -142,30 +142,39 @@ function Animation( elem, properties, options ) {
142142
return animation;
143143
}
144144

145-
function propFilter( props ) {
146-
var index, name, hooks, replace;
145+
function propFilter( props, specialEasing ) {
146+
var index, name, easing, value, hooks;
147147

148-
// camelCase and expand cssHook pass
148+
// camelCase, specialEasing and expand cssHook pass
149149
for ( index in props ) {
150150
name = jQuery.camelCase( index );
151+
easing = specialEasing[ name ];
152+
value = props[ index ];
153+
if ( jQuery.isArray( value ) ) {
154+
easing = value[ 1 ];
155+
value = props[ index ] = value[ 0 ];
156+
}
157+
151158
if ( index !== name ) {
152-
props[ name ] = props[ index ];
159+
props[ name ] = value;
153160
delete props[ index ];
154161
}
155162

156163
hooks = jQuery.cssHooks[ name ];
157164
if ( hooks && "expand" in hooks ) {
158-
replace = hooks.expand( props[ name ] );
165+
value = hooks.expand( value );
159166
delete props[ name ];
160167

161168
// not quite $.extend, this wont overwrite keys already present.
162169
// also - reusing 'index' from above because we have the correct "name"
163-
for ( index in replace ) {
164-
if ( index in props ) {
165-
continue;
170+
for ( index in value ) {
171+
if ( !( index in props ) ) {
172+
props[ index ] = value[ index ];
173+
specialEasing[ index ] = easing;
166174
}
167-
props[ index ] = replace[ index ];
168175
}
176+
} else {
177+
specialEasing[ name ] = easing;
169178
}
170179
}
171180
}
@@ -200,19 +209,12 @@ jQuery.Animation = jQuery.extend( Animation, {
200209
}
201210
});
202211

203-
Animation.prefilter(function( elem, props, opts ) {
204-
var index, value,
205-
style = elem.style;
206-
207-
// custom easing pass
208-
opts.specialEasing = opts.specialEasing || {};
209-
for ( index in props ) {
210-
value = props[ index ];
211-
if ( jQuery.isArray( value ) ) {
212-
opts.specialEasing[ index ] = value[ 1 ];
213-
value = props[ index ] = value[ 0 ];
214-
}
215-
}
212+
function defaultPrefilter( elem, props, opts ) {
213+
var index, prop, value, length, dataShow, tween,
214+
style = elem.style,
215+
orig = {},
216+
handled = [],
217+
hidden = jQuery( elem ).is(":hidden");
216218

217219
// height/width overflow pass
218220
if ( elem.nodeType === 1 && ( props.height || props.width ) ) {
@@ -246,15 +248,9 @@ Animation.prefilter(function( elem, props, opts ) {
246248
style.overflowY = opts.overflow[ 2 ];
247249
});
248250
}
249-
});
250251

251-
// special case show/hide prefilter
252-
Animation.prefilter(function( elem, props, opts ) {
253-
var index, prop, value, length, dataShow, tween,
254-
orig = {},
255-
handled = [],
256-
hidden = jQuery( elem ).is(":hidden");
257252

253+
// show/hide pass
258254
for ( index in props ) {
259255
value = props[ index ];
260256
if ( rfxtypes.exec( value ) ) {
@@ -297,7 +293,7 @@ Animation.prefilter(function( elem, props, opts ) {
297293
}
298294
}
299295
}
300-
});
296+
}
301297

302298
function Tween( elem, options, prop, end, easing ) {
303299
return new Tween.prototype.init( elem, options, prop, end, easing );

test/unit/effects.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,53 @@ test("animate with per-property easing", function(){
12481248

12491249
});
12501250

1251+
test("animate with CSS shorthand properties", function(){
1252+
expect(11);
1253+
stop();
1254+
1255+
var _default_count = 0,
1256+
_special_count = 0,
1257+
propsBasic = { padding: "10 20 30" },
1258+
propsSpecial = { padding: [ "1 2 3", "_special" ] };
1259+
1260+
jQuery.easing["_default"] = function(p) {
1261+
if ( p >= 1 ) {
1262+
_default_count++;
1263+
}
1264+
return p;
1265+
};
1266+
1267+
jQuery.easing["_special"] = function(p) {
1268+
if ( p >= 1 ) {
1269+
_special_count++;
1270+
}
1271+
return p;
1272+
};
1273+
1274+
jQuery("#foo")
1275+
.animate( propsBasic, 200, "_default", function() {
1276+
equal( this.style.paddingTop, "10px", "padding-top was animated" );
1277+
equal( this.style.paddingLeft, "20px", "padding-left was animated" );
1278+
equal( this.style.paddingRight, "20px", "padding-right was animated" );
1279+
equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
1280+
equal( _default_count, 4, "per-animation default easing called for each property" );
1281+
_default_count = 0;
1282+
})
1283+
.animate( propsSpecial, 200, "_default", function() {
1284+
equal( this.style.paddingTop, "1px", "padding-top was animated again" );
1285+
equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
1286+
equal( this.style.paddingRight, "2px", "padding-right was animated again" );
1287+
equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
1288+
equal( _default_count, 0, "per-animation default easing not called" );
1289+
equal( _special_count, 4, "special easing called for each property" );
1290+
1291+
jQuery(this).css("padding", "0");
1292+
delete jQuery.easing["_default"];
1293+
delete jQuery.easing["_special"];
1294+
start();
1295+
});
1296+
});
1297+
12511298
test("hide hidden elements (bug #7141)", function() {
12521299
expect(3);
12531300
QUnit.reset();

0 commit comments

Comments
 (0)