Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / core / src / dom / CompositeElementLite-more.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.CompositeElementLite
17  */
18 Ext.apply(Ext.CompositeElementLite.prototype, {
19     addElements : function(els, root){
20         if(!els){
21             return this;
22         }
23         if(typeof els == "string"){
24             els = Ext.Element.selectorFunction(els, root);
25         }
26         var yels = this.elements;
27         Ext.each(els, function(e) {
28             yels.push(Ext.get(e));
29         });
30         return this;
31     },
32
33     /**
34      * Returns the first Element
35      * @return {Ext.Element}
36      */
37     first : function(){
38         return this.item(0);
39     },
40
41     /**
42      * Returns the last Element
43      * @return {Ext.Element}
44      */
45     last : function(){
46         return this.item(this.getCount()-1);
47     },
48
49     /**
50      * Returns true if this composite contains the passed element
51      * @param el {String/HTMLElement/Ext.Element/Number} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
52      * @return Boolean
53      */
54     contains : function(el){
55         return this.indexOf(el) != -1;
56     },
57
58     /**
59     * Removes the specified element(s).
60     * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the element in this composite
61     * or an array of any of those.
62     * @param {Boolean} removeDom (optional) True to also remove the element from the document
63     * @return {Ext.CompositeElement} this
64     */
65     removeElement : function(keys, removeDom){
66         var me = this,
67             els = this.elements,
68             el;
69         Ext.each(keys, function(val){
70             if ((el = (els[val] || els[val = me.indexOf(val)]))) {
71                 if(removeDom){
72                     if(el.dom){
73                         el.remove();
74                     }else{
75                         Ext.removeNode(el);
76                     }
77                 }
78                 Ext.Array.erase(els, val, 1);
79             }
80         });
81         return this;
82     }
83 });
84