Skip to content

Commit 7a60bc6

Browse files
committed
effect.*: Style Guidance
1 parent 8ce879e commit 7a60bc6

File tree

3 files changed

+76
-58
lines changed

3 files changed

+76
-58
lines changed

ui/jquery.effects.fold.js

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,59 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.fold = function(o) {
15+
$.effects.fold = function( o ) {
1616

17-
return this.queue(function() {
17+
return this.queue( function() {
1818

1919
// Create element
20-
var el = $(this), props = ['position','top','bottom','left','right'];
21-
22-
// Set options
23-
var mode = $.effects.setMode(el, o.mode || 'hide'); // Set Mode
24-
var size = o.size || 15; // Default fold size
25-
var horizFirst = !(!o.horizFirst); // Ensure a boolean value
26-
var duration = o.duration ? o.duration / 2 : $.fx.speeds._default / 2;
27-
28-
// Adjust
29-
$.effects.save(el, props); el.show(); // Save & Show
30-
var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
31-
var widthFirst = ((mode == 'show') != horizFirst);
32-
var ref = widthFirst ? ['width', 'height'] : ['height', 'width'];
33-
var distance = widthFirst ? [wrapper.width(), wrapper.height()] : [wrapper.height(), wrapper.width()];
34-
var percent = /([0-9]+)%/.exec(size);
35-
if(percent) size = parseInt(percent[1],10) / 100 * distance[mode == 'hide' ? 0 : 1];
36-
if(mode == 'show') wrapper.css(horizFirst ? {height: 0, width: size} : {height: size, width: 0}); // Shift
20+
var el = $( this ),
21+
props = ['position','top','bottom','left','right'],
22+
mode = $.effects.setMode(el, o.mode || 'hide'),
23+
size = o.size || 15,
24+
percent = /([0-9]+)%/.exec(size),
25+
horizFirst = !!o.horizFirst,
26+
widthFirst = ((mode == 'show') != horizFirst),
27+
ref = widthFirst ? ['width', 'height'] : ['height', 'width'],
28+
duration = o.duration / 2,
29+
wrapper, distance;
30+
31+
$.effects.save( el, props );
32+
el.show();
33+
34+
// Create Wrapper
35+
wrapper = $.effects.createWrapper( el ).css({
36+
overflow: 'hidden'
37+
});
38+
distance = widthFirst ?
39+
[ wrapper.width(), wrapper.height() ] :
40+
[ wrapper.height(), wrapper.width() ];
41+
42+
if ( percent ) {
43+
size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ ( mode == 'hide') ? 0 : 1 ];
44+
}
45+
mode == 'show' && wrapper.css( horizFirst ? {
46+
height: 0,
47+
width: size
48+
} : {
49+
height: size,
50+
width: 0
51+
});
3752

3853
// Animation
3954
var animation1 = {}, animation2 = {};
40-
animation1[ref[0]] = mode == 'show' ? distance[0] : size;
41-
animation2[ref[1]] = mode == 'show' ? distance[1] : 0;
55+
animation1[ ref[ 0 ] ] = mode == 'show' ? distance[ 0 ] : size;
56+
animation2[ ref[ 1 ] ] = mode == 'show' ? distance[ 1 ] : 0;
4257

4358
// Animate
44-
wrapper.animate(animation1, duration, o.easing)
45-
.animate(animation2, duration, o.easing, function() {
46-
if(mode == 'hide') el.hide(); // Hide
47-
$.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
48-
if(o.complete) o.complete.apply(el[0], arguments); // Callback
49-
el.dequeue();
50-
});
59+
wrapper
60+
.animate( animation1, duration, o.easing )
61+
.animate( animation2, duration, o.easing, function() {
62+
(mode == 'hide') && el.hide();
63+
$.effects.restore( el, props );
64+
$.effects.removeWrapper( el );
65+
jQuery.isFunction(o.complete) && o.complete.apply( el[ 0 ], arguments );
66+
el.dequeue();
67+
});
5168

5269
});
5370

ui/jquery.effects.highlight.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,36 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.highlight = function(o) {
16-
return this.queue(function() {
17-
var elem = $(this),
18-
props = ['backgroundImage', 'backgroundColor', 'opacity'],
19-
mode = $.effects.setMode(elem, o.mode || 'show'),
15+
$.effects.highlight = function( o ) {
16+
return this.queue( function() {
17+
var elem = $( this ),
18+
props = [ 'backgroundImage', 'backgroundColor', 'opacity' ],
19+
mode = $.effects.setMode( elem, o.mode || 'show' ),
2020
animation = {
21-
backgroundColor: elem.css('backgroundColor')
21+
backgroundColor: elem.css( 'backgroundColor' )
2222
};
2323

2424
if (mode == 'hide') {
2525
animation.opacity = 0;
2626
}
2727

28-
$.effects.save(elem, props);
28+
$.effects.save( elem, props );
2929

3030
elem
3131
.show()
3232
.css({
3333
backgroundImage: 'none',
3434
backgroundColor: o.color || '#ffff99'
3535
})
36-
.animate(animation, {
36+
.animate( animation, {
3737
queue: false,
3838
duration: o.duration,
3939
easing: o.easing,
4040
complete: function() {
4141
(mode == 'hide' && elem.hide());
42-
$.effects.restore(elem, props);
43-
(mode == 'show' && !$.support.opacity && this.style.removeAttribute('filter'));
44-
(o.complete && o.complete.apply(this, arguments));
42+
$.effects.restore( elem, props );
43+
(mode == 'show' && !$.support.opacity && this.style.removeAttribute( 'filter' ));
44+
jQuery.isFunction(o.complete) && o.complete.apply(this, arguments);
4545
elem.dequeue();
4646
}
4747
});

ui/jquery.effects.pulsate.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,40 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.pulsate = function(o) {
16-
return this.queue(function() {
17-
var elem = $(this),
18-
mode = $.effects.setMode(elem, o.mode || 'show'),
19-
times = ((o.times || 5) * 2) - 1,
20-
duration = o.duration ? o.duration / 2 : $.fx.speeds._default / 2,
21-
isVisible = elem.is(':visible'),
22-
animateTo = 0;
15+
$.effects.pulsate = function( o ) {
16+
return this.queue( function() {
17+
var elem = $( this ),
18+
mode = $.effects.setMode( elem, o.mode || 'show' ),
19+
times = ( ( o.times || 5 ) * 2 ) - 1,
20+
duration = o.duration / 2,
21+
isVisible = elem.is( ':visible' ),
22+
animateTo = 0,
23+
i;
2324

24-
if (!isVisible) {
25+
if ( !isVisible ) {
2526
elem.css('opacity', 0).show();
2627
animateTo = 1;
2728
}
2829

29-
if ((mode == 'hide' && isVisible) || (mode == 'show' && !isVisible)) {
30+
if ( ( mode == 'hide' && isVisible ) || ( mode == 'show' && !isVisible ) ) {
3031
times--;
3132
}
3233

33-
for (var i = 0; i < times; i++) {
34-
elem.animate({ opacity: animateTo }, duration, o.easing);
35-
animateTo = (animateTo + 1) % 2;
34+
for ( i = 0; i < times; i++ ) {
35+
elem.animate({
36+
opacity: animateTo
37+
}, duration, o.easing );
38+
animateTo = ( animateTo + 1 ) % 2;
3639
}
3740

38-
elem.animate({ opacity: animateTo }, duration, o.easing, function() {
41+
elem.animate({
42+
opacity: animateTo
43+
}, duration, o.easing, function() {
3944
if (animateTo == 0) {
4045
elem.hide();
4146
}
4247
(o.complete && o.complete.apply(this, arguments));
43-
});
44-
45-
elem
46-
.queue('fx', function() { elem.dequeue(); })
47-
.dequeue();
48+
}).dequeue();
4849
});
4950
};
5051

0 commit comments

Comments
 (0)