3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.CompositeElementLite"></div>/**
\r
10 * @class Ext.CompositeElementLite
\r
11 * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
\r
12 * members, or to perform collective actions upon the whole set.</p>
\r
13 * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
\r
14 * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>
\r
15 * Example:<pre><code>
\r
16 var els = Ext.select("#some-el div.some-class");
\r
17 // or select directly from an existing element
\r
18 var el = Ext.get('some-el');
\r
19 el.select('div.some-class');
\r
21 els.setWidth(100); // all elements become 100 width
\r
22 els.hide(true); // all elements fade out and hide
\r
24 els.setWidth(100).hide(true);
\r
27 Ext.CompositeElementLite = function(els, root){
\r
28 <div id="prop-Ext.CompositeElementLite-elements"></div>/**
\r
29 * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>
\r
30 * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing
\r
31 * to augment the capabilities of the CompositeElementLite class may use it when adding
\r
32 * methods to the class.</p>
\r
33 * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all
\r
34 * following siblings of selected elements, the code would be</p><code><pre>
\r
35 Ext.override(Ext.CompositeElementLite, {
\r
36 nextAll: function() {
\r
37 var els = this.elements, i, l = els.length, n, r = [], ri = -1;
\r
39 // Loop through all elements in this Composite, accumulating
\r
40 // an Array of all siblings.
\r
41 for (i = 0; i < l; i++) {
\r
42 for (n = els[i].nextSibling; n; n = n.nextSibling) {
\r
47 // Add all found siblings to this Composite
\r
52 * @property elements
\r
55 this.add(els, root);
\r
56 this.el = new Ext.Element.Flyweight();
\r
59 Ext.CompositeElementLite.prototype = {
\r
63 getElement : function(el){
\r
64 // Set the shared flyweight dom property to the current element
\r
72 transformElement : function(el){
\r
73 return Ext.getDom(el);
\r
76 <div id="method-Ext.CompositeElementLite-getCount"></div>/**
\r
77 * Returns the number of elements in this Composite.
\r
80 getCount : function(){
\r
81 return this.elements.length;
\r
83 <div id="method-Ext.CompositeElementLite-add"></div>/**
\r
84 * Adds elements to this Composite object.
\r
85 * @param {Mixed} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
\r
86 * @return {CompositeElement} This Composite object.
\r
88 add : function(els, root){
\r
90 elements = me.elements;
\r
94 if(Ext.isString(els)){
\r
95 els = Ext.Element.selectorFunction(els, root);
\r
96 }else if(els.isComposite){
\r
98 }else if(!Ext.isIterable(els)){
\r
102 for(var i = 0, len = els.length; i < len; ++i){
\r
103 elements.push(me.transformElement(els[i]));
\r
108 invoke : function(fn, args){
\r
115 for(i = 0; i < len; i++) {
\r
118 Ext.Element.prototype[fn].apply(me.getElement(e), args);
\r
123 <div id="method-Ext.CompositeElementLite-item"></div>/**
\r
124 * Returns a flyweight Element of the dom element object at the specified index
\r
125 * @param {Number} index
\r
126 * @return {Ext.Element}
\r
128 item : function(index){
\r
130 el = me.elements[index],
\r
134 out = me.getElement(el);
\r
139 // fixes scope with flyweight
\r
140 addListener : function(eventName, handler, scope, opt){
\r
141 var els = this.elements,
\r
145 for(i = 0; i<len; i++) {
\r
148 Ext.EventManager.on(e, eventName, handler, scope || e, opt);
\r
153 <div id="method-Ext.CompositeElementLite-each"></div>/**
\r
154 * <p>Calls the passed function for each element in this composite.</p>
\r
155 * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
\r
156 * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
\r
157 * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
\r
158 * a reference to the dom node, use el.dom.</b></div></li>
\r
159 * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
\r
160 * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
\r
162 * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
\r
163 * @return {CompositeElement} this
\r
165 each : function(fn, scope){
\r
171 for(i = 0; i<len; i++) {
\r
174 e = this.getElement(e);
\r
175 if(fn.call(scope || e, e, me, i) === false){
\r
183 <div id="method-Ext.CompositeElementLite-fill"></div>/**
\r
184 * Clears this Composite and adds the elements passed.
\r
185 * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.
\r
186 * @return {CompositeElement} this
\r
188 fill : function(els){
\r
195 <div id="method-Ext.CompositeElementLite-filter"></div>/**
\r
196 * Filters this composite to only elements that match the passed selector.
\r
197 * @param {String/Function} selector A string CSS selector or a comparison function.
\r
198 * The comparison function will be called with the following arguments:<ul>
\r
199 * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
\r
200 * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
\r
202 * @return {CompositeElement} this
\r
204 filter : function(selector){
\r
207 elements = me.elements,
\r
208 fn = Ext.isFunction(selector) ? selector
\r
210 return el.is(selector);
\r
214 me.each(function(el, self, i){
\r
215 if(fn(el, i) !== false){
\r
216 els[els.length] = me.transformElement(el);
\r
223 <div id="method-Ext.CompositeElementLite-indexOf"></div>/**
\r
224 * Find the index of the passed element within the composite collection.
\r
225 * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
\r
226 * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
\r
228 indexOf : function(el){
\r
229 return this.elements.indexOf(this.transformElement(el));
\r
232 <div id="method-Ext.CompositeElementLite-replaceElement"></div>/**
\r
233 * Replaces the specified element with the passed element.
\r
234 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
\r
236 * @param {Mixed} replacement The id of an element or the Element itself.
\r
237 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
\r
238 * @return {CompositeElement} this
\r
240 replaceElement : function(el, replacement, domReplace){
\r
241 var index = !isNaN(el) ? el : this.indexOf(el),
\r
244 replacement = Ext.getDom(replacement);
\r
246 d = this.elements[index];
\r
247 d.parentNode.insertBefore(replacement, d);
\r
250 this.elements.splice(index, 1, replacement);
\r
255 <div id="method-Ext.CompositeElementLite-clear"></div>/**
\r
256 * Removes all elements.
\r
258 clear : function(){
\r
259 this.elements = [];
\r
263 Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
\r
267 ElProto = Ext.Element.prototype,
\r
268 CelProto = Ext.CompositeElementLite.prototype;
\r
270 for(fnName in ElProto){
\r
271 if(Ext.isFunction(ElProto[fnName])){
\r
272 (function(fnName){
\r
273 CelProto[fnName] = CelProto[fnName] || function(){
\r
274 return this.invoke(fnName, arguments);
\r
276 }).call(CelProto, fnName);
\r
283 Ext.Element.selectorFunction = Ext.DomQuery.select;
\r
286 <div id="method-Ext.Element-select"></div>/**
\r
287 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
\r
288 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
\r
289 * {@link Ext.CompositeElementLite CompositeElementLite} object.
\r
290 * @param {String/Array} selector The CSS selector or an array of elements
\r
291 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
\r
292 * @return {CompositeElementLite/CompositeElement}
\r
293 * @member Ext.Element
\r
296 Ext.Element.select = function(selector, root){
\r
298 if(typeof selector == "string"){
\r
299 els = Ext.Element.selectorFunction(selector, root);
\r
300 }else if(selector.length !== undefined){
\r
303 throw "Invalid selector";
\r
305 return new Ext.CompositeElementLite(els);
\r
307 <div id="method-Ext-select"></div>/**
\r
308 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
\r
309 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
\r
310 * {@link Ext.CompositeElementLite CompositeElementLite} object.
\r
311 * @param {String/Array} selector The CSS selector or an array of elements
\r
312 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
\r
313 * @return {CompositeElementLite/CompositeElement}
\r
317 Ext.select = Ext.Element.select;</pre>
\r