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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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(typeof els == "string"){
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 fn = Ext.isFunction(selector) ? selector
215 return el.is(selector);
218 me.each(function(el, self, i) {
219 if (fn(el, i) !== false) {
220 els[els.length] = me.transformElement(el);
228 <div id="method-Ext.CompositeElementLite-indexOf"></div>/**
229 * Find the index of the passed element within the composite collection.
230 * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
231 * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
233 indexOf : function(el){
234 return this.elements.indexOf(this.transformElement(el));
237 <div id="method-Ext.CompositeElementLite-replaceElement"></div>/**
238 * Replaces the specified element with the passed element.
239 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
241 * @param {Mixed} replacement The id of an element or the Element itself.
242 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
243 * @return {CompositeElement} this
245 replaceElement : function(el, replacement, domReplace){
246 var index = !isNaN(el) ? el : this.indexOf(el),
249 replacement = Ext.getDom(replacement);
251 d = this.elements[index];
252 d.parentNode.insertBefore(replacement, d);
255 this.elements.splice(index, 1, replacement);
260 <div id="method-Ext.CompositeElementLite-clear"></div>/**
261 * Removes all elements.
268 Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
272 * Copies all of the functions from Ext.Element's prototype onto CompositeElementLite's prototype.
273 * This is called twice - once immediately below, and once again after additional Ext.Element
274 * are added in Ext JS
276 Ext.CompositeElementLite.importElementMethods = function() {
278 ElProto = Ext.Element.prototype,
279 CelProto = Ext.CompositeElementLite.prototype;
281 for (fnName in ElProto) {
282 if (typeof ElProto[fnName] == 'function'){
284 CelProto[fnName] = CelProto[fnName] || function() {
285 return this.invoke(fnName, arguments);
287 }).call(CelProto, fnName);
293 Ext.CompositeElementLite.importElementMethods();
296 Ext.Element.selectorFunction = Ext.DomQuery.select;
299 <div id="method-Ext.Element-select"></div>/**
300 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
301 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
302 * {@link Ext.CompositeElementLite CompositeElementLite} object.
303 * @param {String/Array} selector The CSS selector or an array of elements
304 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
305 * @return {CompositeElementLite/CompositeElement}
306 * @member Ext.Element
309 Ext.Element.select = function(selector, root){
311 if(typeof selector == "string"){
312 els = Ext.Element.selectorFunction(selector, root);
313 }else if(selector.length !== undefined){
316 throw "Invalid selector";
318 return new Ext.CompositeElementLite(els);
320 <div id="method-Ext-select"></div>/**
321 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
322 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
323 * {@link Ext.CompositeElementLite CompositeElementLite} object.
324 * @param {String/Array} selector The CSS selector or an array of elements
325 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
326 * @return {CompositeElementLite/CompositeElement}
330 Ext.select = Ext.Element.select;