]> git.proxmox.com Git - extjs.git/blob - extjs/packages/core/src/dom/UnderlayPool.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / src / dom / UnderlayPool.js
1 /**
2 * Private utility class that manages the internal cache for {@link Ext.dom.Shadow Underlays}
3 * and {@link Ext.dom.Shim Shims}.
4 * @private
5 */
6 Ext.define('Ext.dom.UnderlayPool', {
7
8 /**
9 * @constructor
10 * @param {Object} elementConfig A {@link Ext.dom.Helper DomHelper} config object to
11 * use for generating elements in the pool.
12 */
13 constructor: function(elementConfig) {
14 this.elementConfig = elementConfig;
15 this.cache = [];
16 },
17
18 /**
19 * Checks an element out of the pool.
20 * @return {Ext.dom.Element}
21 */
22 checkOut: function() {
23 var el = this.cache.shift();
24
25 if (!el) {
26 el = Ext.Element.create(this.elementConfig);
27 el.setVisibilityMode(2);
28 //<debug>
29 // tell the spec runner to ignore this element when checking if the dom is clean
30 el.dom.setAttribute('data-sticky', true);
31 //</debug>
32 }
33
34 return el;
35 },
36
37 /**
38 * Checks an element back into the pool for future reuse
39 * @param {Ext.dom.Element} el
40 */
41 checkIn: function(el) {
42 this.cache.push(el);
43 },
44
45 /**
46 * Reset the pool by emptying the cache and destroying all its elements
47 */
48 reset: function() {
49 var cache = this.cache,
50 i = cache.length;
51
52 while (i--) {
53 cache[i].destroy();
54 }
55
56 this.cache = [];
57 }
58 });