/**
* @class YAHOO.ext.CompositeElement
* Standard composite class. Creates a YAHOO.ext.Element for every element in the collection.
*
* NOTE: Although they are not listed, this class supports all of the set/update methods of YAHOO.ext.Element. All YAHOO.ext.Element
* actions will be performed on all the elements in this collection.
*
* All methods return this and can be chained.
var els = getEls('#some-el div.some-class');
// or
var els = YAHOO.ext.Element.select('#some-el div.some-class');
els.setWidth(100); // all elements become 100 width
els.hide(true); // all elements fade out and hide
// or
els.setWidth(100).hide(true);
*/
YAHOO.ext.CompositeElement = function(els){
this.elements = [];
this.addElements(els);
};
YAHOO.ext.CompositeElement.prototype = {
isComposite: true,
addElements : function(els){
if(!els) return this;
var yels = this.elements;
var index = yels.length-1;
for(var i = 0, len = els.length; i < len; i++) {
yels[++index] = getEl(els[i], true);
}
return this;
},
invoke : function(fn, args){
var els = this.elements;
for(var i = 0, len = els.length; i < len; i++) {
YAHOO.ext.Element.prototype[fn].apply(els[i], args);
}
return this;
},
/**
* Adds elements to this composite.
* @param {String/Array} els A string CSS selector, an array of elements or an element
* @return {CompositeElement} this
*/
add : function(els){
if(typeof els == 'string'){
this.addElements(YAHOO.ext.Element.selectorFunction(string));
}else if(els instanceof Array){
this.addElements(els);
}else{
this.addElements([els]);
}
return this;
},
/**
* Calls the passed function passing (el, this, index) for each element in this composite.
* @param {Function} fn The function to call
* @param {Object} scope (optional) The this object (defaults to the element)
* @return {CompositeElement} this
*/
each : function(fn, scope){
var els = this.elements;
for(var i = 0, len = els.length; i < len; i++){
fn.call(scope || els[i], els[i], this, i);
}
return this;
}
};
/**
* @class YAHOO.ext.CompositeElementLite
* @extends YAHOO.ext.CompositeElement
* Flyweight composite class. Reuses the same YAHOO.ext.Element for element operations.
*