3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.CompositeElementLite"></div>/**
\r
9 * @class Ext.CompositeElementLite
\r
10 * Flyweight composite class. Reuses the same Ext.Element for element operations.
\r
12 var els = Ext.select("#some-el div.some-class");
\r
13 // or select directly from an existing element
\r
14 var el = Ext.get('some-el');
\r
15 el.select('div.some-class');
\r
17 els.setWidth(100); // all elements become 100 width
\r
18 els.hide(true); // all elements fade out and hide
\r
20 els.setWidth(100).hide(true);
\r
21 </code></pre><br><br>
\r
22 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Ext.Element. All Ext.Element
\r
23 * actions will be performed on all the elements in this collection.</b>
\r
25 Ext.CompositeElementLite = function(els, root){
\r
27 this.add(els, root);
\r
28 this.el = new Ext.Element.Flyweight();
\r
31 Ext.CompositeElementLite.prototype = {
\r
33 <div id="method-Ext.CompositeElementLite-getCount"></div>/**
\r
34 * Returns the number of elements in this composite
\r
37 getCount : function(){
\r
38 return this.elements.length;
\r
40 add : function(els){
\r
42 if (Ext.isArray(els)) {
\r
43 this.elements = this.elements.concat(els);
\r
45 var yels = this.elements;
\r
46 Ext.each(els, function(e) {
\r
53 invoke : function(fn, args){
\r
54 var els = this.elements,
\r
56 Ext.each(els, function(e) {
\r
58 Ext.Element.prototype[fn].apply(el, args);
\r
62 <div id="method-Ext.CompositeElementLite-item"></div>/**
\r
63 * Returns a flyweight Element of the dom element object at the specified index
\r
64 * @param {Number} index
\r
65 * @return {Ext.Element}
\r
67 item : function(index){
\r
69 if(!me.elements[index]){
\r
72 me.el.dom = me.elements[index];
\r
76 // fixes scope with flyweight
\r
77 addListener : function(eventName, handler, scope, opt){
\r
78 Ext.each(this.elements, function(e) {
\r
79 Ext.EventManager.on(e, eventName, handler, scope || e, opt);
\r
83 <div id="method-Ext.CompositeElementLite-each"></div>/**
\r
84 * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element
\r
85 * passed is the flyweight (shared) Ext.Element instance, so if you require a
\r
86 * a reference to the dom node, use el.dom.</b>
\r
87 * @param {Function} fn The function to call
\r
88 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
\r
89 * @return {CompositeElement} this
\r
91 each : function(fn, scope){
\r
95 Ext.each(me.elements, function(e,i) {
\r
97 return fn.call(scope || el, el, me, i);
\r
102 <div id="method-Ext.CompositeElementLite-indexOf"></div>/**
\r
103 * Find the index of the passed element within the composite collection.
\r
104 * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
\r
105 * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
\r
107 indexOf : function(el){
\r
108 return this.elements.indexOf(Ext.getDom(el));
\r
111 <div id="method-Ext.CompositeElementLite-replaceElement"></div>/**
\r
112 * Replaces the specified element with the passed element.
\r
113 * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
\r
115 * @param {Mixed} replacement The id of an element or the Element itself.
\r
116 * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
\r
117 * @return {CompositeElement} this
\r
119 replaceElement : function(el, replacement, domReplace){
\r
120 var index = !isNaN(el) ? el : this.indexOf(el),
\r
123 replacement = Ext.getDom(replacement);
\r
125 d = this.elements[index];
\r
126 d.parentNode.insertBefore(replacement, d);
\r
129 this.elements.splice(index, 1, replacement);
\r
134 <div id="method-Ext.CompositeElementLite-clear"></div>/**
\r
135 * Removes all elements.
\r
137 clear : function(){
\r
138 this.elements = [];
\r
142 Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
\r
146 ElProto = Ext.Element.prototype,
\r
147 CelProto = Ext.CompositeElementLite.prototype;
\r
149 for(fnName in ElProto){
\r
150 if(Ext.isFunction(ElProto[fnName])){
\r
151 (function(fnName){
\r
152 CelProto[fnName] = CelProto[fnName] || function(){
\r
153 return this.invoke(fnName, arguments);
\r
155 }).call(CelProto, fnName);
\r
162 Ext.Element.selectorFunction = Ext.DomQuery.select;
\r
165 <div id="method-Ext.Element-select"></div>/**
\r
166 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
\r
167 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
\r
168 * {@link Ext.CompositeElementLite CompositeElementLite} object.
\r
169 * @param {String/Array} selector The CSS selector or an array of elements
\r
170 * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object) <b>Not supported in core</b>
\r
171 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
\r
172 * @return {CompositeElementLite/CompositeElement}
\r
173 * @member Ext.Element
\r
176 Ext.Element.select = function(selector, unique, root){
\r
178 if(typeof selector == "string"){
\r
179 els = Ext.Element.selectorFunction(selector, root);
\r
180 }else if(selector.length !== undefined){
\r
183 throw "Invalid selector";
\r
185 return new Ext.CompositeElementLite(els);
\r
187 <div id="method-Ext-select"></div>/**
\r
188 * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
\r
189 * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
\r
190 * {@link Ext.CompositeElementLite CompositeElementLite} object.
\r
191 * @param {String/Array} selector The CSS selector or an array of elements
\r
192 * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
\r
193 * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
\r
194 * @return {CompositeElementLite/CompositeElement}
\r
198 Ext.select = Ext.Element.select;</pre>
\r