1: if (typeof vx === "undefined") {
2: vx = {};
3: vx.loadEvent = function ( F ) {
4: var oldonload = window.onload;
5: if (typeof window.onload !== 'function') {
6: window.onload = F;
7: } else {
8: window.onload = function ( ) {
9: oldonload();
10: F();
11: };
12: }
13: };
14: };
15:
16: vx.delay = function( amount, F ) {
17: if (!F) {
18: return false;
19: } else {
20: setTimeout(function() { F(); }, amount);
21: }
22: };
23: vx.animate = function( elem, opts, duration, fps, easing ) {
24: var duration = duration ? parseFloat(duration) : 1000;
25: var fps = fps ? parseFloat(fps) : 20;
26: var startTime = new Date().getTime();
27: var endTime = startTime + duration;
28: var frame = 1;
29: var timer = undefined;
30: var easing = easing ? easing: vx.easing.linear;
31: var interval = Math.ceil(1000 / fps);
32: var totalframes = Math.ceil(duration / interval);
33:
34: var setAnimation = function() {
35: var time = new Date().getTime();
36: frame = parseInt((time - startTime) / interval);
37: var onEnd = undefined;
38: var onStart = undefined;
39:
40: for (var prop in opts){
41: if (prop !== "onEnd" || prop !== "onStart") {
42: vx.animate.utils.manufacture(elem, totalframes, frame, prop, opts, easing);
43: }
44: if (prop === "onEnd") {
45: onEnd = opts[prop];
46: }
47: if (prop === "onStart") {
48: onStart = opts[prop];
49: }
50: }
51: if (onStart) {
52: onStart();
53: }
54: if (time >= startTime + duration) {
55: if (onEnd) {
56: onEnd();
57: }
58: //console.log("endTime is: " + endTime + "; present time is: " + new Date().getTime());
59: clearInterval(timer);
60: }
61: };
62: var timer = setInterval(setAnimation, interval);
63: };
64:
65: vx.animate.utils = {
66: manufacture : function ( elem, totalframes, frame, prop, opts, easing ) {
67: var start = opts[prop].start;
68: if (/[0-9]+/.test(parseInt(start)) && !/\s/.test(start)) {
69: this.calculate(elem, totalframes, frame, prop, opts, easing);
70: return true;
71: }
72: var method = this.camelize(prop);
73: if (this[method]) {
74: this[method](elem, totalframes, frame, prop, opts, easing);
75: return true;
76: }
77: return false;
78: },
79: calculate : function ( elem, totalframes, frame, prop, opts, easing ) {
80: var start = opts[prop].start * 100;
81: var end = opts[prop].end * 100;
82: var units = undefined;
83: if (opts[prop].units) {
84: units = opts[prop].units;
85: }
86: var bezier = opts[prop].bezier * 100;
87: var tween = easing(frame, start, end - start, totalframes);
88: if (bezier) {
89: tween = this.bezier(frame, tween, end, bezier, totalframes);
90: }
91: this.style(elem, prop, tween / 100, units);
92: elem.style.zoom = 1;
93: },
94: style : function ( elem, prop, val, units ) {
95: if (units) {
96: var units = units;
97: } else {
98: var units = "";
99: }
100: if (prop === "opacity") {
101: return this.opacity(elem, parseFloat(val));
102: }
103: if (prop === "float") {
104: prop = (window.attachEvent) ? 'styleFloat': 'cssFloat';
105: }
106: prop = this.camelize(prop);
107: if (!units) {
108: units = (prop === 'zIndex' || prop === 'zoom') ? '': 'px';
109: }
110: try {
111: elem.style[prop] = (typeof val === "string") ? val : val + units;
112: return elem;
113: } catch(e){}
114: },
115: determineMultiValue : function ( elem, totalframes, frame, prop, opts, easing ) {
116:
117: var suffix = ["Top", "Right", "Bottom", "Left"];
118: var prop = prop;
119: var start = opts[prop].start.split(/\s/) || [];
120: var end = opts[prop].end.split(/\s/) || [];
121: var units = (opts[prop].units) ? opts[prop].units : "px";
122:
123: var t = 0; r = 0; b = 0; l = 0;
124: if (start.length === 2) {
125: t = 0; r = 1; b = 0; l = 1;
126: }
127: if (start.length === 3) {
128: t = 0; r = 1; b = 2; l = 1;
129: }
130: if (start.length === 4) {
131: t = 0; r = 1; b = 2; l = 3;
132: }
133: var tempProp = undefined;
134: var a = [t, r, b, l];
135: var len = a.length;
136: for (var i = 0; i < len; i++) {
137: tempProp = prop + suffix[i];
138:
139: var z = eval("opts4 = { " + tempProp + ": { start : " + start[a[i]] + ", end : " + end[a[i]] + " }}");
140: this.calculate(elem, totalframes, frame, tempProp, z, easing);
141: }
142: },
143: opacity : function ( elem, val ) {
144: if (elem.style.filter) {
145: elem.style.zoom = 1;
146: }
147: elem.style.filter = "alpha(opacity=" + parseFloat(val * 100) + ")";
148: elem.style.opacity = parseFloat(val);
149: return elem;
150: },
151: color : function ( elem, totalframes, frame, prop, opts, easing ) {
152:
153: var c1 = opts[prop].start.toLowerCase();
154: var c2 = opts[prop].end.toLowerCase();
155:
156: function returnColorValue ( v ) {
157: for (color in vx.color) {
158: if (v === color) {
159: return vx.color[color];
160: }
161: }
162: }
163: if (!/#/.test(c1)) {
164: c1 = returnColorValue(c1);
165: }
166: if (!/#/.test(c2)) {
167: c2 = returnColorValue(c2);
168: }
169: var b = this.hexToArray(c1);
170: var e = this.hexToArray(c2);
171: var rgb = [];
172: for (j = 0; j < 3; j++) {
173: rgb.push(parseInt(easing(frame, b[j], e[j] - b[j], totalframes)));
174: }
175: this.style(elem, prop, 'rgb(' + rgb.join(',') + ')');
176: },
177: backgroundColor : function ( elem, totalframes, frame, prop, opts, easing ) {
178: this.color(elem, totalframes, frame, prop, opts, easing);
179: },
180: borderColor : function ( elem, totalframes, frame, prop, opts, easing ) {
181: this.color(elem, totalframes, frame, prop, opts, easing);
182: },
183: padding : function ( elem, totalframes, frame, prop, opts, easing ) {
184: this.determineMultiValue(elem, totalframes, frame, prop, opts, easing);
185: },
186: margin : function ( elem, totalframes, frame, prop, opts, easing ) {
187: this.determineMultiValue(elem, totalframes, frame, prop, opts, easing);
188: },
189: bezier : function ( frame, begin, end, deviator, totalframes ) {
190: var t = frame / totalframes;
191: return (1 - t) * (1 - t) * begin + 2 * t * (1 - t) * deviator + t * t * end;
192: },
193: hexToDec : function ( hex ) {
194: return parseInt(hex, 16);
195: },
196: hexToRgb : function ( h, e, x ) {
197: return [this.hexToDec(h), this.hexToDec(e), this.hexToDec(x)];
198: },
199: hexToArray : function ( color ) {
200: return this.hexToRgb(color.substring(1, 3), color.substring(3, 5), color.substring(5, 7));
201: },
202: camelize : function ( value ) {
203: return value.replace(/-(.)/g,
204: function(m, l) {