2 * Portions of this file are based on pieces of Yahoo User Interface Library
3 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4 * YUI licensed under the BSD License:
5 * http://developer.yahoo.net/yui/license.txt
6 * <script type="text/javascript">
10 Roo.lib.Motion = function(el, attributes, duration, method) {
12 Roo.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
16 Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
20 var superclass = Y.Motion.superclass;
21 var proto = Y.Motion.prototype;
23 proto.toString = function() {
24 var el = this.getEl();
25 var id = el.id || el.tagName;
26 return ("Motion " + id);
29 proto.patterns.points = /^points$/i;
31 proto.setAttribute = function(attr, val, unit) {
32 if (this.patterns.points.test(attr)) {
34 superclass.setAttribute.call(this, 'left', val[0], unit);
35 superclass.setAttribute.call(this, 'top', val[1], unit);
37 superclass.setAttribute.call(this, attr, val, unit);
41 proto.getAttribute = function(attr) {
42 if (this.patterns.points.test(attr)) {
44 superclass.getAttribute.call(this, 'left'),
45 superclass.getAttribute.call(this, 'top')
48 val = superclass.getAttribute.call(this, attr);
54 proto.doMethod = function(attr, start, end) {
57 if (this.patterns.points.test(attr)) {
58 var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
59 val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
61 val = superclass.doMethod.call(this, attr, start, end);
66 proto.setRuntimeAttribute = function(attr) {
67 if (this.patterns.points.test(attr)) {
68 var el = this.getEl();
69 var attributes = this.attributes;
71 var control = attributes['points']['control'] || [];
75 if (control.length > 0 && !(control[0] instanceof Array)) {
79 for (i = 0,len = control.length; i < len; ++i) {
85 Roo.fly(el).position();
87 if (isset(attributes['points']['from'])) {
88 Roo.lib.Dom.setXY(el, attributes['points']['from']);
91 Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
94 start = this.getAttribute('points');
97 if (isset(attributes['points']['to'])) {
98 end = translateValues.call(this, attributes['points']['to'], start);
100 var pageXY = Roo.lib.Dom.getXY(this.getEl());
101 for (i = 0,len = control.length; i < len; ++i) {
102 control[i] = translateValues.call(this, control[i], start);
106 } else if (isset(attributes['points']['by'])) {
107 end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
109 for (i = 0,len = control.length; i < len; ++i) {
110 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
114 this.runtimeAttributes[attr] = [start];
116 if (control.length > 0) {
117 this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
120 this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
123 superclass.setRuntimeAttribute.call(this, attr);
127 var translateValues = function(val, start) {
128 var pageXY = Roo.lib.Dom.getXY(this.getEl());
129 val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
134 var isset = function(prop) {
135 return (typeof prop !== 'undefined');