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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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 pointsRe = /^points$/i;
389 Ext.apply(EXTLIB.Motion.prototype, {
390 setAttr: function(attr, val, unit){
392 setAttr = superclass.setAttr;
394 if (pointsRe.test(attr)) {
396 setAttr.call(me, 'left', val[0], unit);
397 setAttr.call(me, 'top', val[1], unit);
399 setAttr.call(me, attr, val, unit);
403 getAttr: function(attr){
405 getAttr = superclass.getAttr;
407 return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr);
410 doMethod: function(attr, start, end){
413 return pointsRe.test(attr)
414 ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100)
415 : superclass.doMethod.call(me, attr, start, end);
418 setRunAttr: function(attr){
419 if(pointsRe.test(attr)){
423 points = this.attributes.points,
424 control = points.control || [],
436 if(control.length > 0 && !Ext.isArray(control[0])){
441 for (i = 0,len = control.length; i < len; ++i) {
448 Ext.fly(el, '_anim').position();
449 DOM.setXY(el, isset(from) ? from : DOM.getXY(el));
450 start = me.getAttr('points');
454 end = translateValues.call(me, to, start);
455 for (i = 0,len = control.length; i < len; ++i) {
456 control[i] = translateValues.call(me, control[i], start);
458 } else if (isset(by)) {
459 end = [start[0] + by[0], start[1] + by[1]];
461 for (i = 0,len = control.length; i < len; ++i) {
462 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
466 ra = this.runAttrs[attr] = [start];
467 if (control.length > 0) {
468 ra = ra.concat(control);
473 superclass.setRunAttr.call(this, attr);
478 var translateValues = function(val, start) {
479 var pageXY = EXTLIB.Dom.getXY(this.el);
480 return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]];