source: [view]
args.rows = args.rows || 3;
args.columns = args.columns || 3;
args.duration = args.duration || 1000;
var node = args.node = dojo.byId(args.node),
parentNode = node.parentNode,
pNode = parentNode,
body = dojo.body(),
_pos = "position"
;
while(pNode && pNode != body && dojo.style(pNode, _pos) == "static"){
pNode = pNode.parentNode;
}
var pCoords = pNode != body ? dojo.position(pNode, true) : { x: 0, y: 0 },
coords = dojo.position(node, true),
nodeHeight = dojo.style(node, "height"),
nodeWidth = dojo.style(node, "width"),
hBorder = dojo.style(node, "borderLeftWidth") + dojo.style(node, "borderRightWidth"),
vBorder = dojo.style(node, "borderTopWidth") + dojo.style(node, "borderBottomWidth"),
pieceHeight = Math.ceil(nodeHeight / args.rows),
pieceWidth = Math.ceil(nodeWidth / args.columns),
container = dojo.create(node.tagName, {
style: {
position: "absolute",
padding: 0,
margin: 0,
border:"none",
top: coords.y - pCoords.y + "px",
left: coords.x - pCoords.x + "px",
height: nodeHeight + vBorder + "px",
width: nodeWidth + hBorder + "px",
background: "none",
overflow: args.crop ? "hidden" : "visible",
zIndex: dojo.style(node, "zIndex")
}
}, node, "after"),
animations = [],
pieceHelper = dojo.create(node.tagName, {
style: {
position: "absolute",
border: "none",
padding: 0,
margin: 0,
height: pieceHeight + hBorder + "px",
width: pieceWidth + vBorder + "px",
overflow: "hidden"
}
});
// Create the pieces and their animations
for(var y = 0, ly = args.rows; y < ly; y++){
for(var x = 0, lx = args.columns; x < lx; x++){
// Create the piece
var piece = dojo.clone(pieceHelper),
pieceContents = dojo.clone(node),
pTop = y * pieceHeight,
pLeft = x * pieceWidth
;
// IE hack
pieceContents.style.filter = "";
// removing the id attribute from the cloned nodes
dojo.removeAttr(pieceContents, "id");
dojo.style(piece, {
border: "none",
overflow: "hidden",
top: pTop + "px",
left: pLeft + "px"
});
dojo.style(pieceContents, {
position: "static",
opacity: "1",
marginTop: -pTop + "px",
marginLeft: -pLeft + "px"
});
piece.appendChild(pieceContents);
container.appendChild(piece);
var pieceAnimation = args.pieceAnimation(piece, x, y, coords);
if(dojo.isArray(pieceAnimation)){
// if pieceAnimation is an array, append its elements
animations = animations.concat(pieceAnimation);
}else{
// otherwise, append it
animations.push(pieceAnimation);
}
}
}
var anim = dojo.fx.combine(animations);
dojo.connect(anim, "onEnd", anim, function(){
container.parentNode.removeChild(container);
});
if(args.onPlay){
dojo.connect(anim, "onPlay", anim, args.onPlay);
}
if(args.onEnd){
dojo.connect(anim, "onEnd", anim, args.onEnd);
}
return anim; // dojo.Animation