| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/connect", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/dom-style", |
| 6 |
"dojo/_base/fx", |
| 7 |
"dojo/fx" |
| 8 |
], function(array, connect, lang, domStyle, baseFx, fx) { |
| 9 |
|
| 10 |
|
| 11 |
var DOWN = 0, |
| 12 |
RIGHT = 1, |
| 13 |
UP = 2, |
| 14 |
LEFT = 3; |
| 15 |
|
| 16 |
function _pan(type, args){ |
| 17 |
|
| 18 |
|
| 19 |
var n = args.next.node, |
| 20 |
r = args.rotatorBox, |
| 21 |
m = type % 2, |
| 22 |
a = m ? "left" : "top", |
| 23 |
s = (m ? r.w : r.h) * (type < 2 ? -1 : 1), |
| 24 |
p = {}, |
| 25 |
q = {}; |
| 26 |
|
| 27 |
domStyle.set(n, "display", ""); |
| 28 |
|
| 29 |
p[a] = { |
| 30 |
start: 0, |
| 31 |
end: -s |
| 32 |
}; |
| 33 |
|
| 34 |
q[a] = { |
| 35 |
start: s, |
| 36 |
end: 0 |
| 37 |
}; |
| 38 |
|
| 39 |
return fx.combine([ |
| 40 |
baseFx.animateProperty({ |
| 41 |
node: args.current.node, |
| 42 |
duration: args.duration, |
| 43 |
properties: p, |
| 44 |
easing: args.easing |
| 45 |
}), |
| 46 |
baseFx.animateProperty({ |
| 47 |
node: n, |
| 48 |
duration: args.duration, |
| 49 |
properties: q, |
| 50 |
easing: args.easing |
| 51 |
}) |
| 52 |
]); |
| 53 |
} |
| 54 |
|
| 55 |
function _setZindex(n, z){ |
| 56 |
|
| 57 |
|
| 58 |
domStyle.set(n, "zIndex", z); |
| 59 |
} |
| 60 |
|
| 61 |
var exports = { |
| 62 |
pan: function(args){ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
var w = args.wrap, |
| 91 |
p = args.rotator.panes, |
| 92 |
len = p.length, |
| 93 |
z = len, |
| 94 |
j = args.current.idx, |
| 95 |
k = args.next.idx, |
| 96 |
nw = Math.abs(k - j), |
| 97 |
ww = Math.abs((len - Math.max(j, k)) + Math.min(j, k)) % len, |
| 98 |
_forward = j < k, |
| 99 |
_dir = LEFT, |
| 100 |
_pans = [], |
| 101 |
_nodes = [], |
| 102 |
_duration = args.duration; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
if((!w && !_forward) || (w && (_forward && nw > ww || !_forward && nw < ww))){ |
| 107 |
_dir = RIGHT; |
| 108 |
} |
| 109 |
|
| 110 |
if(args.continuous){ |
| 111 |
|
| 112 |
if(args.quick){ |
| 113 |
_duration = Math.round(_duration / (w ? Math.min(ww, nw) : nw)); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
_setZindex(p[j].node, z--); |
| 118 |
|
| 119 |
var f = (_dir == LEFT); |
| 120 |
|
| 121 |
|
| 122 |
while(1){ |
| 123 |
|
| 124 |
var i = j; |
| 125 |
|
| 126 |
|
| 127 |
if(f){ |
| 128 |
if(++j >= len){ |
| 129 |
j = 0; |
| 130 |
} |
| 131 |
}else{ |
| 132 |
if(--j < 0){ |
| 133 |
j = len - 1; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
var x = p[i], |
| 138 |
y = p[j]; |
| 139 |
|
| 140 |
|
| 141 |
_setZindex(y.node, z--); |
| 142 |
|
| 143 |
|
| 144 |
_pans.push(_pan(_dir, lang.mixin({ |
| 145 |
easing: function(m){ return m; } |
| 146 |
}, args, { |
| 147 |
current: x, |
| 148 |
next: y, |
| 149 |
duration: _duration |
| 150 |
}))); |
| 151 |
|
| 152 |
|
| 153 |
if((f && j == k) || (!f && j == k)){ |
| 154 |
break; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
_nodes.push(y.node); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
var _anim = fx.chain(_pans), |
| 164 |
|
| 165 |
|
| 166 |
h = connect.connect(_anim, "onEnd", function(){ |
| 167 |
connect.disconnect(h); |
| 168 |
array.forEach(_nodes, function(q){ |
| 169 |
domStyle.set(q, { |
| 170 |
display: "none", |
| 171 |
left: 0, |
| 172 |
opacity: 1, |
| 173 |
top: 0, |
| 174 |
zIndex: 0 |
| 175 |
}); |
| 176 |
}); |
| 177 |
}); |
| 178 |
|
| 179 |
return _anim; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
return _pan(_dir, args); |
| 184 |
}, |
| 185 |
|
| 186 |
panDown: function(args){ |
| 187 |
|
| 188 |
|
| 189 |
return _pan(DOWN, args); |
| 190 |
}, |
| 191 |
|
| 192 |
panRight: function(args){ |
| 193 |
|
| 194 |
|
| 195 |
return _pan(RIGHT, args); |
| 196 |
}, |
| 197 |
|
| 198 |
panUp: function(args){ |
| 199 |
|
| 200 |
|
| 201 |
return _pan(UP, args); |
| 202 |
}, |
| 203 |
|
| 204 |
panLeft: function(args){ |
| 205 |
|
| 206 |
|
| 207 |
return _pan(LEFT, args); |
| 208 |
} |
| 209 |
}; |
| 210 |
|
| 211 |
|
| 212 |
lang.mixin(lang.getObject("dojox.widget.rotator"), exports); |
| 213 |
|
| 214 |
return exports; |
| 215 |
}); |