Skip to content

Commit 4881a27

Browse files
committed
Merge branch 'ticket-3968' of https://github.com/gnarf37/jquery-ui
2 parents ac0cc2f + 7bb0e40 commit 4881a27

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

ui/jquery.effects.explode.js

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,60 +18,77 @@ $.effects.effect.explode = function( o ) {
1818

1919
var rows = o.pieces ? Math.round(Math.sqrt(o.pieces)) : 3,
2020
cells = rows,
21-
el = $( this ).show().css( 'visibility', 'hidden' ),
21+
el = $( this ),
2222
mode = $.effects.setMode( el, o.mode || 'hide' ),
23-
offset = el.offset(),
24-
width = el.outerWidth( true ),
25-
height = el.outerHeight( true ),
26-
peices = [];
23+
show = ( mode == 'show' ),
2724

28-
//Substract the margins - not fixing the problem yet.
29-
offset.top -= parseInt( el.css( "marginTop" ), 10 ) || 0;
30-
offset.left -= parseInt( el.css( "marginLeft" ), 10 ) || 0;
25+
// show and then visibility:hidden the element before calculating offset
26+
offset = el.show().css( 'visibility', 'hidden' ).offset(),
27+
28+
// width and height of a piece
29+
width = Math.ceil( el.outerWidth() / cells ),
30+
height = Math.ceil( el.outerHeight() / rows ),
31+
pieces = [],
32+
33+
// loop
34+
i, j, left, top, mx, my;
3135

3236
// clone the element for each row and cell.
33-
for( var i = 0; i < rows ; i++ ) { // =
34-
for( var j = 0; j < cells ; j++ ) { // ||
37+
for( i = 0; i < rows ; i++ ) { // ===>
38+
top = offset.top + i * height;
39+
my = i - ( rows - 1 ) / 2 ;
40+
41+
for( j = 0; j < cells ; j++ ) { // |||
42+
left = offset.left + j * width;
43+
mx = j - ( cells - 1 ) / 2 ;
44+
45+
// Create a clone of the now hidden main element that will be absolute positioned
46+
// within a wrapper div off the -left and -top equal to size of our pieces
3547
el
3648
.clone()
37-
.appendTo('body')
38-
.wrap('<div></div>')
49+
.appendTo( 'body' )
50+
.wrap( '<div></div>' )
3951
.css({
4052
position: 'absolute',
4153
visibility: 'visible',
42-
left: -j*(width/cells),
43-
top: -i*(height/rows)
54+
left: -j * width,
55+
top: -i * height
4456
})
57+
58+
// select the wrapper - make it overflow: hidden and absolute positioned based on
59+
// where the original was located +left and +top equal to the size of pieces
4560
.parent()
46-
.addClass('ui-effects-explode')
61+
.addClass( 'ui-effects-explode' )
4762
.css({
4863
position: 'absolute',
4964
overflow: 'hidden',
50-
width: width/cells,
51-
height: height/rows,
52-
left: offset.left + j*(width/cells) + (o.mode == 'show' ? (j-Math.floor(cells/2))*(width/cells) : 0),
53-
top: offset.top + i*(height/rows) + (o.mode == 'show' ? (i-Math.floor(rows/2))*(height/rows) : 0),
54-
opacity: mode == 'show' ? 0 : 1
65+
width: width,
66+
height: height,
67+
left: left + ( show ? mx * width : 0 ),
68+
top: top + ( show ? my * height : 0 ),
69+
opacity: show ? 0 : 1
5570
}).animate({
56-
left: offset.left + j*(width/cells) + (o.mode == 'show' ? 0 : (j-Math.floor(cells/2))*(width/cells)),
57-
top: offset.top + i*(height/rows) + (o.mode == 'show' ? 0 : (i-Math.floor(rows/2))*(height/rows)),
58-
opacity: mode == 'show' ? 1 : 0
59-
}, o.duration || 500, childComplete );
71+
left: left + ( show ? 0 : mx * width ),
72+
top: top + ( show ? 0 : my * height ),
73+
opacity: show ? 1 : 0
74+
}, o.duration || 500, o.easing, childComplete );
6075
}
6176
}
6277

6378
// children animate complete:
6479
function childComplete() {
65-
peices.push( this );
66-
if ( peices.length == rows * cells ) {
80+
pieces.push( this );
81+
if ( pieces.length == rows * cells ) {
6782
animComplete();
6883
}
6984
}
7085

7186
function animComplete() {
72-
el.css({ visibility: 'visible' });
73-
$( peices ).remove();
74-
if ( mode != 'show' ) {
87+
el.css({
88+
visibility: 'visible'
89+
});
90+
$( pieces ).remove();
91+
if ( !show ) {
7592
el.hide();
7693
}
7794
if ( $.isFunction( o.complete ) ) {

0 commit comments

Comments
 (0)