| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
( function( factory ) { |
| 17 |
"use strict"; |
| 18 |
|
| 19 |
if ( typeof define === "function" && define.amd ) { |
| 20 |
|
| 21 |
|
| 22 |
define( [ |
| 23 |
"jquery", |
| 24 |
"../version", |
| 25 |
"../effect" |
| 26 |
], factory ); |
| 27 |
} else { |
| 28 |
|
| 29 |
|
| 30 |
factory( jQuery ); |
| 31 |
} |
| 32 |
} )( function( $ ) { |
| 33 |
"use strict"; |
| 34 |
|
| 35 |
return $.effects.define( "explode", "hide", function( options, done ) { |
| 36 |
|
| 37 |
var i, j, left, top, mx, my, |
| 38 |
rows = options.pieces ? Math.round( Math.sqrt( options.pieces ) ) : 3, |
| 39 |
cells = rows, |
| 40 |
element = $( this ), |
| 41 |
mode = options.mode, |
| 42 |
show = mode === "show", |
| 43 |
|
| 44 |
|
| 45 |
offset = element.show().css( "visibility", "hidden" ).offset(), |
| 46 |
|
| 47 |
|
| 48 |
width = Math.ceil( element.outerWidth() / cells ), |
| 49 |
height = Math.ceil( element.outerHeight() / rows ), |
| 50 |
pieces = []; |
| 51 |
|
| 52 |
|
| 53 |
function childComplete() { |
| 54 |
pieces.push( this ); |
| 55 |
if ( pieces.length === rows * cells ) { |
| 56 |
animComplete(); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
for ( i = 0; i < rows; i++ ) { |
| 62 |
top = offset.top + i * height; |
| 63 |
my = i - ( rows - 1 ) / 2; |
| 64 |
|
| 65 |
for ( j = 0; j < cells; j++ ) { |
| 66 |
left = offset.left + j * width; |
| 67 |
mx = j - ( cells - 1 ) / 2; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
element |
| 72 |
.clone() |
| 73 |
.appendTo( "body" ) |
| 74 |
.wrap( "<div></div>" ) |
| 75 |
.css( { |
| 76 |
position: "absolute", |
| 77 |
visibility: "visible", |
| 78 |
left: -j * width, |
| 79 |
top: -i * height |
| 80 |
} ) |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
.parent() |
| 85 |
.addClass( "ui-effects-explode" ) |
| 86 |
.css( { |
| 87 |
position: "absolute", |
| 88 |
overflow: "hidden", |
| 89 |
width: width, |
| 90 |
height: height, |
| 91 |
left: left + ( show ? mx * width : 0 ), |
| 92 |
top: top + ( show ? my * height : 0 ), |
| 93 |
opacity: show ? 0 : 1 |
| 94 |
} ) |
| 95 |
.animate( { |
| 96 |
left: left + ( show ? 0 : mx * width ), |
| 97 |
top: top + ( show ? 0 : my * height ), |
| 98 |
opacity: show ? 1 : 0 |
| 99 |
}, options.duration || 500, options.easing, childComplete ); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
function animComplete() { |
| 104 |
element.css( { |
| 105 |
visibility: "visible" |
| 106 |
} ); |
| 107 |
$( pieces ).remove(); |
| 108 |
done(); |
| 109 |
} |
| 110 |
} ); |
| 111 |
|
| 112 |
} ); |