(function() {
YAHOO.util.Motion = function(el, attributes, duration, method) {
if (el) {
YAHOO.util.Motion.superclass.constructor.call(this, el, attributes, duration, method);
}
};
YAHOO.extend(YAHOO.util.Motion, YAHOO.util.ColorAnim);
var Y = YAHOO.util;
var superclass = Y.Motion.superclass;
var prototype = Y.Motion.prototype;
prototype.toString = function() {
var el = this.getEl();
var id = el.id || el.tagName;
return ("Motion " + id);
};
prototype.patterns.points = /^points$/i;
prototype.setAttribute = function(attr, val, unit) {
if ( this.patterns.points.test(attr) ) {
unit = unit || 'px';
superclass.setAttribute.call(this, 'left', val[0], unit);
superclass.setAttribute.call(this, 'top', val[1], unit);
} else {
superclass.setAttribute.call(this, attr, val, unit);
}
};
prototype.getAttribute = function(attr) {
if ( this.patterns.points.test(attr) ) {
var val = [
superclass.getAttribute.call(this, 'left'),
superclass.getAttribute.call(this, 'top')
];
} else {
val = superclass.getAttribute.call(this, attr);
}
return val;
};
prototype.doMethod = function(attr, start, end) {
var val = null;
if ( this.patterns.points.test(attr) ) {
var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
} else {
val = superclass.doMethod.call(this, attr, start, end);
}
return val;
};
prototype.setRuntimeAttribute = function(attr) {
if ( this.patterns.points.test(attr) ) {
var el = this.getEl();
var attributes = this.attributes;
var start;
var control = attributes['points']['control'] || [];
var end;
var i, len;
if (control.length > 0 && control[0].constructor.toString().indexOf('Array') < 0) {
control = [control];
} else {
var tmp = [];
for (i = 0, len = control.length; i< len; ++i) {
tmp[i] = control[i];
}
control = tmp;
}
if (Y.Dom.getStyle(el, 'position') == 'static') {
Y.Dom.setStyle(el, 'position', 'relative');
}
if ( isset(attributes['points']['from']) ) {
Y.Dom.setXY(el, attributes['points']['from']);
}
else { Y.Dom.setXY( el, Y.Dom.getXY(el) ); }
start = this.getAttribute('points');
if ( isset(attributes['points']['to']) ) {
end = translateValues.call(this, attributes['points']['to'], start);
var pageXY = Y.Dom.getXY(this.getEl());
for (i = 0, len = control.length; i < len; ++i) {
control[i] = translateValues.call(this, control[i], start);
}
} else if ( isset(attributes['points']['by']) ) {
end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
for (i = 0, len = control.length; i < len; ++i) {
control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
}
}
this.runtimeAttributes[attr] = [start];
if (control.length > 0) {
this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
}
this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
}
else {
superclass.setRuntimeAttribute.call(this, attr);
}
};
var translateValues = function(val, start) {
var pageXY = Y.Dom.getXY(this.getEl());
val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
return val;
};
var isset = function(prop) {
return (typeof prop !== 'undefined');
};
})();