3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.CompositeElement
17 * @extends Ext.CompositeElementLite
18 * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
19 * members, or to perform collective actions upon the whole set.</p>
20 * <p>Although they are not listed, this class supports all of the methods of {@link Ext.core.Element} and
21 * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.</p>
22 * <p>All methods return <i>this</i> and can be chained.</p>
25 var els = Ext.select("#some-el div.some-class", true);
26 // or select directly from an existing element
27 var el = Ext.get('some-el');
28 el.select('div.some-class', true);
30 els.setWidth(100); // all elements become 100 width
31 els.hide(true); // all elements fade out and hide
33 els.setWidth(100).hide(true);
36 Ext.CompositeElement = Ext.extend(Ext.CompositeElementLite, {
38 constructor : function(els, root){
44 getElement : function(el){
45 // In this case just return it, since we already have a reference to it
50 transformElement : function(el){
55 * Adds elements to this composite.
56 * @param {String/Array} els A string CSS selector, an array of elements or an element
57 * @return {CompositeElement} this
61 * Returns the Element object at the specified index
62 * @param {Number} index
63 * @return {Ext.core.Element}
67 * Iterates each `element` in this `composite` calling the supplied function using {@link Ext#each Ext.each}.
68 * @param {Function} fn
70 The function to be called with each
71 `element`. If the supplied function returns <tt>false</tt>,
72 iteration stops. This function is called with the following arguments:
74 - `element` : __Ext.core.Element++
75 The element at the current `index` in the `composite`
77 - `composite` : __Object__
80 - `index` : __Number__
81 The current index within the `composite`
83 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed.
84 * Defaults to the <code>element</code> at the current <code>index</code>
85 * within the composite.
86 * @return {CompositeElement} this
92 * Selects elements based on the passed CSS selector to enable {@link Ext.core.Element Element} methods
93 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
94 * {@link Ext.CompositeElementLite CompositeElementLite} object.
95 * @param {String/Array} selector The CSS selector or an array of elements
96 * @param {Boolean} unique (optional) true to create a unique Ext.core.Element for each element (defaults to a shared flyweight object)
97 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
98 * @return {CompositeElementLite/CompositeElement}
99 * @member Ext.core.Element
102 Ext.core.Element.select = function(selector, unique, root){
104 if(typeof selector == "string"){
105 els = Ext.core.Element.selectorFunction(selector, root);
106 }else if(selector.length !== undefined){
111 sourceClass: "Ext.core.Element",
112 sourceMethod: "select",
116 msg: "Invalid selector specified: " + selector
120 return (unique === true) ? new Ext.CompositeElement(els) : new Ext.CompositeElementLite(els);
124 * Selects elements based on the passed CSS selector to enable {@link Ext.core.Element Element} methods
125 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
126 * {@link Ext.CompositeElementLite CompositeElementLite} object.
127 * @param {String/Array} selector The CSS selector or an array of elements
128 * @param {Boolean} unique (optional) true to create a unique Ext.core.Element for each element (defaults to a shared flyweight object)
129 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
130 * @return {CompositeElementLite/CompositeElement}
134 Ext.select = Ext.core.Element.select;