4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.CompositeElementLite
14 * @extends Roo.CompositeElement
15 * Flyweight composite class. Reuses the same Roo.Element for element operations.
17 var els = Roo.select("#some-el div.some-class");
18 // or select directly from an existing element
19 var el = Roo.get('some-el');
20 el.select('div.some-class');
22 els.setWidth(100); // all elements become 100 width
23 els.hide(true); // all elements fade out and hide
25 els.setWidth(100).hide(true);
27 * <b>NOTE: Although they are not listed, this class supports all of the set/update methods of Roo.Element. All Roo.Element
28 * actions will be performed on all the elements in this collection.</b>
30 Roo.CompositeElementLite = function(els){
31 Roo.CompositeElementLite.superclass.constructor.call(this, els);
32 this.el = new Roo.Element.Flyweight();
34 Roo.extend(Roo.CompositeElementLite, Roo.CompositeElement, {
35 addElements : function(els){
37 if(els instanceof Array){
38 this.elements = this.elements.concat(els);
40 var yels = this.elements;
41 var index = yels.length-1;
42 for(var i = 0, len = els.length; i < len; i++) {
43 yels[++index] = els[i];
49 invoke : function(fn, args){
50 var els = this.elements;
52 for(var i = 0, len = els.length; i < len; i++) {
54 Roo.Element.prototype[fn].apply(el, args);
59 * Returns a flyweight Element of the dom element object at the specified index
60 * @param {Number} index
61 * @return {Roo.Element}
63 item : function(index){
64 if(!this.elements[index]){
67 this.el.dom = this.elements[index];
71 // fixes scope with flyweight
72 addListener : function(eventName, handler, scope, opt){
73 var els = this.elements;
74 for(var i = 0, len = els.length; i < len; i++) {
75 Roo.EventManager.on(els[i], eventName, handler, scope || els[i], opt);
81 * Calls the passed function passing (el, this, index) for each element in this composite. <b>The element
82 * passed is the flyweight (shared) Roo.Element instance, so if you require a
83 * a reference to the dom node, use el.dom.</b>
84 * @param {Function} fn The function to call
85 * @param {Object} scope (optional) The <i>this</i> object (defaults to the element)
86 * @return {CompositeElement} this
88 each : function(fn, scope){
89 var els = this.elements;
91 for(var i = 0, len = els.length; i < len; i++){
93 if(fn.call(scope || el, el, this, i) === false){
100 indexOf : function(el){
101 return this.elements.indexOf(Roo.getDom(el));
104 replaceElement : function(el, replacement, domReplace){
105 var index = typeof el == 'number' ? el : this.indexOf(el);
107 replacement = Roo.getDom(replacement);
109 var d = this.elements[index];
110 d.parentNode.insertBefore(replacement, d);
111 d.parentNode.removeChild(d);
113 this.elements.splice(index, 1, replacement);
118 Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addListener;