~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/core/CompositeElement.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 3.0 RC2
 
3
 * Copyright(c) 2006-2009, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.CompositeElement
 
11
 * @extends Ext.CompositeElementLite
 
12
 * Standard composite class. Creates a Ext.Element for every element in the collection.
 
13
 * <br><br>
 
14
 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Ext.Element. All Ext.Element
 
15
 * actions will be performed on all the elements in this collection.</b>
 
16
 * <br><br>
 
17
 * All methods return <i>this</i> and can be chained.
 
18
 <pre><code>
 
19
 var els = Ext.select("#some-el div.some-class", true);
 
20
 // or select directly from an existing element
 
21
 var el = Ext.get('some-el');
 
22
 el.select('div.some-class', true);
 
23
 
 
24
 els.setWidth(100); // all elements become 100 width
 
25
 els.hide(true); // all elements fade out and hide
 
26
 // or
 
27
 els.setWidth(100).hide(true);
 
28
 </code></pre>
 
29
 */
 
30
Ext.CompositeElement = function(els, root){
 
31
    this.elements = [];
 
32
    this.add(els, root);
 
33
};
 
34
 
 
35
Ext.extend(Ext.CompositeElement, Ext.CompositeElementLite, {
 
36
    invoke : function(fn, args){
 
37
            Ext.each(this.elements, function(e) {
 
38
                Ext.Element.prototype[fn].apply(e, args);
 
39
        });
 
40
        return this;
 
41
    },
 
42
    
 
43
    /**
 
44
    * Adds elements to this composite.
 
45
    * @param {String/Array} els A string CSS selector, an array of elements or an element
 
46
    * @return {CompositeElement} this
 
47
    */
 
48
    add : function(els, root){
 
49
            if(!els) return this;
 
50
        if(typeof els == "string"){
 
51
            els = Ext.Element.selectorFunction(els, root);
 
52
        }
 
53
        var yels = this.elements;        
 
54
            Ext.each(els, function(e) {
 
55
                yels.push(Ext.get(e));
 
56
        });
 
57
        return this;
 
58
    },    
 
59
    
 
60
    /**
 
61
     * Returns the Element object at the specified index
 
62
     * @param {Number} index
 
63
     * @return {Ext.Element}
 
64
     */
 
65
    item : function(index){
 
66
        return this.elements[index] || null;
 
67
    },
 
68
 
 
69
 
 
70
    indexOf : function(el){
 
71
        return this.elements.indexOf(Ext.get(el));
 
72
    },
 
73
        
 
74
    filter : function(selector){
 
75
                var me = this,
 
76
                        out = [];
 
77
                        
 
78
                Ext.each(me.elements, function(el) {    
 
79
                        if(el.is(selector)){
 
80
                                out.push(Ext.get(el));
 
81
                        }
 
82
                })
 
83
                me.elements = out;
 
84
                return me;
 
85
        },
 
86
        
 
87
        /**
 
88
    * Calls the passed function passing (el, this, index) for each element in this composite.
 
89
    * @param {Function} fn The function to call
 
90
    * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
 
91
    * @return {CompositeElement} this
 
92
    */
 
93
    each : function(fn, scope){        
 
94
        Ext.each(this.elements, function(e,i) {
 
95
                return fn.call(scope || e, e, this, i)
 
96
        }, this);
 
97
        return this;
 
98
    }
 
99
});
 
100
 
 
101
/**
 
102
 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
 
103
 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
 
104
 * {@link Ext.CompositeElementLite CompositeElementLite} object.
 
105
 * @param {String/Array} selector The CSS selector or an array of elements
 
106
 * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
 
107
 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
 
108
 * @return {CompositeElementLite/CompositeElement}
 
109
 * @member Ext.Element
 
110
 * @method select
 
111
 */
 
112
Ext.Element.select = function(selector, unique, root){
 
113
    var els;
 
114
    if(typeof selector == "string"){
 
115
        els = Ext.Element.selectorFunction(selector, root);
 
116
    }else if(selector.length !== undefined){
 
117
        els = selector;
 
118
    }else{
 
119
        throw "Invalid selector";
 
120
    }
 
121
 
 
122
    return (unique === true) ? new Ext.CompositeElement(els) : new Ext.CompositeElementLite(els);
 
123
};
 
124
 
 
125
/**
 
126
 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
 
127
 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
 
128
 * {@link Ext.CompositeElementLite CompositeElementLite} object.
 
129
 * @param {String/Array} selector The CSS selector or an array of elements
 
130
 * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
 
131
 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
 
132
 * @return {CompositeElementLite/CompositeElement}
 
133
 * @member Ext.Element
 
134
 * @method select
 
135
 */
 
136
Ext.select = Ext.Element.select;
 
 
b'\\ No newline at end of file'