| 1 |
define(["dojo", "dijit", "dojox/main", "dijit/_Widget", "dijit/_TemplatedMixin", "dojo/fx/easing"], |
| 2 |
function(dojo, dijit, dojox, _Widget, _TemplatedMixin){ |
| 3 |
|
| 4 |
dojo.experimental("dojox.image.Badge"); |
| 5 |
dojo.getObject("image", true, dojox); |
| 6 |
|
| 7 |
return dojo.declare("dojox.image.Badge", [_Widget, _TemplatedMixin], { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
baseClass: "dojoxBadge", |
| 12 |
|
| 13 |
templateString:'<div class="dojoxBadge" dojoAttachPoint="containerNode"></div>', |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
children: "div.dojoxBadgeImage", |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
rows: 4, |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
cols: 5, |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
cellSize: 50, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
cellMargin: 1, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
delay: 2000, |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
threads: 1, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
easing: "dojo.fx.easing.backOut", |
| 46 |
|
| 47 |
startup: function(){ |
| 48 |
if(this._started){ return; } |
| 49 |
if(dojo.isString(this.easing)){ |
| 50 |
this.easing = dojo.getObject(this.easing); |
| 51 |
} |
| 52 |
this.inherited(arguments); |
| 53 |
this._init(); |
| 54 |
}, |
| 55 |
|
| 56 |
_init: function(){ |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
var _row = 0, |
| 61 |
_w = this.cellSize; |
| 62 |
|
| 63 |
dojo.style(this.domNode, { |
| 64 |
width: _w * this.cols + "px", |
| 65 |
height: _w * this.rows + "px" |
| 66 |
}); |
| 67 |
|
| 68 |
this._nl = dojo.query(this.children, this.containerNode) |
| 69 |
.forEach(function(n, _idx){ |
| 70 |
|
| 71 |
var _col = _idx % this.cols, |
| 72 |
t = _row * _w, |
| 73 |
l = _col * _w, |
| 74 |
m = this.cellMargin * 2; |
| 75 |
|
| 76 |
dojo.style(n, { |
| 77 |
top: t + "px", |
| 78 |
left: l + "px", |
| 79 |
width: _w - m + "px", |
| 80 |
height: _w - m + "px" |
| 81 |
}); |
| 82 |
|
| 83 |
if(_col == this.cols - 1){ _row++; } |
| 84 |
dojo.addClass(n, this.baseClass + "Image"); |
| 85 |
|
| 86 |
}, this) |
| 87 |
; |
| 88 |
|
| 89 |
var l = this._nl.length; |
| 90 |
while(this.threads--){ |
| 91 |
var s = Math.floor(Math.random() * l); |
| 92 |
setTimeout(dojo.hitch(this, "_enbiggen", { |
| 93 |
target: this._nl[s] |
| 94 |
}), this.delay * this.threads); |
| 95 |
} |
| 96 |
|
| 97 |
}, |
| 98 |
|
| 99 |
_getCell: function( n){ |
| 100 |
|
| 101 |
|
| 102 |
var _pos = this._nl.indexOf(n); |
| 103 |
if(_pos >= 0){ |
| 104 |
var _col = _pos % this.cols; |
| 105 |
var _row = Math.floor(_pos / this.cols); |
| 106 |
return { x: _col, y: _row, n: this._nl[_pos], io: _pos }; |
| 107 |
}else{ |
| 108 |
return undefined; |
| 109 |
} |
| 110 |
}, |
| 111 |
|
| 112 |
_getImage: function(){ |
| 113 |
|
| 114 |
|
| 115 |
return "url('')"; |
| 116 |
}, |
| 117 |
|
| 118 |
_enbiggen: function( e){ |
| 119 |
|
| 120 |
|
| 121 |
var _pos = this._getCell(e.target || e); |
| 122 |
|
| 123 |
if (_pos){ |
| 124 |
|
| 125 |
|
| 126 |
var m = this.cellMargin, |
| 127 |
_cc = (this.cellSize * 2) - (m * 2), |
| 128 |
props = { |
| 129 |
height: _cc, |
| 130 |
width: _cc |
| 131 |
} |
| 132 |
; |
| 133 |
|
| 134 |
var _tehDecider = function(){ |
| 135 |
|
| 136 |
|
| 137 |
return Math.round(Math.random()); |
| 138 |
}; |
| 139 |
|
| 140 |
if(_pos.x == this.cols - 1 || (_pos.x > 0 && _tehDecider() )){ |
| 141 |
|
| 142 |
props.left = this.cellSize * (_pos.x - m); |
| 143 |
} |
| 144 |
|
| 145 |
if(_pos.y == this.rows - 1 || (_pos.y > 0 && _tehDecider() )){ |
| 146 |
|
| 147 |
props.top = this.cellSize * (_pos.y - m); |
| 148 |
} |
| 149 |
|
| 150 |
var bc = this.baseClass; |
| 151 |
dojo.addClass(_pos.n, bc + "Top"); |
| 152 |
dojo.addClass(_pos.n, bc + "Seen"); |
| 153 |
|
| 154 |
dojo.animateProperty({ node: _pos.n, properties: props, |
| 155 |
onEnd: dojo.hitch(this, "_loadUnder", _pos, props), |
| 156 |
easing: this.easing |
| 157 |
}).play(); |
| 158 |
|
| 159 |
} |
| 160 |
}, |
| 161 |
|
| 162 |
_loadUnder: function(info, props){ |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
var idx = info.io; |
| 168 |
var nodes = []; |
| 169 |
|
| 170 |
var isLeft = (props.left >= 0); |
| 171 |
var isUp = (props.top >= 0); |
| 172 |
|
| 173 |
var c = this.cols, |
| 174 |
|
| 175 |
e = idx + (isLeft ? -1 : 1), |
| 176 |
f = idx + (isUp ? -c : c), |
| 177 |
|
| 178 |
g = (isUp ? (isLeft ? e - c : f + 1) : (isLeft ? f - 1 : e + c)), |
| 179 |
|
| 180 |
bc = this.baseClass; |
| 181 |
|
| 182 |
dojo.forEach([e, f, g], function(x){ |
| 183 |
var n = this._nl[x]; |
| 184 |
if(n){ |
| 185 |
if(dojo.hasClass(n, bc + "Seen")){ |
| 186 |
|
| 187 |
dojo.removeClass(n, bc + "Seen"); |
| 188 |
} |
| 189 |
} |
| 190 |
},this); |
| 191 |
|
| 192 |
setTimeout(dojo.hitch(this, "_disenbiggen", info, props), this.delay * 1.25); |
| 193 |
|
| 194 |
}, |
| 195 |
|
| 196 |
_disenbiggen: function(info, props){ |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
if(props.top >= 0){ |
| 202 |
props.top += this.cellSize; |
| 203 |
} |
| 204 |
if(props.left >= 0){ |
| 205 |
props.left += this.cellSize; |
| 206 |
} |
| 207 |
var _cc = this.cellSize - (this.cellMargin * 2); |
| 208 |
dojo.animateProperty({ |
| 209 |
node: info.n, |
| 210 |
properties: dojo.mixin(props, { |
| 211 |
width:_cc, |
| 212 |
height:_cc |
| 213 |
}), |
| 214 |
onEnd: dojo.hitch(this, "_cycle", info, props) |
| 215 |
}).play(5); |
| 216 |
}, |
| 217 |
|
| 218 |
_cycle: function(info, props){ |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
var bc = this.baseClass; |
| 223 |
dojo.removeClass(info.n, bc + "Top"); |
| 224 |
var ns = this._nl.filter(function(n){ |
| 225 |
return !dojo.hasClass(n, bc + "Seen") |
| 226 |
}); |
| 227 |
var c = ns[Math.floor(Math.random() * ns.length)]; |
| 228 |
setTimeout(dojo.hitch(this,"_enbiggen", { target: c }), this.delay / 2) |
| 229 |
|
| 230 |
} |
| 231 |
|
| 232 |
}); |
| 233 |
}); |
| 234 |
|