Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / core / src / dom / CompositeElementLite-more.js
1 /**
2  * @class Ext.CompositeElementLite
3  */
4 Ext.apply(Ext.CompositeElementLite.prototype, {
5     addElements : function(els, root){
6         if(!els){
7             return this;
8         }
9         if(typeof els == "string"){
10             els = Ext.core.Element.selectorFunction(els, root);
11         }
12         var yels = this.elements;
13         Ext.each(els, function(e) {
14             yels.push(Ext.get(e));
15         });
16         return this;
17     },
18
19     /**
20      * Returns the first Element
21      * @return {Ext.core.Element}
22      */
23     first : function(){
24         return this.item(0);
25     },
26
27     /**
28      * Returns the last Element
29      * @return {Ext.core.Element}
30      */
31     last : function(){
32         return this.item(this.getCount()-1);
33     },
34
35     /**
36      * Returns true if this composite contains the passed element
37      * @param el {Mixed} The id of an element, or an Ext.core.Element, or an HtmlElement to find within the composite collection.
38      * @return Boolean
39      */
40     contains : function(el){
41         return this.indexOf(el) != -1;
42     },
43
44     /**
45     * Removes the specified element(s).
46     * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
47     * or an array of any of those.
48     * @param {Boolean} removeDom (optional) True to also remove the element from the document
49     * @return {CompositeElement} this
50     */
51     removeElement : function(keys, removeDom){
52         var me = this,
53             els = this.elements,
54             el;
55         Ext.each(keys, function(val){
56             if ((el = (els[val] || els[val = me.indexOf(val)]))) {
57                 if(removeDom){
58                     if(el.dom){
59                         el.remove();
60                     }else{
61                         Ext.removeNode(el);
62                     }
63                 }
64                 els.splice(val, 1);
65             }
66         });
67         return this;
68     }
69 });