Skip to content

Commit 65a6c46

Browse files
committed
Effects.*: Style Guidance
1 parent 1c1a3b1 commit 65a6c46

10 files changed

+74
-51
lines changed

ui/jquery.effects.blind.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* jquery.effects.core.js
1212
*/
1313
(function( $, undefined ) {
14-
14+
1515
var rvertical = /up|down|vertical/,
1616
rpositivemotion = /up|left|vertical|horizontal/;
1717

@@ -35,24 +35,24 @@ $.effects.effect.blind = function( o, next ) {
3535
} else {
3636
$.effects.save( el, props );
3737
}
38-
el.show();
39-
wrapper = $.effects.createWrapper( el ).css({
38+
el.show();
39+
wrapper = $.effects.createWrapper( el ).css({
4040
overflow: "hidden"
4141
});
4242

4343
distance = wrapper[ ref ]();
4444

45-
animation[ ref ] = ( mode === "show" ? distance : 0 );
45+
animation[ ref ] = show ? distance : 0;
4646
if ( !motion ) {
4747
el
4848
.css( vertical ? "bottom" : "right", 0 )
4949
.css( vertical ? "top" : "left", "" )
5050
.css({ position: "absolute" });
51-
animation[ ref2 ] = ( mode === "show" ) ? 0 : distance;
51+
animation[ ref2 ] = show ? 0 : distance;
5252
}
5353

5454
// start at 0 if we are showing
55-
if ( mode === "show" ) {
55+
if ( show ) {
5656
wrapper.css( ref, 0 );
5757
if ( ! motion ) {
5858
wrapper.css( ref2, distance );
@@ -65,10 +65,10 @@ $.effects.effect.blind = function( o, next ) {
6565
easing: o.easing,
6666
queue: false,
6767
complete: function() {
68-
if ( mode == "hide" ) {
68+
if ( mode === "hide" ) {
6969
el.hide();
7070
}
71-
$.effects.restore( el, props );
71+
$.effects.restore( el, props );
7272
$.effects.removeWrapper( el );
7373
if ( $.isFunction( o.complete ) ) {
7474
o.complete.apply( el[ 0 ], arguments );

ui/jquery.effects.bounce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ $.effects.effect.bounce = function( o, next ) {
6161
// if we are showing, force opacity 0 and set the initial position
6262
// then do the "first" animation
6363
el.css( "opacity", 0 )
64-
.css( ref, motion ? -distance*2 : distance*2 )
64+
.css( ref, motion ? -distance * 2 : distance * 2 )
6565
.animate( downAnim, speed, easing );
6666
}
6767

ui/jquery.effects.drop.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ $.effects.effect.drop = function( o, next ) {
1717
var el = $( this ),
1818
props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ],
1919
mode = $.effects.setMode( el, o.mode || "hide" ),
20+
show = mode === "show",
2021
direction = o.direction || "left",
21-
ref = ( direction == "up" || direction == "down" ) ? "top" : "left",
22-
motion = ( direction == "up" || direction == "left" ) ? "pos" : "neg",
22+
ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
23+
motion = ( direction === "up" || direction === "left" ) ? "pos" : "neg",
2324
animation = {
24-
opacity: mode == "show" ? 1 : 0
25+
opacity: show ? 1 : 0
2526
},
2627
distance;
2728

@@ -32,14 +33,17 @@ $.effects.effect.drop = function( o, next ) {
3233

3334
distance = o.distance || el[ ref == "top" ? "outerHeight": "outerWidth" ]({ margin: true }) / 2;
3435

35-
if ( mode == "show" ) {
36+
if ( show ) {
3637
el
3738
.css( "opacity", 0 )
3839
.css( ref, motion == "pos" ? -distance : distance );
3940
}
4041

4142
// Animation
42-
animation[ ref ] = ((mode == "show") ? (motion == "pos" ? "+=" : "-=") : (motion == "pos" ? "-=" : "+=")) + distance;
43+
animation[ ref ] = ( show ?
44+
( motion === "pos" ? "+=" : "-=" ) :
45+
( motion === "pos" ? "-=" : "+=" ) )
46+
+ distance;
4347

4448
// Animate
4549
el.animate( animation, {
@@ -50,7 +54,7 @@ $.effects.effect.drop = function( o, next ) {
5054
mode == "hide" && el.hide();
5155
$.effects.restore( el, props );
5256
$.effects.removeWrapper( el );
53-
$.isFunction( o.complete ) && o.complete.apply(this, arguments);
57+
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
5458
next();
5559
}
5660
});

ui/jquery.effects.explode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
$.effects.effect.explode = function( o, next ) {
1616

17-
var rows = o.pieces ? Math.round(Math.sqrt(o.pieces)) : 3,
17+
var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3,
1818
cells = rows,
1919
el = $( this ),
2020
mode = $.effects.setMode( el, o.mode || "hide" ),
21-
show = ( mode == "show" ),
21+
show = mode === "show",
2222

2323
// show and then visibility:hidden the element before calculating offset
2424
offset = el.show().css( "visibility", "hidden" ).offset(),

ui/jquery.effects.fold.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ $.effects.effect.fold = function( o, next ) {
1616

1717
// Create element
1818
var el = $( this ),
19-
props = ["position","top","bottom","left","right","height","width"],
20-
mode = $.effects.setMode(el, o.mode || "hide"),
19+
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
20+
mode = $.effects.setMode( el, o.mode || "hide" ),
21+
show = mode === "show",
22+
hide = mode === "hide",
2123
size = o.size || 15,
22-
percent = /([0-9]+)%/.exec(size),
24+
percent = /([0-9]+)%/.exec( size ),
2325
horizFirst = !!o.horizFirst,
24-
widthFirst = ((mode == "show") != horizFirst),
25-
ref = widthFirst ? ["width", "height"] : ["height", "width"],
26+
widthFirst = show != horizFirst,
27+
ref = widthFirst ? [ "width", "height" ] : [ "height", "width" ],
2628
duration = o.duration / 2,
27-
wrapper, distance;
29+
wrapper, distance,
30+
animation1 = {}, animation2 = {};
2831

2932
$.effects.save( el, props );
3033
el.show();
@@ -38,29 +41,34 @@ $.effects.effect.fold = function( o, next ) {
3841
[ wrapper.height(), wrapper.width() ];
3942

4043
if ( percent ) {
41-
size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ ( mode == "hide") ? 0 : 1 ];
44+
size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ];
4245
}
43-
mode == "show" && wrapper.css( horizFirst ? {
46+
if ( show ) {
47+
wrapper.css( horizFirst ? {
4448
height: 0,
4549
width: size
4650
} : {
4751
height: size,
4852
width: 0
4953
});
54+
}
5055

5156
// Animation
52-
var animation1 = {}, animation2 = {};
53-
animation1[ ref[ 0 ] ] = mode == "show" ? distance[ 0 ] : size;
54-
animation2[ ref[ 1 ] ] = mode == "show" ? distance[ 1 ] : 0;
57+
animation1[ ref[ 0 ] ] = show ? distance[ 0 ] : size;
58+
animation2[ ref[ 1 ] ] = show ? distance[ 1 ] : 0;
5559

5660
// Animate
5761
wrapper
5862
.animate( animation1, duration, o.easing )
5963
.animate( animation2, duration, o.easing, function() {
60-
(mode == "hide") && el.hide();
64+
if ( hide ) {
65+
el.hide();
66+
}
6167
$.effects.restore( el, props );
6268
$.effects.removeWrapper( el );
63-
jQuery.isFunction(o.complete) && o.complete.apply( el[ 0 ], arguments );
69+
if ( $.isFunction( o.complete ) ) {
70+
o.complete.apply( el[ 0 ], arguments );
71+
}
6472
next();
6573
});
6674

ui/jquery.effects.highlight.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $.effects.effect.highlight = function( o, next ) {
2020
backgroundColor: elem.css( "backgroundColor" )
2121
};
2222

23-
if (mode == "hide") {
23+
if (mode === "hide") {
2424
animation.opacity = 0;
2525
}
2626

@@ -37,10 +37,13 @@ $.effects.effect.highlight = function( o, next ) {
3737
duration: o.duration,
3838
easing: o.easing,
3939
complete: function() {
40-
(mode == "hide" && elem.hide());
40+
if ( mode === "hide" ) {
41+
elem.hide();
42+
}
4143
$.effects.restore( elem, props );
42-
(mode == "show" && !$.support.opacity && this.style.removeAttribute( "filter" ));
43-
jQuery.isFunction(o.complete) && o.complete.apply(this, arguments);
44+
if ( $.isFunction( o.complete) ) {
45+
o.complete.apply( this, arguments );
46+
}
4447
next();
4548
}
4649
});

ui/jquery.effects.scale.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function compFunction( el, complete, next ) {
2424
$.effects.effect.puff = function( o, next ) {
2525
var elem = $( this ),
2626
mode = $.effects.setMode( elem, o.mode || "hide" ),
27+
hide = mode === "hide",
2728
percent = parseInt( o.percent, 10 ) || 150,
2829
factor = percent / 100,
2930
original = {
@@ -37,8 +38,8 @@ $.effects.effect.puff = function( o, next ) {
3738
fade: true,
3839
mode: mode,
3940
complete: compFunction( this, o.complete, next ),
40-
percent: mode == "hide" ? percent : 100,
41-
from: mode == "hide"
41+
percent: hide ? percent : 100,
42+
from: hide
4243
? original
4344
: {
4445
height: original.height * factor,

ui/jquery.effects.shake.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $.effects.effect.shake = function( o, next ) {
2323
anims = times * 2 + 1,
2424
speed = o.duration,
2525
ref = (direction == "up" || direction == "down") ? "top" : "left",
26-
motion = (direction == "up" || direction == "left") ? "pos" : "neg",
26+
positiveMotion = (direction == "up" || direction == "left"),
2727
animation = {},
2828
animation1 = {},
2929
animation2 = {},
@@ -39,9 +39,9 @@ $.effects.effect.shake = function( o, next ) {
3939
$.effects.createWrapper( el );
4040

4141
// Animation
42-
animation[ ref ] = ( motion == "pos" ? "-=" : "+=" ) + distance;
43-
animation1[ ref ] = ( motion == "pos" ? "+=" : "-=" ) + distance * 2;
44-
animation2[ ref ] = ( motion == "pos" ? "-=" : "+=" ) + distance * 2;
42+
animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance;
43+
animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2;
44+
animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2;
4545

4646
// Animate
4747
el.animate( animation, speed, o.easing );
@@ -59,7 +59,9 @@ $.effects.effect.shake = function( o, next ) {
5959
}
6060
$.effects.restore( el, props );
6161
$.effects.removeWrapper( el );
62-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
62+
if ( $.isFunction( o.complete ) ) {
63+
o.complete.apply( this, arguments );
64+
}
6365
next();
6466
});
6567

ui/jquery.effects.slide.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,33 @@ $.effects.effect.slide = function( o, next ) {
1818
var el = $( this ),
1919
props = [ "position", "top", "bottom", "left", "right", "width", "height" ],
2020
mode = $.effects.setMode( el, o.mode || "show" ),
21+
show = mode === "show",
2122
direction = o.direction || "left",
2223
ref = (direction == "up" || direction == "down") ? "top" : "left",
23-
motion = (direction == "up" || direction == "left") ? "pos" : "neg",
24+
positiveMotion = (direction == "up" || direction == "left"),
2425
distance,
2526
animation = {},
2627
size;
2728

2829
// Adjust
2930
$.effects.save( el, props );
3031
el.show();
31-
distance = o.distance || el[ ref == "top" ? "outerHeight" : "outerWidth" ]({
32+
distance = o.distance || el[ ref === "top" ? "outerHeight" : "outerWidth" ]({
3233
margin: true
3334
});
3435

3536
$.effects.createWrapper( el ).css({
3637
overflow: "hidden"
3738
});
3839

39-
if (mode == "show") {
40-
el.css( ref, motion == "pos" ? (isNaN(distance) ? "-" + distance : -distance) : distance );
40+
if ( show ) {
41+
el.css( ref, positiveMotion ? (isNaN(distance) ? "-" + distance : -distance) : distance );
4142
}
4243

4344
// Animation
44-
animation[ ref ] = ( mode == "show" ?
45-
(motion == "pos" ? "+=" : "-=") :
46-
(motion == "pos" ? "-=" : "+="))
45+
animation[ ref ] = ( show ?
46+
( positiveMotion ? "+=" : "-=") :
47+
( positiveMotion ? "-=" : "+="))
4748
+ distance;
4849

4950
// Animate
@@ -52,12 +53,14 @@ $.effects.effect.slide = function( o, next ) {
5253
duration: o.duration,
5354
easing: o.easing,
5455
complete: function() {
55-
if ( mode == "hide" ) {
56+
if ( mode === "hide" ) {
5657
el.hide();
5758
}
5859
$.effects.restore( el, props );
5960
$.effects.removeWrapper( el );
60-
$.isFunction(o.complete) && o.complete.apply( this, arguments );
61+
if ( $.isFunction( o.complete ) ) {
62+
o.complete.apply( this, arguments );
63+
}
6164
next();
6265
}
6366
});

ui/jquery.effects.transfer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ $.effects.effect.transfer = function( o, next ) {
3939
})
4040
.animate( animation, o.duration, o.easing, function() {
4141
transfer.remove();
42-
$.isFunction( o.complete ) && o.complete.apply(elem[0], arguments);
42+
if ( $.isFunction( o.complete ) ) {
43+
o.complete.apply( elem[0], arguments );
44+
}
4345
next();
4446
});
4547
};

0 commit comments

Comments
 (0)