| 1 |
define(["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/array","dojo/_base/declare", "dojo/_base/connect", |
| 2 |
"dojo/_base/Color", "dojo/_base/fx", "dojo/fx"], |
| 3 |
function(dojo, lang, arrayUtil, declare, connectUtil, Color, baseFx, coreFx){ |
| 4 |
lang.getObject("dojox.fx.ext-dojo.complex", true); |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
var da = baseFx.animateProperty; |
| 32 |
dojo.animateProperty = baseFx.animateProperty = function(options){ |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
var ani = da(options); |
| 56 |
|
| 57 |
connectUtil.connect(ani, "beforeBegin", function(){ |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ani.curve.getValue = function(r){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
var ret = {}; |
| 66 |
for(var p in this._properties){ |
| 67 |
var prop = this._properties[p], |
| 68 |
start = prop.start; |
| 69 |
if(start instanceof dojo.Color){ |
| 70 |
ret[p] = dojo.blendColors(start, prop.end, r, prop.tempColor).toCss(); |
| 71 |
}else if(start instanceof dojox.fx._Complex){ |
| 72 |
ret[p] = start.getValue(r); |
| 73 |
}else if(!dojo.isArray(start)){ |
| 74 |
ret[p] = ((prop.end - start) * r) + start + (p != "opacity" ? prop.units || "px" : 0); |
| 75 |
} |
| 76 |
} |
| 77 |
return ret; |
| 78 |
}; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
var pm = {}; |
| 84 |
for(var p in this.properties){ |
| 85 |
var o = this.properties[p]; |
| 86 |
if(typeof(o.start) == "string" && /\(/.test(o.start)){ |
| 87 |
this.curve._properties[p].start = new dojox.fx._Complex(o); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
}); |
| 92 |
return ani; |
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
return declare("dojox.fx._Complex", null, { |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
PROP: /\([\w|,|+|\-|#|\.|\s]*\)/g, |
| 108 |
constructor: function(options){ |
| 109 |
var beg = options.start.match(this.PROP); |
| 110 |
var end = options.end.match(this.PROP); |
| 111 |
|
| 112 |
var begProps = arrayUtil.map(beg, this.getProps, this); |
| 113 |
var endProps = arrayUtil.map(end, this.getProps, this); |
| 114 |
|
| 115 |
this._properties = {}; |
| 116 |
this.strProp = options.start; |
| 117 |
arrayUtil.forEach(begProps, function(prop, i){ |
| 118 |
arrayUtil.forEach(prop, function(p, j){ |
| 119 |
this.strProp = this.strProp.replace(p, "PROP_"+i+""+j); |
| 120 |
this._properties["PROP_"+i+""+j] = this.makePropObject(p, endProps[i][j]) |
| 121 |
},this); |
| 122 |
},this); |
| 123 |
}, |
| 124 |
|
| 125 |
getValue: function(r){ |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
var str = this.strProp, u; |
| 130 |
for(var nm in this._properties){ |
| 131 |
var v, o = this._properties[nm]; |
| 132 |
if(o.units == "isColor"){ |
| 133 |
v = Color.blendColors(o.beg, o.end, r).toCss(false); |
| 134 |
u = ""; |
| 135 |
}else{ |
| 136 |
v = ((o.end - o.beg) * r) + o.beg; |
| 137 |
u = o.units; |
| 138 |
} |
| 139 |
str = str.replace(nm, v + u); |
| 140 |
} |
| 141 |
|
| 142 |
return str; |
| 143 |
}, |
| 144 |
|
| 145 |
makePropObject: function(beg, end){ |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
var b = this.getNumAndUnits(beg); |
| 151 |
var e = this.getNumAndUnits(end); |
| 152 |
return { |
| 153 |
beg:b.num, |
| 154 |
end:e.num, |
| 155 |
units:b.units |
| 156 |
}; |
| 157 |
}, |
| 158 |
|
| 159 |
getProps: function(str){ |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
str = str.substring(1, str.length-1); |
| 165 |
var s; |
| 166 |
if(/,/.test(str)){ |
| 167 |
str = str.replace(/\s/g, ""); |
| 168 |
s = str.split(","); |
| 169 |
}else{ |
| 170 |
str = str.replace(/\s{2,}/g, " "); |
| 171 |
s = str.split(" "); |
| 172 |
} |
| 173 |
return s; |
| 174 |
}, |
| 175 |
getNumAndUnits: function(prop){ |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
if(!prop){ return {}; } |
| 182 |
if(/#/.test(prop)){ |
| 183 |
return { |
| 184 |
num: new Color(prop), |
| 185 |
units:"isColor" |
| 186 |
}; |
| 187 |
} |
| 188 |
var o = { |
| 189 |
num:parseFloat(/-*[\d\.\d|\d]{1,}/.exec(prop).join("")) |
| 190 |
}; |
| 191 |
o.units = /[a-z]{1,}/.exec(prop); |
| 192 |
o.units = o.units && o.units.length ? o.units.join("") : ""; |
| 193 |
return o; |
| 194 |
} |
| 195 |
}); |
| 196 |
}); |