root / trunk / web / dojo / dojox / image / Badge.js @ 9
History | View | Annotate | Download (3.18 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.image.Badge"]){ |
||
9 | dojo._hasResource["dojox.image.Badge"]=true; |
||
10 | dojo.provide("dojox.image.Badge");
|
||
11 | dojo.experimental("dojox.image.Badge");
|
||
12 | dojo.require("dijit._Widget");
|
||
13 | dojo.require("dijit._Templated");
|
||
14 | dojo.require("dojo.fx.easing");
|
||
15 | dojo.declare("dojox.image.Badge",[dijit._Widget,dijit._Templated],{baseClass:"dojoxBadge",templateString:"<div class=\"dojoxBadge\" dojoAttachPoint=\"containerNode\"></div>",children:"div.dojoxBadgeImage",rows:4,cols:5,cellSize:50,cellMargin:1,delay:2000,threads:1,easing:"dojo.fx.easing.backOut",startup:function(){ |
||
16 | if(this._started){ |
||
17 | return;
|
||
18 | } |
||
19 | if(dojo.isString(this.easing)){ |
||
20 | this.easing=dojo.getObject(this.easing); |
||
21 | } |
||
22 | this.inherited(arguments); |
||
23 | this._init();
|
||
24 | },_init:function(){ |
||
25 | var _1=0,_2=this.cellSize; |
||
26 | dojo.style(this.domNode,{width:_2*this.cols+"px",height:_2*this.rows+"px"}); |
||
27 | this._nl=dojo.query(this.children,this.containerNode).forEach(function(n,_3){ |
||
28 | var _4=_3%this.cols,t=_1*_2,l=_4*_2,m=this.cellMargin*2; |
||
29 | dojo.style(n,{top:t+"px",left:l+"px",width:_2-m+"px",height:_2-m+"px"}); |
||
30 | if(_4==this.cols-1){ |
||
31 | _1++; |
||
32 | } |
||
33 | dojo.addClass(n,this.baseClass+"Image"); |
||
34 | },this);
|
||
35 | var l=this._nl.length; |
||
36 | while(this.threads--){ |
||
37 | var s=Math.floor(Math.random()*l);
|
||
38 | setTimeout(dojo.hitch(this,"_enbiggen",{target:this._nl[s]}),this.delay*this.threads); |
||
39 | } |
||
40 | },_getCell:function(n){ |
||
41 | var _5=this._nl.indexOf(n); |
||
42 | if(_5>=0){ |
||
43 | var _6=_5%this.cols; |
||
44 | var _7=Math.floor(_5/this.cols); |
||
45 | return {x:_6,y:_7,n:this._nl[_5],io:_5}; |
||
46 | }else{
|
||
47 | return undefined; |
||
48 | } |
||
49 | },_getImage:function(){ |
||
50 | return "url('')"; |
||
51 | },_enbiggen:function(e){ |
||
52 | var _8=this._getCell(e.target||e); |
||
53 | if(_8){
|
||
54 | var m=this.cellMargin,_9=(this.cellSize*2)-(m*2),_a={height:_9,width:_9}; |
||
55 | var _b=function(){ |
||
56 | return Math.round(Math.random());
|
||
57 | }; |
||
58 | if(_8.x==this.cols-1||(_8.x>0&&_b())){ |
||
59 | _a.left=this.cellSize*(_8.x-m);
|
||
60 | } |
||
61 | if(_8.y==this.rows-1||(_8.y>0&&_b())){ |
||
62 | _a.top=this.cellSize*(_8.y-m);
|
||
63 | } |
||
64 | var bc=this.baseClass; |
||
65 | dojo.addClass(_8.n,bc+"Top");
|
||
66 | dojo.addClass(_8.n,bc+"Seen");
|
||
67 | dojo.animateProperty({node:_8.n,properties:_a,onEnd:dojo.hitch(this,"_loadUnder",_8,_a),easing:this.easing}).play(); |
||
68 | } |
||
69 | },_loadUnder:function(_c,_d){ |
||
70 | var _e=_c.io;
|
||
71 | var _f=[];
|
||
72 | var _10=(_d.left>=0); |
||
73 | var _11=(_d.top>=0); |
||
74 | var c=this.cols,e=_e+(_10?-1:1),f=_e+(_11?-c:c),g=(_11?(_10?e-c:f+1):(_10?f-1:e+c)),bc=this.baseClass; |
||
75 | dojo.forEach([e,f,g],function(x){
|
||
76 | var n=this._nl[x]; |
||
77 | if(n){
|
||
78 | if(dojo.hasClass(n,bc+"Seen")){ |
||
79 | dojo.removeClass(n,bc+"Seen");
|
||
80 | } |
||
81 | } |
||
82 | },this);
|
||
83 | setTimeout(dojo.hitch(this,"_disenbiggen",_c,_d),this.delay*1.25); |
||
84 | },_disenbiggen:function(_12,_13){ |
||
85 | if(_13.top>=0){ |
||
86 | _13.top+=this.cellSize;
|
||
87 | } |
||
88 | if(_13.left>=0){ |
||
89 | _13.left+=this.cellSize;
|
||
90 | } |
||
91 | var _14=this.cellSize-(this.cellMargin*2); |
||
92 | dojo.animateProperty({node:_12.n,properties:dojo.mixin(_13,{width:_14,height:_14}),onEnd:dojo.hitch(this,"_cycle",_12,_13)}).play(5); |
||
93 | },_cycle:function(_15,_16){ |
||
94 | var bc=this.baseClass; |
||
95 | dojo.removeClass(_15.n,bc+"Top");
|
||
96 | var ns=this._nl.filter(function(n){ |
||
97 | return !dojo.hasClass(n,bc+"Seen"); |
||
98 | }); |
||
99 | var c=ns[Math.floor(Math.random()*ns.length)];
|
||
100 | setTimeout(dojo.hitch(this,"_enbiggen",{target:c}),this.delay/2); |
||
101 | }}); |
||
102 | } |