2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Effects Explode @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2008-06-06 20:08:52 +00:00
|
|
|
*
|
2012-07-04 13:08:08 +00:00
|
|
|
* Copyright 2012 jQuery Foundation and other contributors
|
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:
|
2012-06-15 16:47:12 +00:00
|
|
|
* jquery.ui.effect.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-06-21 06:11:46 +00:00
|
|
|
$.effects.effect.explode = function( o, done ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-06-21 06:15:42 +00:00
|
|
|
var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3,
|
2011-06-21 05:23:52 +00:00
|
|
|
cells = rows,
|
|
|
|
el = $( this ),
|
|
|
|
mode = $.effects.setMode( el, o.mode || "hide" ),
|
2011-06-21 06:15:42 +00:00
|
|
|
show = mode === "show",
|
2008-06-06 19:47:31 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// show and then visibility:hidden the element before calculating offset
|
|
|
|
offset = el.show().css( "visibility", "hidden" ).offset(),
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// width and height of a piece
|
|
|
|
width = Math.ceil( el.outerWidth() / cells ),
|
|
|
|
height = Math.ceil( el.outerHeight() / rows ),
|
|
|
|
pieces = [],
|
2011-03-12 02:00:36 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// loop
|
|
|
|
i, j, left, top, mx, my;
|
2011-03-12 20:41:56 +00:00
|
|
|
|
2012-04-02 23:12:21 +00:00
|
|
|
// children animate complete:
|
|
|
|
function childComplete() {
|
|
|
|
pieces.push( this );
|
|
|
|
if ( pieces.length === rows * cells ) {
|
|
|
|
animComplete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// clone the element for each row and cell.
|
|
|
|
for( i = 0; i < rows ; i++ ) { // ===>
|
|
|
|
top = offset.top + i * height;
|
|
|
|
my = i - ( rows - 1 ) / 2 ;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
for( j = 0; j < cells ; j++ ) { // |||
|
|
|
|
left = offset.left + j * width;
|
|
|
|
mx = j - ( cells - 1 ) / 2 ;
|
2011-03-12 02:00:36 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// Create a clone of the now hidden main element that will be absolute positioned
|
|
|
|
// within a wrapper div off the -left and -top equal to size of our pieces
|
|
|
|
el
|
|
|
|
.clone()
|
|
|
|
.appendTo( "body" )
|
|
|
|
.wrap( "<div></div>" )
|
|
|
|
.css({
|
|
|
|
position: "absolute",
|
|
|
|
visibility: "visible",
|
|
|
|
left: -j * width,
|
|
|
|
top: -i * height
|
|
|
|
})
|
2011-03-12 02:00:36 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// select the wrapper - make it overflow: hidden and absolute positioned based on
|
|
|
|
// where the original was located +left and +top equal to the size of pieces
|
|
|
|
.parent()
|
|
|
|
.addClass( "ui-effects-explode" )
|
|
|
|
.css({
|
|
|
|
position: "absolute",
|
|
|
|
overflow: "hidden",
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
left: left + ( show ? mx * width : 0 ),
|
|
|
|
top: top + ( show ? my * height : 0 ),
|
|
|
|
opacity: show ? 0 : 1
|
|
|
|
}).animate({
|
|
|
|
left: left + ( show ? 0 : mx * width ),
|
|
|
|
top: top + ( show ? 0 : my * height ),
|
|
|
|
opacity: show ? 1 : 0
|
|
|
|
}, o.duration || 500, o.easing, childComplete );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2011-06-21 05:23:52 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
function animComplete() {
|
|
|
|
el.css({
|
|
|
|
visibility: "visible"
|
|
|
|
});
|
|
|
|
$( pieces ).remove();
|
|
|
|
if ( !show ) {
|
|
|
|
el.hide();
|
2011-03-11 04:18:19 +00:00
|
|
|
}
|
2011-06-21 06:11:46 +00:00
|
|
|
done();
|
2011-06-21 05:23:52 +00:00
|
|
|
}
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|