Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / core / CompositeElementLite-more.js
1 /*!
2  * Ext JS Library 3.1.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      * Returns the first Element\r
27      * @return {Ext.Element}\r
28      */\r
29     first : function(){\r
30         return this.item(0);\r
31     },   \r
32     \r
33     /**\r
34      * Returns the last Element\r
35      * @return {Ext.Element}\r
36      */\r
37     last : function(){\r
38         return this.item(this.getCount()-1);\r
39     },\r
40     \r
41     /**\r
42      * Returns true if this composite contains the passed element\r
43      * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.\r
44      * @return Boolean\r
45      */\r
46     contains : function(el){\r
47         return this.indexOf(el) != -1;\r
48     },
49     
50     /**\r
51     * Removes the specified element(s).\r
52     * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite\r
53     * or an array of any of those.\r
54     * @param {Boolean} removeDom (optional) True to also remove the element from the document\r
55     * @return {CompositeElement} this\r
56     */\r
57     removeElement : function(keys, removeDom){\r
58         var me = this,\r
59                 els = this.elements,        \r
60                 el;             \r
61             Ext.each(keys, function(val){\r
62                     if ((el = (els[val] || els[val = me.indexOf(val)]))) {\r
63                         if(removeDom){\r
64                     if(el.dom){\r
65                         el.remove();\r
66                     }else{\r
67                         Ext.removeNode(el);\r
68                     }\r
69                 }\r
70                         els.splice(val, 1);                     \r
71                         }\r
72             });\r
73         return this;\r
74     }    \r
75 });