4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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.core.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>
65 this.el = new Ext.core.Element.Flyweight();
68 Ext.CompositeElementLite.prototype = {
72 getElement : function(el){
73 // Set the shared flyweight dom property to the current element
81 transformElement : function(el){
82 return Ext.getDom(el);
85 <span id='Ext-CompositeElementLite-method-getCount'> /**
86 </span> * Returns the number of elements in this Composite.
89 getCount : function(){
90 return this.elements.length;
92 <span id='Ext-CompositeElementLite-method-add'> /**
93 </span> * Adds elements to this Composite object.
94 * @param {Mixed} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
95 * @return {CompositeElement} This Composite object.
97 add : function(els, root){
99 elements = me.elements;
103 if(typeof els == "string"){
104 els = Ext.core.Element.selectorFunction(els, root);
105 }else if(els.isComposite){
107 }else if(!Ext.isIterable(els)){
111 for(var i = 0, len = els.length; i < len; ++i){
112 elements.push(me.transformElement(els[i]));
117 invoke : function(fn, args){
124 for(i = 0; i < len; i++) {
127 Ext.core.Element.prototype[fn].apply(me.getElement(e), args);
132 <span id='Ext-CompositeElementLite-method-item'> /**
133 </span> * Returns a flyweight Element of the dom element object at the specified index
134 * @param {Number} index
135 * @return {Ext.core.Element}
137 item : function(index){
139 el = me.elements[index],
143 out = me.getElement(el);
148 // fixes scope with flyweight
149 addListener : function(eventName, handler, scope, opt){
150 var els = this.elements,
154 for(i = 0; i<len; i++) {
157 Ext.EventManager.on(e, eventName, handler, scope || e, opt);
162 <span id='Ext-CompositeElementLite-method-each'> /**
163 </span> * <p>Calls the passed function for each element in this composite.</p>
164 * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
165 * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
166 * <b>This is the flyweight (shared) Ext.core.Element instance, so if you require a
167 * a reference to the dom node, use el.dom.</b></div></li>
168 * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
169 * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
171 * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
172 * @return {CompositeElement} this
174 each : function(fn, scope){
180 for(i = 0; i<len; i++) {
183 e = this.getElement(e);
184 if(fn.call(scope || e, e, me, i) === false){
192 <span id='Ext-CompositeElementLite-method-fill'> /**
193 </span> * Clears this Composite and adds the elements passed.
194 * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.
195 * @return {CompositeElement} this
197 fill : function(els){
204 <span id='Ext-CompositeElementLite-method-filter'> /**
205 </span> * Filters this composite to only elements that match the passed selector.
206 * @param {String/Function} selector A string CSS selector or a comparison function.
207 * The comparison function will be called with the following arguments:<ul>
208 * <li><code>el</code> : Ext.core.Element<div class="sub-desc">The current DOM element.</div></li>
209 * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
211 * @return {CompositeElement} this
213 filter : function(selector){
216 fn = Ext.isFunction(selector) ? selector
218 return el.is(selector);
221 me.each(function(el, self, i) {
222 if (fn(el, i) !== false) {
223 els[els.length] = me.transformElement(el);
231 <span id='Ext-CompositeElementLite-method-indexOf'> /**
232 </span> * Find the index of the passed element within the composite collection.
233 * @param el {Mixed} The id of an element, or an Ext.core.Element, or an HtmlElement to find within the composite collection.
234 * @return Number The index of the passed Ext.core.Element in the composite collection, or -1 if not found.
236 indexOf : function(el){
237 return Ext.Array.indexOf(this.elements, this.transformElement(el));
240 <span id='Ext-CompositeElementLite-method-replaceElement'> /**
241 </span> * Replaces the specified element with the passed element.
242 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
244 * @param {Mixed} replacement The id of an element or the Element itself.
245 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
246 * @return {CompositeElement} this
248 replaceElement : function(el, replacement, domReplace){
249 var index = !isNaN(el) ? el : this.indexOf(el),
252 replacement = Ext.getDom(replacement);
254 d = this.elements[index];
255 d.parentNode.insertBefore(replacement, d);
258 this.elements.splice(index, 1, replacement);
263 <span id='Ext-CompositeElementLite-method-clear'> /**
264 </span> * Removes all elements.
271 Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
273 <span id='Ext-CompositeElementLite-method-importElementMethods'>/**
275 * Copies all of the functions from Ext.core.Element's prototype onto CompositeElementLite's prototype.
276 * This is called twice - once immediately below, and once again after additional Ext.core.Element
277 * are added in Ext JS
279 Ext.CompositeElementLite.importElementMethods = function() {
281 ElProto = Ext.core.Element.prototype,
282 CelProto = Ext.CompositeElementLite.prototype;
284 for (fnName in ElProto) {
285 if (typeof ElProto[fnName] == 'function'){
287 CelProto[fnName] = CelProto[fnName] || function() {
288 return this.invoke(fnName, arguments);
290 }).call(CelProto, fnName);
296 Ext.CompositeElementLite.importElementMethods();
299 Ext.core.Element.selectorFunction = Ext.DomQuery.select;
302 <span id='Ext-core-Element-method-select'>/**
303 </span> * Selects elements based on the passed CSS selector to enable {@link Ext.core.Element Element} methods
304 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
305 * {@link Ext.CompositeElementLite CompositeElementLite} object.
306 * @param {String/Array} selector The CSS selector or an array of elements
307 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
308 * @return {CompositeElementLite/CompositeElement}
309 * @member Ext.core.Element
312 Ext.core.Element.select = function(selector, root){
314 if(typeof selector == "string"){
315 els = Ext.core.Element.selectorFunction(selector, root);
316 }else if(selector.length !== undefined){
321 sourceClass: "Ext.core.Element",
322 sourceMethod: "select",
325 msg: "Invalid selector specified: " + selector
329 return new Ext.CompositeElementLite(els);
331 <span id='Ext-method-select'>/**
332 </span> * Selects elements based on the passed CSS selector to enable {@link Ext.core.Element Element} methods
333 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
334 * {@link Ext.CompositeElementLite CompositeElementLite} object.
335 * @param {String/Array} selector The CSS selector or an array of elements
336 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
337 * @return {CompositeElementLite/CompositeElement}
341 Ext.select = Ext.core.Element.select;