4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-CompositeElementLite'>/**
19 </span> * @class Ext.CompositeElementLite
20 * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
21 * members, or to perform collective actions upon the whole set.</p>
22 * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
23 * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.</p>
24 * Example:<pre><code>
25 var els = Ext.select("#some-el div.some-class");
26 // or select directly from an existing element
27 var el = Ext.get('some-el');
28 el.select('div.some-class');
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);
34 </code></pre>
36 Ext.CompositeElementLite = function(els, root){
37 <span id='Ext-CompositeElementLite-property-elements'> /**
38 </span> * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>
39 * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing
40 * to augment the capabilities of the CompositeElementLite class may use it when adding
41 * methods to the class.</p>
42 * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all
43 * following siblings of selected elements, the code would be</p><code><pre>
44 Ext.override(Ext.CompositeElementLite, {
46 var els = this.elements, i, l = els.length, n, r = [], ri = -1;
48 // Loop through all elements in this Composite, accumulating
49 // an Array of all siblings.
50 for (i = 0; i < l; i++) {
51 for (n = els[i].nextSibling; n; n = n.nextSibling) {
56 // Add all found siblings to this Composite
59 });</pre></code>
60 * @property {HTMLElement} elements
64 this.el = new Ext.Element.Flyweight();
67 Ext.CompositeElementLite.prototype = {
71 getElement : function(el){
72 // Set the shared flyweight dom property to the current element
80 transformElement : function(el){
81 return Ext.getDom(el);
84 <span id='Ext-CompositeElementLite-method-getCount'> /**
85 </span> * Returns the number of elements in this Composite.
88 getCount : function(){
89 return this.elements.length;
91 <span id='Ext-CompositeElementLite-method-add'> /**
92 </span> * Adds elements to this Composite object.
93 * @param {HTMLElement[]/Ext.CompositeElement} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
94 * @return {Ext.CompositeElement} This Composite object.
96 add : function(els, root){
98 elements = me.elements;
102 if(typeof els == "string"){
103 els = Ext.Element.selectorFunction(els, root);
104 }else if(els.isComposite){
106 }else if(!Ext.isIterable(els)){
110 for(var i = 0, len = els.length; i < len; ++i){
111 elements.push(me.transformElement(els[i]));
116 invoke : function(fn, args){
123 for(i = 0; i < len; i++) {
126 Ext.Element.prototype[fn].apply(me.getElement(e), args);
131 <span id='Ext-CompositeElementLite-method-item'> /**
132 </span> * Returns a flyweight Element of the dom element object at the specified index
133 * @param {Number} index
134 * @return {Ext.Element}
136 item : function(index){
138 el = me.elements[index],
142 out = me.getElement(el);
147 // fixes scope with flyweight
148 addListener : function(eventName, handler, scope, opt){
149 var els = this.elements,
153 for(i = 0; i<len; i++) {
156 Ext.EventManager.on(e, eventName, handler, scope || e, opt);
161 <span id='Ext-CompositeElementLite-method-each'> /**
162 </span> * <p>Calls the passed function for each element in this composite.</p>
163 * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
164 * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
165 * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
166 * a reference to the dom node, use el.dom.</b></div></li>
167 * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
168 * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
170 * @param {Object} [scope] The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
171 * @return {Ext.CompositeElement} this
173 each : function(fn, scope){
179 for(i = 0; i<len; i++) {
182 e = this.getElement(e);
183 if(fn.call(scope || e, e, me, i) === false){
191 <span id='Ext-CompositeElementLite-method-fill'> /**
192 </span> * Clears this Composite and adds the elements passed.
193 * @param {HTMLElement[]/Ext.CompositeElement} els Either an array of DOM elements, or another Composite from which to fill this Composite.
194 * @return {Ext.CompositeElement} this
196 fill : function(els){
203 <span id='Ext-CompositeElementLite-method-filter'> /**
204 </span> * Filters this composite to only elements that match the passed selector.
205 * @param {String/Function} selector A string CSS selector or a comparison function.
206 * The comparison function will be called with the following arguments:<ul>
207 * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
208 * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
210 * @return {Ext.CompositeElement} this
212 filter : function(selector){
215 fn = Ext.isFunction(selector) ? selector
217 return el.is(selector);
220 me.each(function(el, self, i) {
221 if (fn(el, i) !== false) {
222 els[els.length] = me.transformElement(el);
230 <span id='Ext-CompositeElementLite-method-indexOf'> /**
231 </span> * Find the index of the passed element within the composite collection.
232 * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
233 * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
235 indexOf : function(el){
236 return Ext.Array.indexOf(this.elements, this.transformElement(el));
239 <span id='Ext-CompositeElementLite-method-replaceElement'> /**
240 </span> * Replaces the specified element with the passed element.
241 * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the element in this composite
243 * @param {String/Ext.Element} replacement The id of an element or the Element itself.
244 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
245 * @return {Ext.CompositeElement} this
247 replaceElement : function(el, replacement, domReplace){
248 var index = !isNaN(el) ? el : this.indexOf(el),
251 replacement = Ext.getDom(replacement);
253 d = this.elements[index];
254 d.parentNode.insertBefore(replacement, d);
257 Ext.Array.splice(this.elements, index, 1, replacement);
262 <span id='Ext-CompositeElementLite-method-clear'> /**
263 </span> * Removes all elements.
270 Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
272 <span id='Ext-CompositeElementLite-method-importElementMethods'>/**
274 * Copies all of the functions from Ext.Element's prototype onto CompositeElementLite's prototype.
275 * This is called twice - once immediately below, and once again after additional Ext.Element
276 * are added in Ext JS
278 Ext.CompositeElementLite.importElementMethods = function() {
280 ElProto = Ext.Element.prototype,
281 CelProto = Ext.CompositeElementLite.prototype;
283 for (fnName in ElProto) {
284 if (typeof ElProto[fnName] == 'function'){
286 CelProto[fnName] = CelProto[fnName] || function() {
287 return this.invoke(fnName, arguments);
289 }).call(CelProto, fnName);
295 Ext.CompositeElementLite.importElementMethods();
298 Ext.Element.selectorFunction = Ext.DomQuery.select;
301 <span id='Ext-Element-method-select'>/**
302 </span> * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
303 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
304 * {@link Ext.CompositeElementLite CompositeElementLite} object.
305 * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
306 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
307 * @return {Ext.CompositeElementLite/Ext.CompositeElement}
308 * @member Ext.Element
311 Ext.Element.select = function(selector, root){
313 if(typeof selector == "string"){
314 els = Ext.Element.selectorFunction(selector, root);
315 }else if(selector.length !== undefined){
320 sourceClass: "Ext.Element",
321 sourceMethod: "select",
324 msg: "Invalid selector specified: " + selector
328 return new Ext.CompositeElementLite(els);
330 <span id='Ext-method-select'>/**
331 </span> * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
332 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
333 * {@link Ext.CompositeElementLite CompositeElementLite} object.
334 * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
335 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
336 * @return {Ext.CompositeElementLite/Ext.CompositeElement}
340 Ext.select = Ext.Element.select;