3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.CompositeElementLite"></div>/**
16 * @class Ext.CompositeElementLite
17 * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
18 * members, or to perform collective actions upon the whole set.</p>
19 * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
20 * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>
22 var els = Ext.select("#some-el div.some-class");
23 // or select directly from an existing element
24 var el = Ext.get('some-el');
25 el.select('div.some-class');
27 els.setWidth(100); // all elements become 100 width
28 els.hide(true); // all elements fade out and hide
30 els.setWidth(100).hide(true);
33 Ext.CompositeElementLite = function(els, root){
34 <div id="prop-Ext.CompositeElementLite-elements"></div>/**
35 * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>
36 * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing
37 * to augment the capabilities of the CompositeElementLite class may use it when adding
38 * methods to the class.</p>
39 * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all
40 * following siblings of selected elements, the code would be</p><code><pre>
41 Ext.override(Ext.CompositeElementLite, {
43 var els = this.elements, i, l = els.length, n, r = [], ri = -1;
45 // Loop through all elements in this Composite, accumulating
46 // an Array of all siblings.
47 for (i = 0; i < l; i++) {
48 for (n = els[i].nextSibling; n; n = n.nextSibling) {
53 // Add all found siblings to this Composite
62 this.el = new Ext.Element.Flyweight();
65 Ext.CompositeElementLite.prototype = {
69 getElement : function(el){
70 // Set the shared flyweight dom property to the current element
78 transformElement : function(el){
79 return Ext.getDom(el);
82 <div id="method-Ext.CompositeElementLite-getCount"></div>/**
83 * Returns the number of elements in this Composite.
86 getCount : function(){
87 return this.elements.length;
89 <div id="method-Ext.CompositeElementLite-add"></div>/**
90 * Adds elements to this Composite object.
91 * @param {Mixed} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
92 * @return {CompositeElement} This Composite object.
94 add : function(els, root){
96 elements = me.elements;
100 if(Ext.isString(els)){
101 els = Ext.Element.selectorFunction(els, root);
102 }else if(els.isComposite){
104 }else if(!Ext.isIterable(els)){
108 for(var i = 0, len = els.length; i < len; ++i){
109 elements.push(me.transformElement(els[i]));
114 invoke : function(fn, args){
121 for(i = 0; i < len; i++) {
124 Ext.Element.prototype[fn].apply(me.getElement(e), args);
129 <div id="method-Ext.CompositeElementLite-item"></div>/**
130 * Returns a flyweight Element of the dom element object at the specified index
131 * @param {Number} index
132 * @return {Ext.Element}
134 item : function(index){
136 el = me.elements[index],
140 out = me.getElement(el);
145 // fixes scope with flyweight
146 addListener : function(eventName, handler, scope, opt){
147 var els = this.elements,
151 for(i = 0; i<len; i++) {
154 Ext.EventManager.on(e, eventName, handler, scope || e, opt);
159 <div id="method-Ext.CompositeElementLite-each"></div>/**
160 * <p>Calls the passed function for each element in this composite.</p>
161 * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
162 * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
163 * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
164 * a reference to the dom node, use el.dom.</b></div></li>
165 * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
166 * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
168 * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
169 * @return {CompositeElement} this
171 each : function(fn, scope){
177 for(i = 0; i<len; i++) {
180 e = this.getElement(e);
181 if(fn.call(scope || e, e, me, i) === false){
189 <div id="method-Ext.CompositeElementLite-fill"></div>/**
190 * Clears this Composite and adds the elements passed.
191 * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.
192 * @return {CompositeElement} this
194 fill : function(els){
201 <div id="method-Ext.CompositeElementLite-filter"></div>/**
202 * Filters this composite to only elements that match the passed selector.
203 * @param {String/Function} selector A string CSS selector or a comparison function.
204 * The comparison function will be called with the following arguments:<ul>
205 * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
206 * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
208 * @return {CompositeElement} this
210 filter : function(selector){
213 elements = me.elements,
214 fn = Ext.isFunction(selector) ? selector
216 return el.is(selector);
220 me.each(function(el, self, i){
221 if(fn(el, i) !== false){
222 els[els.length] = me.transformElement(el);
229 <div id="method-Ext.CompositeElementLite-indexOf"></div>/**
230 * Find the index of the passed element within the composite collection.
231 * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
232 * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
234 indexOf : function(el){
235 return this.elements.indexOf(this.transformElement(el));
238 <div id="method-Ext.CompositeElementLite-replaceElement"></div>/**
239 * Replaces the specified element with the passed element.
240 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
242 * @param {Mixed} replacement The id of an element or the Element itself.
243 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
244 * @return {CompositeElement} this
246 replaceElement : function(el, replacement, domReplace){
247 var index = !isNaN(el) ? el : this.indexOf(el),
250 replacement = Ext.getDom(replacement);
252 d = this.elements[index];
253 d.parentNode.insertBefore(replacement, d);
256 this.elements.splice(index, 1, replacement);
261 <div id="method-Ext.CompositeElementLite-clear"></div>/**
262 * Removes all elements.
269 Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
273 ElProto = Ext.Element.prototype,
274 CelProto = Ext.CompositeElementLite.prototype;
276 for(fnName in ElProto){
277 if(Ext.isFunction(ElProto[fnName])){
279 CelProto[fnName] = CelProto[fnName] || function(){
280 return this.invoke(fnName, arguments);
282 }).call(CelProto, fnName);
289 Ext.Element.selectorFunction = Ext.DomQuery.select;
292 <div id="method-Ext.Element-select"></div>/**
293 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
294 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
295 * {@link Ext.CompositeElementLite CompositeElementLite} object.
296 * @param {String/Array} selector The CSS selector or an array of elements
297 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
298 * @return {CompositeElementLite/CompositeElement}
299 * @member Ext.Element
302 Ext.Element.select = function(selector, root){
304 if(typeof selector == "string"){
305 els = Ext.Element.selectorFunction(selector, root);
306 }else if(selector.length !== undefined){
309 throw "Invalid selector";
311 return new Ext.CompositeElementLite(els);
313 <div id="method-Ext-select"></div>/**
314 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
315 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
316 * {@link Ext.CompositeElementLite CompositeElementLite} object.
317 * @param {String/Array} selector The CSS selector or an array of elements
318 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
319 * @return {CompositeElementLite/CompositeElement}
323 Ext.select = Ext.Element.select;</pre>