| 1 |
define(["dojo/_base/array","dojo/_base/lang", "dojo/_base/fx", "dojo/fx", "dojo/dom", "dojo/dom-style", |
| 2 |
"dojo/dom-geometry", "dojo/_base/connect", "dojo/_base/html"], |
| 3 |
function(arrayUtil, lang, baseFx, coreFx, dom, domStyle, domGeom, connectUtil, htmlUtil){ |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var dojoxFx = lang.getObject("dojox.fx", true); |
| 14 |
|
| 15 |
lang.mixin(dojoxFx, { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
anim: baseFx.anim, |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
animateProperty: baseFx.animateProperty, |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
fadeTo: baseFx._fade, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
fadeIn: baseFx.fadeIn, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
fadeOut: baseFx.fadeOut, |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
combine: coreFx.combine, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
chain: coreFx.chain, |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
slideTo: coreFx.slideTo, |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
wipeIn: coreFx.wipeIn, |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
wipeOut: coreFx.wipeOut |
| 58 |
}); |
| 59 |
|
| 60 |
|
| 61 |
dojoxFx.sizeTo = function(args){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
var node = args.node = dom.byId(args.node), |
| 86 |
abs = "absolute"; |
| 87 |
|
| 88 |
var method = args.method || "chain"; |
| 89 |
if(!args.duration){ args.duration = 500; } |
| 90 |
if(method == "chain"){ args.duration = Math.floor(args.duration / 2); } |
| 91 |
|
| 92 |
var top, newTop, left, newLeft, width, height = null; |
| 93 |
|
| 94 |
var init = (function(n){ |
| 95 |
return function(){ |
| 96 |
var cs = domStyle.getComputedStyle(n), |
| 97 |
pos = cs.position, |
| 98 |
w = cs.width, |
| 99 |
h = cs.height |
| 100 |
; |
| 101 |
|
| 102 |
top = (pos == abs ? n.offsetTop : parseInt(cs.top) || 0); |
| 103 |
left = (pos == abs ? n.offsetLeft : parseInt(cs.left) || 0); |
| 104 |
width = (w == "auto" ? 0 : parseInt(w)); |
| 105 |
height = (h == "auto" ? 0 : parseInt(h)); |
| 106 |
|
| 107 |
newLeft = left - Math.floor((args.width - width) / 2); |
| 108 |
newTop = top - Math.floor((args.height - height) / 2); |
| 109 |
|
| 110 |
if(pos != abs && pos != 'relative'){ |
| 111 |
var ret = domStyle.coords(n, true); |
| 112 |
top = ret.y; |
| 113 |
left = ret.x; |
| 114 |
n.style.position = abs; |
| 115 |
n.style.top = top + "px"; |
| 116 |
n.style.left = left + "px"; |
| 117 |
} |
| 118 |
} |
| 119 |
})(node); |
| 120 |
|
| 121 |
var anim1 = baseFx.animateProperty(lang.mixin({ |
| 122 |
properties: { |
| 123 |
height: function(){ |
| 124 |
init(); |
| 125 |
return { end: args.height || 0, start: height }; |
| 126 |
}, |
| 127 |
top: function(){ |
| 128 |
return { start: top, end: newTop }; |
| 129 |
} |
| 130 |
} |
| 131 |
}, args)); |
| 132 |
var anim2 = baseFx.animateProperty(lang.mixin({ |
| 133 |
properties: { |
| 134 |
width: function(){ |
| 135 |
return { start: width, end: args.width || 0 } |
| 136 |
}, |
| 137 |
left: function(){ |
| 138 |
return { start: left, end: newLeft } |
| 139 |
} |
| 140 |
} |
| 141 |
}, args)); |
| 142 |
|
| 143 |
var anim = coreFx[(args.method == "combine" ? "combine" : "chain")]([anim1, anim2]); |
| 144 |
return anim; |
| 145 |
|
| 146 |
}; |
| 147 |
|
| 148 |
dojoxFx.slideBy = function(args){ |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
var node = args.node = dom.byId(args.node), |
| 165 |
top, left; |
| 166 |
|
| 167 |
var init = (function(n){ |
| 168 |
return function(){ |
| 169 |
var cs = domStyle.getComputedStyle(n); |
| 170 |
var pos = cs.position; |
| 171 |
top = (pos == 'absolute' ? n.offsetTop : parseInt(cs.top) || 0); |
| 172 |
left = (pos == 'absolute' ? n.offsetLeft : parseInt(cs.left) || 0); |
| 173 |
if(pos != 'absolute' && pos != 'relative'){ |
| 174 |
var ret = domGeom.coords(n, true); |
| 175 |
top = ret.y; |
| 176 |
left = ret.x; |
| 177 |
n.style.position = "absolute"; |
| 178 |
n.style.top = top + "px"; |
| 179 |
n.style.left = left + "px"; |
| 180 |
} |
| 181 |
} |
| 182 |
})(node); |
| 183 |
init(); |
| 184 |
|
| 185 |
var _anim = baseFx.animateProperty(lang.mixin({ |
| 186 |
properties: { |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
top: top + (args.top || 0), |
| 191 |
left: left + (args.left || 0) |
| 192 |
} |
| 193 |
}, args)); |
| 194 |
connectUtil.connect(_anim, "beforeBegin", _anim, init); |
| 195 |
return _anim; |
| 196 |
}; |
| 197 |
|
| 198 |
dojoxFx.crossFade = function(args){ |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
var node1 = args.nodes[0] = dom.byId(args.nodes[0]), |
| 208 |
op1 = htmlUtil.style(node1,"opacity"), |
| 209 |
node2 = args.nodes[1] = dom.byId(args.nodes[1]), |
| 210 |
op2 = htmlUtil.style(node2, "opacity") |
| 211 |
; |
| 212 |
|
| 213 |
var _anim = coreFx.combine([ |
| 214 |
baseFx[(op1 == 0 ? "fadeIn" : "fadeOut")](lang.mixin({ |
| 215 |
node: node1 |
| 216 |
},args)), |
| 217 |
baseFx[(op1 == 0 ? "fadeOut" : "fadeIn")](lang.mixin({ |
| 218 |
node: node2 |
| 219 |
},args)) |
| 220 |
]); |
| 221 |
return _anim; |
| 222 |
}; |
| 223 |
|
| 224 |
dojoxFx.highlight = function( args){ |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
var node = args.node = dom.byId(args.node); |
| 236 |
|
| 237 |
args.duration = args.duration || 400; |
| 238 |
|
| 239 |
|
| 240 |
var startColor = args.color || '#ffff99', |
| 241 |
endColor = htmlUtil.style(node, "backgroundColor") |
| 242 |
; |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
if(endColor == "rgba(0, 0, 0, 0)"){ |
| 251 |
endColor = "transparent"; |
| 252 |
} |
| 253 |
|
| 254 |
var anim = baseFx.animateProperty(lang.mixin({ |
| 255 |
properties: { |
| 256 |
backgroundColor: { start: startColor, end: endColor } |
| 257 |
} |
| 258 |
}, args)); |
| 259 |
|
| 260 |
if(endColor == "transparent"){ |
| 261 |
connectUtil.connect(anim, "onEnd", anim, function(){ |
| 262 |
node.style.backgroundColor = endColor; |
| 263 |
}); |
| 264 |
} |
| 265 |
|
| 266 |
return anim; |
| 267 |
}; |
| 268 |
|
| 269 |
|
| 270 |
dojoxFx.wipeTo = function( args){ |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
args.node = dom.byId(args.node); |
| 292 |
var node = args.node, s = node.style; |
| 293 |
|
| 294 |
var dir = (args.width ? "width" : "height"), |
| 295 |
endVal = args[dir], |
| 296 |
props = {} |
| 297 |
; |
| 298 |
|
| 299 |
props[dir] = { |
| 300 |
|
| 301 |
start: function(){ |
| 302 |
|
| 303 |
|
| 304 |
s.overflow = "hidden"; |
| 305 |
if(s.visibility == "hidden" || s.display == "none"){ |
| 306 |
s[dir] = "1px"; |
| 307 |
s.display = ""; |
| 308 |
s.visibility = ""; |
| 309 |
return 1; |
| 310 |
}else{ |
| 311 |
var now = htmlUtil.style(node,dir); |
| 312 |
return Math.max(now, 1); |
| 313 |
} |
| 314 |
}, |
| 315 |
end: endVal |
| 316 |
}; |
| 317 |
|
| 318 |
var anim = baseFx.animateProperty(lang.mixin({ properties: props }, args)); |
| 319 |
return anim; |
| 320 |
}; |
| 321 |
|
| 322 |
return dojoxFx; |
| 323 |
}); |