+++ /dev/null
-/*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-/**\r
- * @class Ext.CompositeElementLite\r
- * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter\r
- * members, or to perform collective actions upon the whole set.</p>\r
- * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and\r
- * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>\r
- * Example:<pre><code>\r
-var els = Ext.select("#some-el div.some-class");\r
-// or select directly from an existing element\r
-var el = Ext.get('some-el');\r
-el.select('div.some-class');\r
-\r
-els.setWidth(100); // all elements become 100 width\r
-els.hide(true); // all elements fade out and hide\r
-// or\r
-els.setWidth(100).hide(true);\r
-</code>\r
- */\r
-Ext.CompositeElementLite = function(els, root){\r
- /**\r
- * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>\r
- * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing\r
- * to augment the capabilities of the CompositeElementLite class may use it when adding\r
- * methods to the class.</p>\r
- * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all\r
- * following siblings of selected elements, the code would be</p><code><pre>\r
-Ext.override(Ext.CompositeElementLite, {\r
- nextAll: function() {\r
- var els = this.elements, i, l = els.length, n, r = [], ri = -1;\r
-\r
-// Loop through all elements in this Composite, accumulating\r
-// an Array of all siblings.\r
- for (i = 0; i < l; i++) {\r
- for (n = els[i].nextSibling; n; n = n.nextSibling) {\r
- r[++ri] = n;\r
- }\r
- }\r
-\r
-// Add all found siblings to this Composite\r
- return this.add(r);\r
- }\r
-});</pre></code>\r
- * @type Array\r
- * @property elements\r
- */\r
- this.elements = [];\r
- this.add(els, root);\r
- this.el = new Ext.Element.Flyweight();\r
-};\r
-\r
-Ext.CompositeElementLite.prototype = {\r
- isComposite: true, \r
- \r
- // private\r
- getElement : function(el){\r
- // Set the shared flyweight dom property to the current element\r
- var e = this.el;\r
- e.dom = el;\r
- e.id = el.id;\r
- return e;\r
- },\r
- \r
- // private\r
- transformElement : function(el){\r
- return Ext.getDom(el);\r
- },\r
- \r
- /**\r
- * Returns the number of elements in this Composite.\r
- * @return Number\r
- */\r
- getCount : function(){\r
- return this.elements.length;\r
- }, \r
- /**\r
- * Adds elements to this Composite object.\r
- * @param {Mixed} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.\r
- * @return {CompositeElement} This Composite object.\r
- */\r
- add : function(els, root){\r
- var me = this,\r
- elements = me.elements;\r
- if(!els){\r
- return this;\r
- }\r
- if(Ext.isString(els)){\r
- els = Ext.Element.selectorFunction(els, root);\r
- }else if(els.isComposite){\r
- els = els.elements;\r
- }else if(!Ext.isIterable(els)){\r
- els = [els];\r
- }\r
- \r
- for(var i = 0, len = els.length; i < len; ++i){\r
- elements.push(me.transformElement(els[i]));\r
- }\r
- return me;\r
- },\r
- \r
- invoke : function(fn, args){\r
- var me = this,\r
- els = me.elements,\r
- len = els.length, \r
- e, \r
- i;\r
- \r
- for(i = 0; i < len; i++) {\r
- e = els[i];\r
- if(e){\r
- Ext.Element.prototype[fn].apply(me.getElement(e), args);\r
- }\r
- }\r
- return me;\r
- },\r
- /**\r
- * Returns a flyweight Element of the dom element object at the specified index\r
- * @param {Number} index\r
- * @return {Ext.Element}\r
- */\r
- item : function(index){\r
- var me = this,\r
- el = me.elements[index],\r
- out = null;\r
-\r
- if(el){\r
- out = me.getElement(el);\r
- }\r
- return out;\r
- },\r
-\r
- // fixes scope with flyweight\r
- addListener : function(eventName, handler, scope, opt){\r
- var els = this.elements,\r
- len = els.length,\r
- i, e;\r
- \r
- for(i = 0; i<len; i++) {\r
- e = els[i];\r
- if(e) {\r
- Ext.EventManager.on(e, eventName, handler, scope || e, opt);\r
- }\r
- }\r
- return this;\r
- },\r
- /**\r
- * <p>Calls the passed function for each element in this composite.</p>\r
- * @param {Function} fn The function to call. The function is passed the following parameters:<ul>\r
- * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.\r
- * <b>This is the flyweight (shared) Ext.Element instance, so if you require a\r
- * a reference to the dom node, use el.dom.</b></div></li>\r
- * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>\r
- * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>\r
- * </ul>\r
- * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)\r
- * @return {CompositeElement} this\r
- */\r
- each : function(fn, scope){ \r
- var me = this,\r
- els = me.elements,\r
- len = els.length,\r
- i, e;\r
- \r
- for(i = 0; i<len; i++) {\r
- e = els[i];\r
- if(e){\r
- e = this.getElement(e);\r
- if(fn.call(scope || e, e, me, i) === false){\r
- break;\r
- }\r
- }\r
- }\r
- return me;\r
- },\r
- \r
- /**\r
- * Clears this Composite and adds the elements passed.\r
- * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.\r
- * @return {CompositeElement} this\r
- */\r
- fill : function(els){\r
- var me = this;\r
- me.elements = [];\r
- me.add(els);\r
- return me;\r
- },\r
- \r
- /**\r
- * Filters this composite to only elements that match the passed selector.\r
- * @param {String/Function} selector A string CSS selector or a comparison function.\r
- * The comparison function will be called with the following arguments:<ul>\r
- * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>\r
- * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>\r
- * </ul>\r
- * @return {CompositeElement} this\r
- */\r
- filter : function(selector){\r
- var els = [],\r
- me = this,\r
- elements = me.elements,\r
- fn = Ext.isFunction(selector) ? selector\r
- : function(el){\r
- return el.is(selector);\r
- };\r
- \r
- \r
- me.each(function(el, self, i){\r
- if(fn(el, i) !== false){\r
- els[els.length] = me.transformElement(el);\r
- }\r
- });\r
- me.elements = els;\r
- return me;\r
- },\r
- \r
- /**\r
- * Find the index of the passed element within the composite collection.\r
- * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.\r
- * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.\r
- */\r
- indexOf : function(el){\r
- return this.elements.indexOf(this.transformElement(el));\r
- },\r
- \r
- /**\r
- * Replaces the specified element with the passed element.\r
- * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite\r
- * to replace.\r
- * @param {Mixed} replacement The id of an element or the Element itself.\r
- * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.\r
- * @return {CompositeElement} this\r
- */ \r
- replaceElement : function(el, replacement, domReplace){\r
- var index = !isNaN(el) ? el : this.indexOf(el),\r
- d;\r
- if(index > -1){\r
- replacement = Ext.getDom(replacement);\r
- if(domReplace){\r
- d = this.elements[index];\r
- d.parentNode.insertBefore(replacement, d);\r
- Ext.removeNode(d);\r
- }\r
- this.elements.splice(index, 1, replacement);\r
- }\r
- return this;\r
- },\r
- \r
- /**\r
- * Removes all elements.\r
- */\r
- clear : function(){\r
- this.elements = [];\r
- }\r
-};\r
-\r
-Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;\r
-\r
-(function(){\r
-var fnName,\r
- ElProto = Ext.Element.prototype,\r
- CelProto = Ext.CompositeElementLite.prototype;\r
- \r
-for(fnName in ElProto){\r
- if(Ext.isFunction(ElProto[fnName])){\r
- (function(fnName){ \r
- CelProto[fnName] = CelProto[fnName] || function(){\r
- return this.invoke(fnName, arguments);\r
- };\r
- }).call(CelProto, fnName);\r
- \r
- }\r
-}\r
-})();\r
-\r
-if(Ext.DomQuery){\r
- Ext.Element.selectorFunction = Ext.DomQuery.select;\r
-} \r
-\r
-/**\r
- * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods\r
- * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or\r
- * {@link Ext.CompositeElementLite CompositeElementLite} object.\r
- * @param {String/Array} selector The CSS selector or an array of elements\r
- * @param {HTMLElement/String} root (optional) The root element of the query or id of the root\r
- * @return {CompositeElementLite/CompositeElement}\r
- * @member Ext.Element\r
- * @method select\r
- */\r
-Ext.Element.select = function(selector, root){\r
- var els;\r
- if(typeof selector == "string"){\r
- els = Ext.Element.selectorFunction(selector, root);\r
- }else if(selector.length !== undefined){\r
- els = selector;\r
- }else{\r
- throw "Invalid selector";\r
- }\r
- return new Ext.CompositeElementLite(els);\r
-};\r
-/**\r
- * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods\r
- * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or\r
- * {@link Ext.CompositeElementLite CompositeElementLite} object.\r
- * @param {String/Array} selector The CSS selector or an array of elements\r
- * @param {HTMLElement/String} root (optional) The root element of the query or id of the root\r
- * @return {CompositeElementLite/CompositeElement}\r
- * @member Ext\r
- * @method select\r
- */\r
-Ext.select = Ext.Element.select;
\ No newline at end of file