2020-10-07 12:33:25 -04:00
|
|
|
/*!
|
2024-05-27 17:14:15 -04:00
|
|
|
* jQuery UI Effects Explode 1.13.3
|
|
|
|
* https://jqueryui.com
|
2020-10-07 12:33:25 -04:00
|
|
|
*
|
2024-05-27 17:14:15 -04:00
|
|
|
* Copyright OpenJS Foundation and other contributors
|
2020-10-07 12:33:25 -04:00
|
|
|
* Released under the MIT license.
|
2024-05-27 17:14:15 -04:00
|
|
|
* https://jquery.org/license
|
2020-10-07 12:33:25 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
//>>label: Explode Effect
|
|
|
|
//>>group: Effects
|
2021-09-09 20:02:59 -04:00
|
|
|
/* eslint-disable max-len */
|
2020-10-07 12:33:25 -04:00
|
|
|
//>>description: Explodes an element in all directions into n pieces. Implodes an element to its original wholeness.
|
2021-09-09 20:02:59 -04:00
|
|
|
/* eslint-enable max-len */
|
2024-05-27 17:14:15 -04:00
|
|
|
//>>docs: https://api.jqueryui.com/explode-effect/
|
|
|
|
//>>demos: https://jqueryui.com/effect/
|
2020-10-07 12:33:25 -04:00
|
|
|
|
|
|
|
( function( factory ) {
|
2021-09-09 20:02:59 -04:00
|
|
|
"use strict";
|
|
|
|
|
2020-10-07 12:33:25 -04:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define( [
|
|
|
|
"jquery",
|
2024-05-27 17:14:15 -04:00
|
|
|
"../version",
|
|
|
|
"../effect"
|
2020-10-07 12:33:25 -04:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-09-09 20:02:59 -04:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2020-10-07 12:33:25 -04:00
|
|
|
|
|
|
|
return $.effects.define( "explode", "hide", function( options, done ) {
|
|
|
|
|
|
|
|
var i, j, left, top, mx, my,
|
|
|
|
rows = options.pieces ? Math.round( Math.sqrt( options.pieces ) ) : 3,
|
|
|
|
cells = rows,
|
|
|
|
element = $( this ),
|
|
|
|
mode = options.mode,
|
|
|
|
show = mode === "show",
|
|
|
|
|
|
|
|
// Show and then visibility:hidden the element before calculating offset
|
|
|
|
offset = element.show().css( "visibility", "hidden" ).offset(),
|
|
|
|
|
|
|
|
// Width and height of a piece
|
|
|
|
width = Math.ceil( element.outerWidth() / cells ),
|
|
|
|
height = Math.ceil( element.outerHeight() / rows ),
|
|
|
|
pieces = [];
|
|
|
|
|
|
|
|
// Children animate complete:
|
|
|
|
function childComplete() {
|
|
|
|
pieces.push( this );
|
|
|
|
if ( pieces.length === rows * cells ) {
|
|
|
|
animComplete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clone the element for each row and cell.
|
|
|
|
for ( i = 0; i < rows; i++ ) { // ===>
|
|
|
|
top = offset.top + i * height;
|
|
|
|
my = i - ( rows - 1 ) / 2;
|
|
|
|
|
|
|
|
for ( j = 0; j < cells; j++ ) { // |||
|
|
|
|
left = offset.left + j * width;
|
|
|
|
mx = j - ( cells - 1 ) / 2;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
element
|
|
|
|
.clone()
|
|
|
|
.appendTo( "body" )
|
|
|
|
.wrap( "<div></div>" )
|
|
|
|
.css( {
|
|
|
|
position: "absolute",
|
|
|
|
visibility: "visible",
|
|
|
|
left: -j * width,
|
|
|
|
top: -i * height
|
|
|
|
} )
|
|
|
|
|
|
|
|
// 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()
|
2022-09-19 14:04:09 -04: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 );
|
2020-10-07 12:33:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function animComplete() {
|
|
|
|
element.css( {
|
|
|
|
visibility: "visible"
|
|
|
|
} );
|
|
|
|
$( pieces ).remove();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2021-09-09 20:02:59 -04:00
|
|
|
} );
|