Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / Queue.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-fx-Queue'>/**
19 </span> * @class Ext.fx.Queue
20  * Animation Queue mixin to handle chaining and queueing by target.
21  * @private
22  */
23
24 Ext.define('Ext.fx.Queue', {
25
26     requires: ['Ext.util.HashMap'],
27
28     constructor: function() {
29         this.targets = Ext.create('Ext.util.HashMap');
30         this.fxQueue = {};
31     },
32
33     // @private
34     getFxDefaults: function(targetId) {
35         var target = this.targets.get(targetId);
36         if (target) {
37             return target.fxDefaults;
38         }
39         return {};
40     },
41
42     // @private
43     setFxDefaults: function(targetId, obj) {
44         var target = this.targets.get(targetId);
45         if (target) {
46             target.fxDefaults = Ext.apply(target.fxDefaults || {}, obj);
47         }
48     },
49
50     // @private
51     stopAnimation: function(targetId) {
52         var me = this,
53             queue = me.getFxQueue(targetId),
54             ln = queue.length;
55         while (ln) {
56             queue[ln - 1].end();
57             ln--;
58         }
59     },
60
61 <span id='Ext-fx-Queue-method-getActiveAnimation'>    /**
62 </span>     * @private
63      * Returns current animation object if the element has any effects actively running or queued, else returns false.
64      */
65     getActiveAnimation: function(targetId) {
66         var queue = this.getFxQueue(targetId);
67         return (queue &amp;&amp; !!queue.length) ? queue[0] : false;
68     },
69
70     // @private
71     hasFxBlock: function(targetId) {
72         var queue = this.getFxQueue(targetId);
73         return queue &amp;&amp; queue[0] &amp;&amp; queue[0].block;
74     },
75
76     // @private get fx queue for passed target, create if needed.
77     getFxQueue: function(targetId) {
78         if (!targetId) {
79             return false;
80         }
81         var me = this,
82             queue = me.fxQueue[targetId],
83             target = me.targets.get(targetId);
84
85         if (!target) {
86             return false;
87         }
88
89         if (!queue) {
90             me.fxQueue[targetId] = [];
91             // GarbageCollector will need to clean up Elements since they aren't currently observable
92             if (target.type != 'element') {
93                 target.target.on('destroy', function() {
94                     me.fxQueue[targetId] = [];
95                 });
96             }
97         }
98         return me.fxQueue[targetId];
99     },
100
101     // @private
102     queueFx: function(anim) {
103         var me = this,
104             target = anim.target,
105             queue, ln;
106
107         if (!target) {
108             return;
109         }
110
111         queue = me.getFxQueue(target.getId());
112         ln = queue.length;
113
114         if (ln) {
115             if (anim.concurrent) {
116                 anim.paused = false;
117             }
118             else {
119                 queue[ln - 1].on('afteranimate', function() {
120                     anim.paused = false;
121                 });
122             }
123         }
124         else {
125             anim.paused = false;
126         }
127         anim.on('afteranimate', function() {
128             Ext.Array.remove(queue, anim);
129             if (anim.remove) {
130                 if (target.type == 'element') {
131                     var el = Ext.get(target.id);
132                     if (el) {
133                         el.remove();
134                     }
135                 }
136             }
137         }, this);
138         queue.push(anim);
139     }
140 });</pre>
141 </body>
142 </html>