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
|
|
|
*
|
2022-07-19 07:36:55 +00:00
|
|
|
* Copyright OpenJS Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2008-06-06 20:08:52 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Explode Effect
|
|
|
|
//>>group: Effects
|
2021-06-06 22:58:12 +00:00
|
|
|
/* eslint-disable max-len */
|
2014-10-30 19:55:08 +00:00
|
|
|
//>>description: Explodes an element in all directions into n pieces. Implodes an element to its original wholeness.
|
2021-06-06 22:58:12 +00:00
|
|
|
/* eslint-enable max-len */
|
2014-10-30 19:55:08 +00:00
|
|
|
//>>docs: http://api.jqueryui.com/explode-effect/
|
|
|
|
//>>demos: http://jqueryui.com/effect/
|
|
|
|
|
2015-03-18 14:39:12 +00:00
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
// AMD. Register as an anonymous module.
|
2015-03-18 14:39:12 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2015-07-15 02:01:41 +00:00
|
|
|
"../version",
|
|
|
|
"../effect"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2013-07-12 16:40:48 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
return $.effects.define( "explode", "hide", function( options, done ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
var i, j, left, top, mx, my,
|
|
|
|
rows = options.pieces ? Math.round( Math.sqrt( options.pieces ) ) : 3,
|
2011-06-21 05:23:52 +00:00
|
|
|
cells = rows,
|
2012-12-26 13:35:42 +00:00
|
|
|
element = $( this ),
|
|
|
|
mode = options.mode,
|
2011-06-21 06:15:42 +00:00
|
|
|
show = mode === "show",
|
2008-06-06 19:47:31 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Show and then visibility:hidden the element before calculating offset
|
2012-12-26 13:35:42 +00:00
|
|
|
offset = element.show().css( "visibility", "hidden" ).offset(),
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Width and height of a piece
|
2012-12-26 13:35:42 +00:00
|
|
|
width = Math.ceil( element.outerWidth() / cells ),
|
|
|
|
height = Math.ceil( element.outerHeight() / rows ),
|
|
|
|
pieces = [];
|
2011-03-12 20:41:56 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Children animate complete:
|
2012-04-02 23:12:21 +00:00
|
|
|
function childComplete() {
|
|
|
|
pieces.push( this );
|
|
|
|
if ( pieces.length === rows * cells ) {
|
|
|
|
animComplete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Clone the element for each row and cell.
|
2015-03-18 14:39:12 +00:00
|
|
|
for ( i = 0; i < rows; i++ ) { // ===>
|
2011-06-21 05:23:52 +00:00
|
|
|
top = offset.top + i * height;
|
2015-03-18 14:39:12 +00:00
|
|
|
my = i - ( rows - 1 ) / 2;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-03-18 14:39:12 +00:00
|
|
|
for ( j = 0; j < cells; j++ ) { // |||
|
2011-06-21 05:23:52 +00:00
|
|
|
left = offset.left + j * width;
|
2015-03-18 14:39:12 +00:00
|
|
|
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
|
2012-12-26 13:35:42 +00:00
|
|
|
element
|
2011-06-21 05:23:52 +00:00
|
|
|
.clone()
|
|
|
|
.appendTo( "body" )
|
|
|
|
.wrap( "<div></div>" )
|
2015-03-18 14:39:12 +00:00
|
|
|
.css( {
|
2011-06-21 05:23:52 +00:00
|
|
|
position: "absolute",
|
|
|
|
visibility: "visible",
|
|
|
|
left: -j * width,
|
|
|
|
top: -i * height
|
2015-03-18 14:39:12 +00:00
|
|
|
} )
|
2011-03-12 02:00:36 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Select the wrapper - make it overflow: hidden and absolute positioned based on
|
2015-03-18 14:39:12 +00:00
|
|
|
// where the original was located +left and +top equal to the size of pieces
|
2011-06-21 05:23:52 +00:00
|
|
|
.parent()
|
2015-03-18 14:39:12 +00:00
|
|
|
.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
|
|
|
|
}, options.duration || 500, options.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() {
|
2015-03-18 14:39:12 +00:00
|
|
|
element.css( {
|
2011-06-21 05:23:52 +00:00
|
|
|
visibility: "visible"
|
2015-03-18 14:39:12 +00:00
|
|
|
} );
|
2011-06-21 05:23:52 +00:00
|
|
|
$( pieces ).remove();
|
2011-06-21 06:11:46 +00:00
|
|
|
done();
|
2011-06-21 05:23:52 +00:00
|
|
|
}
|
2015-03-18 14:39:12 +00:00
|
|
|
} );
|
2008-06-06 19:47:31 +00:00
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|