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.CompositeElement |
---|
9 | * @extends Ext.CompositeElementLite |
---|
10 | * Standard composite class. Creates a Ext.Element for every element in the collection. |
---|
11 | * <br><br> |
---|
12 | * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Ext.Element. All Ext.Element |
---|
13 | * actions will be performed on all the elements in this collection.</b> |
---|
14 | * <br><br> |
---|
15 | * All methods return <i>this</i> and can be chained. |
---|
16 | <pre><code> |
---|
17 | var els = Ext.select("#some-el div.some-class", true); |
---|
18 | // or select directly from an existing element |
---|
19 | var el = Ext.get('some-el'); |
---|
20 | el.select('div.some-class', true); |
---|
21 | |
---|
22 | els.setWidth(100); // all elements become 100 width |
---|
23 | els.hide(true); // all elements fade out and hide |
---|
24 | // or |
---|
25 | els.setWidth(100).hide(true); |
---|
26 | </code></pre> |
---|
27 | */ |
---|
28 | Ext.CompositeElement = function(els, root){ |
---|
29 | this.elements = []; |
---|
30 | this.add(els, root); |
---|
31 | }; |
---|
32 | |
---|
33 | Ext.extend(Ext.CompositeElement, Ext.CompositeElementLite, { |
---|
34 | invoke : function(fn, args){ |
---|
35 | Ext.each(this.elements, function(e) { |
---|
36 | Ext.Element.prototype[fn].apply(e, args); |
---|
37 | }); |
---|
38 | return this; |
---|
39 | }, |
---|
40 | |
---|
41 | /** |
---|
42 | * Adds elements to this composite. |
---|
43 | * @param {String/Array} els A string CSS selector, an array of elements or an element |
---|
44 | * @return {CompositeElement} this |
---|
45 | */ |
---|
46 | add : function(els, root){ |
---|
47 | if(!els){ |
---|
48 | return this; |
---|
49 | } |
---|
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; |
---|