source: trunk/web/addons/job_monarch/lib/extjs-30/src/core/CompositeElementLite-more.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

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