client/player/development-bundle/ui/jquery.effects.explode.js
author ymh <ymh.work@gmail.com>
Sat, 12 Jun 2010 04:25:05 +0200
changeset 0 cc4a51750724
permissions -rw-r--r--
first commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
/*
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
 * jQuery UI Effects Explode 1.8.1
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 *
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * Dual licensed under the MIT (MIT-LICENSE.txt)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * and GPL (GPL-LICENSE.txt) licenses.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 *
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * http://docs.jquery.com/UI/Effects/Explode
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 *
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Depends:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *	jquery.effects.core.js
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 */
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
(function($) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
$.effects.explode = function(o) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	return this.queue(function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	var rows = o.options.pieces ? Math.round(Math.sqrt(o.options.pieces)) : 3;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	var cells = o.options.pieces ? Math.round(Math.sqrt(o.options.pieces)) : 3;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	o.options.mode = o.options.mode == 'toggle' ? ($(this).is(':visible') ? 'hide' : 'show') : o.options.mode;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	var el = $(this).show().css('visibility', 'hidden');
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	var offset = el.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	//Substract the margins - not fixing the problem yet.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	offset.top -= parseInt(el.css("marginTop"),10) || 0;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	offset.left -= parseInt(el.css("marginLeft"),10) || 0;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	var width = el.outerWidth(true);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	var height = el.outerHeight(true);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	for(var i=0;i<rows;i++) { // =
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		for(var j=0;j<cells;j++) { // ||
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
			el
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
				.clone()
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
				.appendTo('body')
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
				.wrap('<div></div>')
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
				.css({
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
					position: 'absolute',
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
					visibility: 'visible',
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
					left: -j*(width/cells),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
					top: -i*(height/rows)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
				})
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
				.parent()
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
				.addClass('ui-effects-explode')
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
				.css({
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
					position: 'absolute',
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
					overflow: 'hidden',
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
					width: width/cells,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
					height: height/rows,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
					left: offset.left + j*(width/cells) + (o.options.mode == 'show' ? (j-Math.floor(cells/2))*(width/cells) : 0),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
					top: offset.top + i*(height/rows) + (o.options.mode == 'show' ? (i-Math.floor(rows/2))*(height/rows) : 0),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
					opacity: o.options.mode == 'show' ? 0 : 1
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
				}).animate({
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
					left: offset.left + j*(width/cells) + (o.options.mode == 'show' ? 0 : (j-Math.floor(cells/2))*(width/cells)),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
					top: offset.top + i*(height/rows) + (o.options.mode == 'show' ? 0 : (i-Math.floor(rows/2))*(height/rows)),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
					opacity: o.options.mode == 'show' ? 1 : 0
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
				}, o.duration || 500);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	// Set a timeout, to call the callback approx. when the other animations have finished
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	setTimeout(function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		o.options.mode == 'show' ? el.css({ visibility: 'visible' }) : el.css({ visibility: 'visible' }).hide();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
				if(o.callback) o.callback.apply(el[0]); // Callback
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
				el.dequeue();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
				$('div.ui-effects-explode').remove();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	}, o.duration || 500);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
})(jQuery);