3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">(function(){
\r
10 var EXTLIB = Ext.lib,
\r
11 noNegatives = /width|height|opacity|padding/i,
\r
12 offsetAttribute = /^((width|height)|(top|left))$/,
\r
13 defaultUnit = /width|height|top$|bottom$|left$|right$/i,
\r
14 offsetUnit = /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i,
\r
15 isset = function(v){
\r
16 return typeof v !== 'undefined';
\r
23 motion : function(el, args, duration, easing, cb, scope) {
\r
24 return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
\r
27 run : function(el, args, duration, easing, cb, scope, type) {
\r
28 type = type || Ext.lib.AnimBase;
\r
29 if (typeof easing == "string") {
\r
30 easing = Ext.lib.Easing[easing];
\r
32 var anim = new type(el, args, duration, easing);
\r
33 anim.animateX(function() {
\r
34 if(Ext.isFunction(cb)){
\r
42 EXTLIB.AnimBase = function(el, attributes, duration, method) {
\r
44 this.init(el, attributes, duration, method);
\r
48 EXTLIB.AnimBase.prototype = {
\r
49 doMethod: function(attr, start, end) {
\r
51 return me.method(me.curFrame, start, end - start, me.totalFrames);
\r
55 setAttr: function(attr, val, unit) {
\r
56 if (noNegatives.test(attr) && val < 0) {
\r
59 Ext.fly(this.el, '_anim').setStyle(attr, val + unit);
\r
63 getAttr: function(attr) {
\r
64 var el = Ext.fly(this.el),
\r
65 val = el.getStyle(attr),
\r
66 a = offsetAttribute.exec(attr) || []
\r
68 if (val !== 'auto' && !offsetUnit.test(val)) {
\r
69 return parseFloat(val);
\r
72 return (!!(a[2]) || (el.getStyle('position') == 'absolute' && !!(a[3]))) ? el.dom['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)] : 0;
\r
76 getDefaultUnit: function(attr) {
\r
77 return defaultUnit.test(attr) ? 'px' : '';
\r
80 animateX : function(callback, scope) {
\r
83 me.onComplete.removeListener(f);
\r
84 if (Ext.isFunction(callback)) {
\r
85 callback.call(scope || me, me);
\r
88 me.onComplete.addListener(f, me);
\r
93 setRunAttr: function(attr) {
\r
95 a = this.attributes[attr],
\r
100 ra = (this.runAttrs[attr] = {}),
\r
103 if (!isset(to) && !isset(by)){
\r
107 var start = isset(from) ? from : me.getAttr(attr);
\r
110 }else if(isset(by)) {
\r
111 if (Ext.isArray(start)){
\r
113 for(var i=0,len=start.length; i<len; i++) {
\r
114 end[i] = start[i] + by[i];
\r
124 unit: isset(unit) ? unit : me.getDefaultUnit(attr)
\r
129 init: function(el, attributes, duration, method) {
\r
132 mgr = EXTLIB.AnimMgr;
\r
137 el: Ext.getDom(el),
\r
138 attributes: attributes || {},
\r
139 duration: duration || 1,
\r
140 method: method || EXTLIB.Easing.easeNone,
\r
143 totalFrames: mgr.fps,
\r
145 animate: function(){
\r
154 me.totalFrames = me.useSec ? Math.ceil(mgr.fps * d) : d;
\r
155 mgr.registerElement(me);
\r
158 stop: function(finish){
\r
162 me.curFrame = me.totalFrames;
\r
163 me._onTween.fire();
\r
169 var onStart = function(){
\r
175 for(attr in this.attributes){
\r
176 this.setRunAttr(attr);
\r
179 me.isAnimated = true;
\r
180 me.startTime = now();
\r
185 var onTween = function(){
\r
189 duration: now() - me.startTime,
\r
190 curFrame: me.curFrame
\r
193 var ra = me.runAttrs;
\r
194 for (var attr in ra) {
\r
195 this.setAttr(attr, me.doMethod(attr, ra[attr].start, ra[attr].end), ra[attr].unit);
\r
201 var onComplete = function() {
\r
203 actual = (now() - me.startTime) / 1000,
\r
206 frames: actualFrames,
\r
207 fps: actualFrames / actual
\r
210 me.isAnimated = false;
\r
212 me.onComplete.fire(data);
\r
215 me.onStart = new Ext.util.Event(me);
\r
216 me.onTween = new Ext.util.Event(me);
\r
217 me.onComplete = new Ext.util.Event(me);
\r
218 (me._onStart = new Ext.util.Event(me)).addListener(onStart);
\r
219 (me._onTween = new Ext.util.Event(me)).addListener(onTween);
\r
220 (me._onComplete = new Ext.util.Event(me)).addListener(onComplete);
\r
225 Ext.lib.AnimMgr = new function() {
\r
235 registerElement: function(tween){
\r
238 tween._onStart.fire();
\r
242 unRegister: function(tween, index){
\r
243 tween._onComplete.fire();
\r
244 index = index || getIndex(tween);
\r
246 queue.splice(index, 1);
\r
249 if (--tweenCount <= 0) {
\r
255 if(thread === null){
\r
256 thread = setInterval(me.run, me.delay);
\r
260 stop: function(tween){
\r
262 clearInterval(thread);
\r
263 for(var i = 0, len = queue.length; i < len; ++i){
\r
264 if(queue[0].isAnimated){
\r
265 me.unRegister(queue[0], 0);
\r
273 me.unRegister(tween);
\r
278 var tf, i, len, tween;
\r
279 for(i = 0, len = queue.length; i<len; i++) {
\r
281 if(tween && tween.isAnimated){
\r
282 tf = tween.totalFrames;
\r
283 if(tween.curFrame < tf || tf === null){
\r
286 correctFrame(tween);
\r
288 tween._onTween.fire();
\r
297 var getIndex = function(anim) {
\r
299 for(i = 0, len = queue.length; i<len; i++) {
\r
300 if(queue[i] === anim) {
\r
307 var correctFrame = function(tween) {
\r
308 var frames = tween.totalFrames,
\r
309 frame = tween.curFrame,
\r
310 duration = tween.duration,
\r
311 expected = (frame * duration * 1000 / frames),
\r
312 elapsed = (now() - tween.startTime),
\r
315 if(elapsed < duration * 1000){
\r
316 tweak = Math.round((elapsed / expected - 1) * frame);
\r
318 tweak = frames - (frame + 1);
\r
320 if(tweak > 0 && isFinite(tweak)){
\r
321 if(tween.curFrame + tweak >= frames){
\r
322 tweak = frames - (frame + 1);
\r
324 tween.curFrame += tweak;
\r
329 EXTLIB.Bezier = new function() {
\r
331 this.getPosition = function(points, t) {
\r
332 var n = points.length,
\r
338 for (i = 0; i < n; ++i) {
\r
339 tmp[i] = [points[i][0], points[i][1]];
\r
342 for (j = 1; j < n; ++j) {
\r
343 for (i = 0; i < n - j; ++i) {
\r
344 tmp[i][0] = c * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
\r
345 tmp[i][1] = c * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
\r
349 return [ tmp[0][0], tmp[0][1] ];
\r
356 easeNone: function (t, b, c, d) {
\r
357 return c * t / d + b;
\r
361 easeIn: function (t, b, c, d) {
\r
362 return c * (t /= d) * t + b;
\r
366 easeOut: function (t, b, c, d) {
\r
367 return -c * (t /= d) * (t - 2) + b;
\r
372 EXTLIB.Motion = function(el, attributes, duration, method) {
\r
374 EXTLIB.Motion.superclass.constructor.call(this, el, attributes, duration, method);
\r
378 Ext.extend(EXTLIB.Motion, Ext.lib.AnimBase);
\r
380 var superclass = EXTLIB.Motion.superclass,
\r
381 proto = EXTLIB.Motion.prototype,
\r
382 pointsRe = /^points$/i;
\r
384 Ext.apply(EXTLIB.Motion.prototype, {
\r
385 setAttr: function(attr, val, unit){
\r
387 setAttr = superclass.setAttr;
\r
389 if (pointsRe.test(attr)) {
\r
390 unit = unit || 'px';
\r
391 setAttr.call(me, 'left', val[0], unit);
\r
392 setAttr.call(me, 'top', val[1], unit);
\r
394 setAttr.call(me, attr, val, unit);
\r
398 getAttr: function(attr){
\r
400 getAttr = superclass.getAttr;
\r
402 return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr);
\r
405 doMethod: function(attr, start, end){
\r
408 return pointsRe.test(attr)
\r
409 ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100)
\r
410 : superclass.doMethod.call(me, attr, start, end);
\r
413 setRunAttr: function(attr){
\r
414 if(pointsRe.test(attr)){
\r
418 points = this.attributes.points,
\r
419 control = points.control || [],
\r
420 from = points.from,
\r
431 if(control.length > 0 && !Ext.isArray(control[0])){
\r
432 control = [control];
\r
436 for (i = 0,len = control.length; i < len; ++i) {
\r
437 tmp[i] = control[i];
\r
443 Ext.fly(el, '_anim').position();
\r
444 DOM.setXY(el, isset(from) ? from : DOM.getXY(el));
\r
445 start = me.getAttr('points');
\r
449 end = translateValues.call(me, to, start);
\r
450 for (i = 0,len = control.length; i < len; ++i) {
\r
451 control[i] = translateValues.call(me, control[i], start);
\r
453 } else if (isset(by)) {
\r
454 end = [start[0] + by[0], start[1] + by[1]];
\r
456 for (i = 0,len = control.length; i < len; ++i) {
\r
457 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
\r
461 ra = this.runAttrs[attr] = [start];
\r
462 if (control.length > 0) {
\r
463 ra = ra.concat(control);
\r
466 ra[ra.length] = end;
\r
468 superclass.setRunAttr.call(this, attr);
\r
473 var translateValues = function(val, start) {
\r
474 var pageXY = EXTLIB.Dom.getXY(this.el);
\r
475 return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]];
\r