2008-06-06 20:08:52 +00:00
|
|
|
/*
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Effects Explode @VERSION
|
2008-06-06 20:08:52 +00:00
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-11-20 04:10:34 +00:00
|
|
|
*
|
2008-06-06 20:08:52 +00:00
|
|
|
* http://docs.jquery.com/UI/Effects/Explode
|
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.effects.core.js
|
2008-06-06 20:08:52 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-03-06 21:24:24 +00:00
|
|
|
$.effects.explode = function( o ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-03-11 04:18:19 +00:00
|
|
|
return this.queue( function( next ) {
|
2008-06-06 19:47:31 +00:00
|
|
|
|
2011-03-06 21:24:24 +00:00
|
|
|
var rows = o.pieces ? Math.round(Math.sqrt(o.pieces)) : 3,
|
|
|
|
cells = rows,
|
|
|
|
el = $( this ).show().css( 'visibility', 'hidden' ),
|
|
|
|
mode = $.effects.setMode( el, o.mode || 'hide' ),
|
|
|
|
offset = el.offset(),
|
|
|
|
width = el.outerWidth( true ),
|
2011-03-11 04:18:19 +00:00
|
|
|
height = el.outerHeight( true ),
|
|
|
|
peices = [];
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-06 21:24:24 +00:00
|
|
|
//Substract the margins - not fixing the problem yet.
|
|
|
|
offset.top -= parseInt( el.css( "marginTop" ), 10 ) || 0;
|
|
|
|
offset.left -= parseInt( el.css( "marginLeft" ), 10 ) || 0;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-11 04:18:19 +00:00
|
|
|
// clone the element for each row and cell.
|
2011-03-06 21:24:24 +00:00
|
|
|
for( var i = 0; i < rows ; i++ ) { // =
|
|
|
|
for( var j = 0; j < cells ; j++ ) { // ||
|
|
|
|
el
|
|
|
|
.clone()
|
|
|
|
.appendTo('body')
|
|
|
|
.wrap('<div></div>')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
visibility: 'visible',
|
|
|
|
left: -j*(width/cells),
|
|
|
|
top: -i*(height/rows)
|
|
|
|
})
|
|
|
|
.parent()
|
|
|
|
.addClass('ui-effects-explode')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
overflow: 'hidden',
|
|
|
|
width: width/cells,
|
|
|
|
height: height/rows,
|
|
|
|
left: offset.left + j*(width/cells) + (o.mode == 'show' ? (j-Math.floor(cells/2))*(width/cells) : 0),
|
|
|
|
top: offset.top + i*(height/rows) + (o.mode == 'show' ? (i-Math.floor(rows/2))*(height/rows) : 0),
|
|
|
|
opacity: mode == 'show' ? 0 : 1
|
|
|
|
}).animate({
|
|
|
|
left: offset.left + j*(width/cells) + (o.mode == 'show' ? 0 : (j-Math.floor(cells/2))*(width/cells)),
|
|
|
|
top: offset.top + i*(height/rows) + (o.mode == 'show' ? 0 : (i-Math.floor(rows/2))*(height/rows)),
|
|
|
|
opacity: mode == 'show' ? 1 : 0
|
2011-03-11 04:18:19 +00:00
|
|
|
}, o.duration || 500, childComplete );
|
2011-03-06 21:24:24 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-11 04:18:19 +00:00
|
|
|
// children animate complete:
|
|
|
|
function childComplete() {
|
|
|
|
peices.push( this );
|
|
|
|
if ( peices.length == rows * cells ) {
|
|
|
|
animComplete();
|
|
|
|
}
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-11 04:18:19 +00:00
|
|
|
function animComplete() {
|
2011-03-06 21:24:24 +00:00
|
|
|
el.css({ visibility: 'visible' });
|
2011-03-11 04:18:19 +00:00
|
|
|
$( peices ).remove();
|
|
|
|
if ( mode != 'show' ) {
|
|
|
|
el.hide();
|
|
|
|
}
|
|
|
|
if ( $.isFunction( o.complete ) ) {
|
|
|
|
o.complete.apply( el[ 0 ] );
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
}
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|