1/*!
2 * jQuery UI Effects Explode 1.13.3
3 * https://jqueryui.com
4 *
5 * Copyright OpenJS Foundation and other contributors
6 * Released under the MIT license.
7 * https://jquery.org/license
8 */
9
10//>>label: Explode Effect
11//>>group: Effects
12/* eslint-disable max-len */
13//>>description: Explodes an element in all directions into n pieces. Implodes an element to its original wholeness.
14/* eslint-enable max-len */
15//>>docs: https://api.jqueryui.com/explode-effect/
16//>>demos: https://jqueryui.com/effect/
17
18( function( factory ) {
19 "use strict";
20
21 if ( typeof define === "function" && define.amd ) {
22
23 // AMD. Register as an anonymous module.
24 define( [
25 "jquery",
26 "../version",
27 "../effect"
28 ], factory );
29 } else {
30
31 // Browser globals
32 factory( jQuery );
33 }
34} )( function( $ ) {
35"use strict";
36
37return $.effects.define( "explode", "hide", function( options, done ) {
38
39 var i, j, left, top, mx, my,
40 rows = options.pieces ? Math.round( Math.sqrt( options.pieces ) ) : 3,
41 cells = rows,
42 element = $( this ),
43 mode = options.mode,
44 show = mode === "show",
45
46 // Show and then visibility:hidden the element before calculating offset
47 offset = element.show().css( "visibility", "hidden" ).offset(),
48
49 // Width and height of a piece
50 width = Math.ceil( element.outerWidth() / cells ),
51 height = Math.ceil( element.outerHeight() / rows ),
52 pieces = [];
53
54 // Children animate complete:
55 function childComplete() {
56 pieces.push( this );
57 if ( pieces.length === rows * cells ) {
58 animComplete();
59 }
60 }
61
62 // Clone the element for each row and cell.
63 for ( i = 0; i < rows; i++ ) { // ===>
64 top = offset.top + i * height;
65 my = i - ( rows - 1 ) / 2;
66
67 for ( j = 0; j < cells; j++ ) { // |||
68 left = offset.left + j * width;
69 mx = j - ( cells - 1 ) / 2;
70
71 // Create a clone of the now hidden main element that will be absolute positioned
72 // within a wrapper div off the -left and -top equal to size of our pieces
73 element
74 .clone()
75 .appendTo( "body" )
76 .wrap( "<div></div>" )
77 .css( {
78 position: "absolute",
79 visibility: "visible",
80 left: -j * width,
81 top: -i * height
82 } )
83
84 // Select the wrapper - make it overflow: hidden and absolute positioned based on
85 // where the original was located +left and +top equal to the size of pieces
86 .parent()
87 .addClass( "ui-effects-explode" )
88 .css( {
89 position: "absolute",
90 overflow: "hidden",
91 width: width,
92 height: height,
93 left: left + ( show ? mx * width : 0 ),
94 top: top + ( show ? my * height : 0 ),
95 opacity: show ? 0 : 1
96 } )
97 .animate( {
98 left: left + ( show ? 0 : mx * width ),
99 top: top + ( show ? 0 : my * height ),
100 opacity: show ? 1 : 0
101 }, options.duration || 500, options.easing, childComplete );
102 }
103 }
104
105 function animComplete() {
106 element.css( {
107 visibility: "visible"
108 } );
109 $( pieces ).remove();
110 done();
111 }
112} );
113
114} );
115