2008-06-06 20:08:52 +00:00
|
|
|
/*
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Effects Explode @VERSION
|
2008-06-06 20:08:52 +00:00
|
|
|
*
|
2009-01-03 21:55:13 +00:00
|
|
|
* Copyright (c) 2009 AUTHORS.txt (http://ui.jquery.com/about)
|
2008-06-06 20:08:52 +00:00
|
|
|
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
|
|
|
* and GPL (GPL-LICENSE.txt) licenses.
|
2008-11-20 04:10:34 +00:00
|
|
|
*
|
2008-06-06 20:08:52 +00:00
|
|
|
* http://docs.jquery.com/UI/Effects/Explode
|
|
|
|
*
|
|
|
|
* Depends:
|
|
|
|
* effects.core.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
$.effects.explode = function(o) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
return this.queue(function() {
|
|
|
|
|
|
|
|
var rows = o.options.pieces ? Math.round(Math.sqrt(o.options.pieces)) : 3;
|
|
|
|
var cells = o.options.pieces ? Math.round(Math.sqrt(o.options.pieces)) : 3;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
o.options.mode = o.options.mode == 'toggle' ? ($(this).is(':visible') ? 'hide' : 'show') : o.options.mode;
|
|
|
|
var el = $(this).show().css('visibility', 'hidden');
|
|
|
|
var offset = el.offset();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
//Substract the margins - not fixing the problem yet.
|
|
|
|
offset.top -= parseInt(el.css("marginTop")) || 0;
|
|
|
|
offset.left -= parseInt(el.css("marginLeft")) || 0;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
var width = el.outerWidth(true);
|
|
|
|
var height = el.outerHeight(true);
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
for(var i=0;i<rows;i++) { // =
|
|
|
|
for(var j=0;j<cells;j++) { // ||
|
|
|
|
el
|
|
|
|
.clone()
|
|
|
|
.appendTo('body')
|
|
|
|
.wrap('<div></div>')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
visibility: 'visible',
|
|
|
|
left: -j*(width/cells),
|
|
|
|
top: -i*(height/rows)
|
|
|
|
})
|
|
|
|
.parent()
|
2008-06-06 19:54:38 +00:00
|
|
|
.addClass('effects-explode')
|
2008-06-06 19:47:31 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
overflow: 'hidden',
|
|
|
|
width: width/cells,
|
|
|
|
height: height/rows,
|
|
|
|
left: offset.left + j*(width/cells) + (o.options.mode == 'show' ? (j-Math.floor(cells/2))*(width/cells) : 0),
|
|
|
|
top: offset.top + i*(height/rows) + (o.options.mode == 'show' ? (i-Math.floor(rows/2))*(height/rows) : 0),
|
|
|
|
opacity: o.options.mode == 'show' ? 0 : 1
|
|
|
|
}).animate({
|
|
|
|
left: offset.left + j*(width/cells) + (o.options.mode == 'show' ? 0 : (j-Math.floor(cells/2))*(width/cells)),
|
|
|
|
top: offset.top + i*(height/rows) + (o.options.mode == 'show' ? 0 : (i-Math.floor(rows/2))*(height/rows)),
|
|
|
|
opacity: o.options.mode == 'show' ? 1 : 0
|
|
|
|
}, o.duration || 500);
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-06-06 19:47:31 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Set a timeout, to call the callback approx. when the other animations have finished
|
|
|
|
setTimeout(function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
o.options.mode == 'show' ? el.css({ visibility: 'visible' }) : el.css({ visibility: 'visible' }).hide();
|
|
|
|
if(o.callback) o.callback.apply(el[0]); // Callback
|
|
|
|
el.dequeue();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:54:38 +00:00
|
|
|
$('.effects-explode').remove();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
}, o.duration || 500);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|