Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / src / core / CompositeElementLite-more.js
1 /*!
2  * Ext JS Library 3.0.0
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.CompositeElementLite\r
9  */\r
10 Ext.apply(Ext.CompositeElementLite.prototype, { \r
11         addElements : function(els, root){\r
12         if(!els){\r
13             return this;\r
14         }\r
15         if(typeof els == "string"){\r
16             els = Ext.Element.selectorFunction(els, root);\r
17         }\r
18         var yels = this.elements;        \r
19             Ext.each(els, function(e) {\r
20                 yels.push(Ext.get(e));\r
21         });\r
22         return this;\r
23     },\r
24     \r
25     /**\r
26     * Clears this composite and adds the elements returned by the passed selector.\r
27     * @param {String/Array} els A string CSS selector, an array of elements or an element\r
28     * @return {CompositeElement} this\r
29     */\r
30     fill : function(els){\r
31         this.elements = [];\r
32         this.add(els);\r
33         return this;\r
34     },\r
35     \r
36     /**\r
37      * Returns the first Element\r
38      * @return {Ext.Element}\r
39      */\r
40     first : function(){\r
41         return this.item(0);\r
42     },   \r
43     \r
44     /**\r
45      * Returns the last Element\r
46      * @return {Ext.Element}\r
47      */\r
48     last : function(){\r
49         return this.item(this.getCount()-1);\r
50     },\r
51     \r
52     /**\r
53      * Returns true if this composite contains the passed element\r
54      * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.\r
55      * @return Boolean\r
56      */\r
57     contains : function(el){\r
58         return this.indexOf(el) != -1;\r
59     },\r
60 \r
61     /**\r
62     * Filters this composite to only elements that match the passed selector.\r
63     * @param {String} selector A string CSS selector\r
64     * @return {CompositeElement} this\r
65     */\r
66     filter : function(selector){\r
67         var els = [];\r
68         this.each(function(el){\r
69             if(el.is(selector)){\r
70                 els[els.length] = el.dom;\r
71             }\r
72         });\r
73         this.fill(els);\r
74         return this;\r
75     },
76     
77     /**\r
78     * Removes the specified element(s).\r
79     * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite\r
80     * or an array of any of those.\r
81     * @param {Boolean} removeDom (optional) True to also remove the element from the document\r
82     * @return {CompositeElement} this\r
83     */\r
84     removeElement : function(keys, removeDom){\r
85         var me = this,\r
86                 els = this.elements,        \r
87                 el;             \r
88             Ext.each(keys, function(val){\r
89                     if ((el = (els[val] || els[val = me.indexOf(val)]))) {\r
90                         if(removeDom){\r
91                     if(el.dom){\r
92                         el.remove();\r
93                     }else{\r
94                         Ext.removeNode(el);\r
95                     }\r
96                 }\r
97                         els.splice(val, 1);                     \r
98                         }\r
99             });\r
100         return this;\r
101     }    \r
102 });