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">/**
\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
114 for(i = 0; i<len; i++) {
\r
117 Ext.Element.prototype[fn].apply(me.getElement(e), args);
\r
122 <div id="method-Ext.CompositeElementLite-item"></div>/**
\r
123 * Returns a flyweight Element of the dom element object at the specified index
\r
124 * @param {Number} index
\r
125 * @return {Ext.Element}
\r
127 item : function(index){
\r
129 el = me.elements[index],
\r
133 out = me.getElement(el);
\r
138 // fixes scope with flyweight
\r
139 addListener : function(eventName, handler, scope, opt){
\r
140 var els = this.elements,
\r
144 for(i = 0; i<len; i++) {
\r
147 Ext.EventManager.on(e, eventName, handler, scope || e, opt);
\r
152 <div id="method-Ext.CompositeElementLite-each"></div>/**
\r
153 * <p>Calls the passed function for each element in this composite.</p>
\r
154 * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
\r
155 * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
\r
156 * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
\r
157 * a reference to the dom node, use el.dom.</b></div></li>
\r
158 * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
\r
159 * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
\r
161 * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
\r
162 * @return {CompositeElement} this
\r
164 each : function(fn, scope){
\r
170 for(i = 0; i<len; i++) {
\r
173 e = this.getElement(e);
\r
174 if(fn.call(scope || e, e, me, i)){
\r
182 <div id="method-Ext.CompositeElementLite-fill"></div>/**
\r
183 * Clears this Composite and adds the elements passed.
\r
184 * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.
\r
185 * @return {CompositeElement} this
\r
187 fill : function(els){
\r
194 <div id="method-Ext.CompositeElementLite-filter"></div>/**
\r
195 * Filters this composite to only elements that match the passed selector.
\r
196 * @param {String/Function} selector A string CSS selector or a comparison function.
\r
197 * The comparison function will be called with the following arguments:<ul>
\r
198 * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
\r
199 * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
\r
201 * @return {CompositeElement} this
\r
203 filter : function(selector){
\r
206 elements = me.elements,
\r
207 fn = Ext.isFunction(selector) ? selector
\r
209 return el.is(selector);
\r
213 me.each(function(el, self, i){
\r
214 if(fn(el, i) !== false){
\r
215 els[els.length] = me.transformElement(el);
\r
222 <div id="method-Ext.CompositeElementLite-indexOf"></div>/**
\r
223 * Find the index of the passed element within the composite collection.
\r
224 * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
\r
225 * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
\r
227 indexOf : function(el){
\r
228 return this.elements.indexOf(this.transformElement(el));
\r
231 <div id="method-Ext.CompositeElementLite-replaceElement"></div>/**
\r
232 * Replaces the specified element with the passed element.
\r
233 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
\r
235 * @param {Mixed} replacement The id of an element or the Element itself.
\r
236 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
\r
237 * @return {CompositeElement} this
\r
239 replaceElement : function(el, replacement, domReplace){
\r
240 var index = !isNaN(el) ? el : this.indexOf(el),
\r
243 replacement = Ext.getDom(replacement);
\r
245 d = this.elements[index];
\r
246 d.parentNode.insertBefore(replacement, d);
\r
249 this.elements.splice(index, 1, replacement);
\r
254 <div id="method-Ext.CompositeElementLite-clear"></div>/**
\r
255 * Removes all elements.
\r
257 clear : function(){
\r
258 this.elements = [];
\r
262 Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
\r
266 ElProto = Ext.Element.prototype,
\r
267 CelProto = Ext.CompositeElementLite.prototype;
\r
269 for(fnName in ElProto){
\r
270 if(Ext.isFunction(ElProto[fnName])){
\r
271 (function(fnName){
\r
272 CelProto[fnName] = CelProto[fnName] || function(){
\r
273 return this.invoke(fnName, arguments);
\r
275 }).call(CelProto, fnName);
\r
282 Ext.Element.selectorFunction = Ext.DomQuery.select;
\r
285 <div id="method-Ext.Element-select"></div>/**
\r
286 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
\r
287 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
\r
288 * {@link Ext.CompositeElementLite CompositeElementLite} object.
\r
289 * @param {String/Array} selector The CSS selector or an array of elements
\r
290 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
\r
291 * @return {CompositeElementLite/CompositeElement}
\r
292 * @member Ext.Element
\r
295 Ext.Element.select = function(selector, root){
\r
297 if(typeof selector == "string"){
\r
298 els = Ext.Element.selectorFunction(selector, root);
\r
299 }else if(selector.length !== undefined){
\r
302 throw "Invalid selector";
\r
304 return new Ext.CompositeElementLite(els);
\r
306 <div id="method-Ext-select"></div>/**
\r
307 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
\r
308 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
\r
309 * {@link Ext.CompositeElementLite CompositeElementLite} object.
\r
310 * @param {String/Array} selector The CSS selector or an array of elements
\r
311 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
\r
312 * @return {CompositeElementLite/CompositeElement}
\r
316 Ext.select = Ext.Element.select;</pre>
\r