3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
17 noNegatives = /width|height|opacity|padding/i,
18 offsetAttribute = /^((width|height)|(top|left))$/,
19 defaultUnit = /width|height|top$|bottom$|left$|right$/i,
20 offsetUnit = /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i,
22 return typeof v !== 'undefined';
29 motion : function(el, args, duration, easing, cb, scope) {
30 return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
33 run : function(el, args, duration, easing, cb, scope, type) {
34 type = type || Ext.lib.AnimBase;
35 if (typeof easing == "string") {
36 easing = Ext.lib.Easing[easing];
38 var anim = new type(el, args, duration, easing);
39 anim.animateX(function() {
40 if(Ext.isFunction(cb)){
48 EXTLIB.AnimBase = function(el, attributes, duration, method) {
50 this.init(el, attributes, duration, method);
54 EXTLIB.AnimBase.prototype = {
55 doMethod: function(attr, start, end) {
57 return me.method(me.curFrame, start, end - start, me.totalFrames);
61 setAttr: function(attr, val, unit) {
62 if (noNegatives.test(attr) && val < 0) {
65 Ext.fly(this.el, '_anim').setStyle(attr, val + unit);
69 getAttr: function(attr) {
70 var el = Ext.fly(this.el),
71 val = el.getStyle(attr),
72 a = offsetAttribute.exec(attr) || [];
74 if (val !== 'auto' && !offsetUnit.test(val)) {
75 return parseFloat(val);
78 return (!!(a[2]) || (el.getStyle('position') == 'absolute' && !!(a[3]))) ? el.dom['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)] : 0;
82 getDefaultUnit: function(attr) {
83 return defaultUnit.test(attr) ? 'px' : '';
86 animateX : function(callback, scope) {
89 me.onComplete.removeListener(f);
90 if (Ext.isFunction(callback)) {
91 callback.call(scope || me, me);
94 me.onComplete.addListener(f, me);
99 setRunAttr: function(attr) {
101 a = this.attributes[attr],
106 ra = (this.runAttrs[attr] = {}),
109 if (!isset(to) && !isset(by)){
113 var start = isset(from) ? from : me.getAttr(attr);
116 }else if(isset(by)) {
117 if (Ext.isArray(start)){
119 for(var i=0,len=start.length; i<len; i++) {
120 end[i] = start[i] + by[i];
130 unit: isset(unit) ? unit : me.getDefaultUnit(attr)
135 init: function(el, attributes, duration, method) {
138 mgr = EXTLIB.AnimMgr;
144 attributes: attributes || {},
145 duration: duration || 1,
146 method: method || EXTLIB.Easing.easeNone,
149 totalFrames: mgr.fps,
160 me.totalFrames = me.useSec ? Math.ceil(mgr.fps * d) : d;
161 mgr.registerElement(me);
164 stop: function(finish){
168 me.curFrame = me.totalFrames;
175 var onStart = function(){
181 for(attr in this.attributes){
182 this.setRunAttr(attr);
185 me.isAnimated = true;
186 me.startTime = now();
191 var onTween = function(){
195 duration: now() - me.startTime,
196 curFrame: me.curFrame
199 var ra = me.runAttrs;
200 for (var attr in ra) {
201 this.setAttr(attr, me.doMethod(attr, ra[attr].start, ra[attr].end), ra[attr].unit);
207 var onComplete = function() {
209 actual = (now() - me.startTime) / 1000,
212 frames: actualFrames,
213 fps: actualFrames / actual
216 me.isAnimated = false;
218 me.onComplete.fire(data);
221 me.onStart = new Ext.util.Event(me);
222 me.onTween = new Ext.util.Event(me);
223 me.onComplete = new Ext.util.Event(me);
224 (me._onStart = new Ext.util.Event(me)).addListener(onStart);
225 (me._onTween = new Ext.util.Event(me)).addListener(onTween);
226 (me._onComplete = new Ext.util.Event(me)).addListener(onComplete);
231 Ext.lib.AnimMgr = new function() {
241 registerElement: function(tween){
244 tween._onStart.fire();
248 unRegister: function(tween, index){
249 tween._onComplete.fire();
250 index = index || getIndex(tween);
252 queue.splice(index, 1);
255 if (--tweenCount <= 0) {
262 thread = setInterval(me.run, me.delay);
266 stop: function(tween){
268 clearInterval(thread);
269 for(var i = 0, len = queue.length; i < len; ++i){
270 if(queue[0].isAnimated){
271 me.unRegister(queue[0], 0);
279 me.unRegister(tween);
284 var tf, i, len, tween;
285 for(i = 0, len = queue.length; i<len; i++) {
287 if(tween && tween.isAnimated){
288 tf = tween.totalFrames;
289 if(tween.curFrame < tf || tf === null){
294 tween._onTween.fire();
303 var getIndex = function(anim) {
305 for(i = 0, len = queue.length; i<len; i++) {
306 if(queue[i] === anim) {
313 var correctFrame = function(tween) {
314 var frames = tween.totalFrames,
315 frame = tween.curFrame,
316 duration = tween.duration,
317 expected = (frame * duration * 1000 / frames),
318 elapsed = (now() - tween.startTime),
321 if(elapsed < duration * 1000){
322 tweak = Math.round((elapsed / expected - 1) * frame);
324 tweak = frames - (frame + 1);
326 if(tweak > 0 && isFinite(tweak)){
327 if(tween.curFrame + tweak >= frames){
328 tweak = frames - (frame + 1);
330 tween.curFrame += tweak;
335 EXTLIB.Bezier = new function() {
337 this.getPosition = function(points, t) {
338 var n = points.length,
344 for (i = 0; i < n; ++i) {
345 tmp[i] = [points[i][0], points[i][1]];
348 for (j = 1; j < n; ++j) {
349 for (i = 0; i < n - j; ++i) {
350 tmp[i][0] = c * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
351 tmp[i][1] = c * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
355 return [ tmp[0][0], tmp[0][1] ];
362 easeNone: function (t, b, c, d) {
363 return c * t / d + b;
367 easeIn: function (t, b, c, d) {
368 return c * (t /= d) * t + b;
372 easeOut: function (t, b, c, d) {
373 return -c * (t /= d) * (t - 2) + b;
378 EXTLIB.Motion = function(el, attributes, duration, method) {
380 EXTLIB.Motion.superclass.constructor.call(this, el, attributes, duration, method);
384 Ext.extend(EXTLIB.Motion, Ext.lib.AnimBase);
386 var superclass = EXTLIB.Motion.superclass,
387 proto = EXTLIB.Motion.prototype,
388 pointsRe = /^points$/i;
390 Ext.apply(EXTLIB.Motion.prototype, {
391 setAttr: function(attr, val, unit){
393 setAttr = superclass.setAttr;
395 if (pointsRe.test(attr)) {
397 setAttr.call(me, 'left', val[0], unit);
398 setAttr.call(me, 'top', val[1], unit);
400 setAttr.call(me, attr, val, unit);
404 getAttr: function(attr){
406 getAttr = superclass.getAttr;
408 return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr);
411 doMethod: function(attr, start, end){
414 return pointsRe.test(attr)
415 ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100)
416 : superclass.doMethod.call(me, attr, start, end);
419 setRunAttr: function(attr){
420 if(pointsRe.test(attr)){
424 points = this.attributes.points,
425 control = points.control || [],
437 if(control.length > 0 && !Ext.isArray(control[0])){
442 for (i = 0,len = control.length; i < len; ++i) {
449 Ext.fly(el, '_anim').position();
450 DOM.setXY(el, isset(from) ? from : DOM.getXY(el));
451 start = me.getAttr('points');
455 end = translateValues.call(me, to, start);
456 for (i = 0,len = control.length; i < len; ++i) {
457 control[i] = translateValues.call(me, control[i], start);
459 } else if (isset(by)) {
460 end = [start[0] + by[0], start[1] + by[1]];
462 for (i = 0,len = control.length; i < len; ++i) {
463 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
467 ra = this.runAttrs[attr] = [start];
468 if (control.length > 0) {
469 ra = ra.concat(control);
474 superclass.setRunAttr.call(this, attr);
479 var translateValues = function(val, start) {
480 var pageXY = EXTLIB.Dom.getXY(this.el);
481 return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]];