flip.js
5.93 KB
//>>built
define("dojo/_base/kernel dojo/_base/html dojo/dom dojo/dom-construct dojo/dom-geometry dojo/_base/connect dojo/_base/Color dojo/_base/sniff dojo/_base/lang dojo/_base/window dojo/_base/fx dojo/fx ./_base".split(" "),function(G,p,H,A,I,B,J,K,C,E,F,D,r){G.experimental("dojox.fx.flip");r.flip=function(c){var n=A.create("div"),d=c.node=H.byId(c.node),g=d.style,b=null,l=null,a=null,t=c.lightColor||"#dddddd",x=c.darkColor||"#555555",u=p.style(d,"backgroundColor"),v=c.endColor||u,q={},m=[],h=c.duration?
c.duration/2:250,a=c.dir||"left",k=.9,l="transparent",y=c.whichAnim,w=c.axis||"center",k=c.depth,e=function(a){return"#000000"===(new J(a)).toHex()?"#000001":a};7>K("ie")&&(v=e(v),t=e(t),x=e(x),u=e(u),l="black",n.style.filter="chroma(color\x3d'#000000')");(function(a){return function(){var c=p.coords(a,!0);b={top:c.y,left:c.x,width:c.w,height:c.h}}})(d)();l={position:"absolute",top:b.top+"px",left:b.left+"px",height:"0",width:"0",zIndex:c.zIndex||g.zIndex||0,border:"0 solid "+l,fontSize:"0",visibility:"hidden"};
d=[{},{top:b.top,left:b.left}];a={left:"Left Right Top Bottom Width Height endHeightMin Left endHeightMax".split(" "),right:"Right Left Top Bottom Width Height endHeightMin Left endHeightMax".split(" "),top:"Top Bottom Left Right Height Width endWidthMin Top endWidthMax".split(" "),bottom:"Bottom Top Left Right Height Width endWidthMin Top endWidthMax".split(" ")}[a];"undefined"!=typeof k?(k=Math.max(0,Math.min(1,k))/2,k=.4+(.5-k)):k=Math.min(.9,Math.max(.4,b[a[5].toLowerCase()]/b[a[4].toLowerCase()]));
for(var e=d[0],f=4;6>f;f++)"center"==w||"cube"==w?(b["end"+a[f]+"Min"]=b[a[f].toLowerCase()]*k,b["end"+a[f]+"Max"]=b[a[f].toLowerCase()]/k):"shortside"==w?(b["end"+a[f]+"Min"]=b[a[f].toLowerCase()],b["end"+a[f]+"Max"]=b[a[f].toLowerCase()]/k):"longside"==w&&(b["end"+a[f]+"Min"]=b[a[f].toLowerCase()]*k,b["end"+a[f]+"Max"]=b[a[f].toLowerCase()]);"center"==w?e[a[2].toLowerCase()]=b[a[2].toLowerCase()]-(b[a[8]]-b[a[6]])/4:"shortside"==w&&(e[a[2].toLowerCase()]=b[a[2].toLowerCase()]-(b[a[8]]-b[a[6]])/
2);q[a[5].toLowerCase()]=b[a[5].toLowerCase()]+"px";q[a[4].toLowerCase()]="0";q["border"+a[1]+"Width"]=b[a[4].toLowerCase()]+"px";q["border"+a[1]+"Color"]=u;e["border"+a[1]+"Width"]=0;e["border"+a[1]+"Color"]=x;e["border"+a[2]+"Width"]=e["border"+a[3]+"Width"]="cube"!=w?(b["end"+a[5]+"Max"]-b["end"+a[5]+"Min"])/2:b[a[6]]/2;e[a[7].toLowerCase()]=b[a[7].toLowerCase()]+b[a[4].toLowerCase()]/2+(c.shift||0);e[a[5].toLowerCase()]=b[a[6]];c=d[1];c["border"+a[0]+"Color"]={start:t,end:v};c["border"+a[0]+"Width"]=
b[a[4].toLowerCase()];c["border"+a[2]+"Width"]=0;c["border"+a[3]+"Width"]=0;c[a[5].toLowerCase()]={start:b[a[6]],end:b[a[5].toLowerCase()]};C.mixin(l,q);p.style(n,l);E.body().appendChild(n);t=function(){A.destroy(n);g.backgroundColor=v;g.visibility="visible"};if("last"==y){for(f in e)e[f]={start:e[f]};e["border"+a[1]+"Color"]={start:x,end:v};c=e}y&&"first"!=y||m.push(F.animateProperty({node:n,duration:h,properties:e}));y&&"last"!=y||m.push(F.animateProperty({node:n,duration:h,properties:c,onEnd:t}));
B.connect(m[0],"play",function(){n.style.visibility="visible";g.visibility="hidden"});return D.chain(m)};r.flipCube=function(c){var n=[],d=I.getMarginBox(c.node),g=d.w/2,d=d.h/2,g={top:{pName:"height",args:[{whichAnim:"first",dir:"top",shift:-d},{whichAnim:"last",dir:"bottom",shift:d}]},right:{pName:"width",args:[{whichAnim:"first",dir:"right",shift:g},{whichAnim:"last",dir:"left",shift:-g}]},bottom:{pName:"height",args:[{whichAnim:"first",dir:"bottom",shift:d},{whichAnim:"last",dir:"top",shift:-d}]},
left:{pName:"width",args:[{whichAnim:"first",dir:"left",shift:-g},{whichAnim:"last",dir:"right",shift:g}]}}[c.dir||"left"].args;c.duration=c.duration?2*c.duration:500;c.depth=.8;c.axis="cube";for(d=g.length-1;0<=d;d--)C.mixin(c,g[d]),n.push(r.flip(c));return D.combine(n)};r.flipPage=function(c){var n=c.node,d=p.coords(n,!0),g=d.x,b=d.y,l=d.w,a=d.h,t=p.style(n,"backgroundColor"),x=c.lightColor||"#dddddd",u=c.darkColor,v=A.create("div"),q=[],m=[],h=c.dir||"right",k={left:["left","right","x","w"],top:["top",
"bottom","y","h"],right:["left","left","x","w"],bottom:["top","top","y","h"]},y={right:[1,-1],left:[-1,1],top:[-1,1],bottom:[1,-1]};p.style(v,{position:"absolute",width:l+"px",height:a+"px",top:b+"px",left:g+"px",visibility:"hidden"});g=[];for(b=0;2>b;b++){var a=(l=b%2)?k[h][1]:h,w=l?"last":"first",e=l?t:x,f=l?e:c.startColor||n.style.backgroundColor;m[b]=C.clone(v);var z=function(a){return function(){A.destroy(m[a])}}(b);E.body().appendChild(m[b]);g[b]={backgroundColor:l?f:t};g[b][k[h][0]]=d[k[h][2]]+
y[h][0]*b*d[k[h][3]]+"px";p.style(m[b],g[b]);q.push(dojox.fx.flip({node:m[b],dir:a,axis:"shortside",depth:c.depth,duration:c.duration/2,shift:y[h][b]*d[k[h][3]]/2,darkColor:u,lightColor:x,whichAnim:w,endColor:e}));B.connect(q[b],"onEnd",z)}return D.chain(q)};r.flipGrid=function(c){var n=c.rows||4,d=c.cols||4,g=[],b=A.create("div"),l=c.node,a=p.coords(l,!0),t=a.x,x=a.y,u=a.w,v=a.h,q=a.w/d,m=a.h/n,a=[];p.style(b,{position:"absolute",width:q+"px",height:m+"px",backgroundColor:p.style(l,"backgroundColor")});
for(var h=0;h<n;h++){var k=h%2,y=k?"right":"left",w=k?1:-1,e=C.clone(l);p.style(e,{position:"absolute",width:u+"px",height:v+"px",top:x+"px",left:t+"px",clip:"rect("+h*m+"px,"+u+"px,"+v+"px,0)"});E.body().appendChild(e);g[h]=[];for(var f=0;f<d;f++){var z=C.clone(b),r=k?f:d-(f+1),F=function(a,b,c){return function(){b%2?p.style(a,{clip:"rect("+b*m+"px,"+u+"px,"+(b+1)*m+"px,"+(c+1)*q+"px)"}):p.style(a,{clip:"rect("+b*m+"px,"+(u-(c+1)*q)+"px,"+(b+1)*m+"px,0px)"})}}(e,h,f);E.body().appendChild(z);p.style(z,
{left:t+r*q+"px",top:x+h*m+"px",visibility:"hidden"});r=dojox.fx.flipPage({node:z,dir:y,duration:c.duration||900,shift:w*q/2,depth:.2,darkColor:c.darkColor,lightColor:c.lightColor,startColor:c.startColor||c.node.style.backgroundColor});z=function(a){return function(){A.destroy(a)}}(z);B.connect(r,"play",this,F);B.connect(r,"play",this,z);g[h].push(r)}a.push(D.chain(g[h]))}B.connect(a[0],"play",function(){p.style(l,{visibility:"hidden"})});return D.combine(a)};return r});