PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 5ms app.codeStats 0ms

/ext-4.1.0_b3/src/core/src/dom/CompositeElement.js

https://bitbucket.org/srogerf/javascript
JavaScript | 75 lines | 25 code | 7 blank | 43 comment | 5 complexity | dffa7e3920f82b822f210d4d7db786b5 MD5 | raw file
 1/**
 2 * @class Ext.dom.CompositeElement
 3 * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
 4 * members, or to perform collective actions upon the whole set.</p>
 5 * <p>Although they are not listed, this class supports all of the methods of {@link Ext.dom.Element} and
 6 * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.</p>
 7 * <p>All methods return <i>this</i> and can be chained.</p>
 8 * Usage:
 9 <pre><code>
10 var els = Ext.select("#some-el div.some-class", true);
11 // or select directly from an existing element
12 var el = Ext.get('some-el');
13 el.select('div.some-class', true);
14
15 els.setWidth(100); // all elements become 100 width
16 els.hide(true); // all elements fade out and hide
17 // or
18 els.setWidth(100).hide(true);
19 </code></pre>
20 */
21Ext.define('Ext.dom.CompositeElement', {
22    alternateClassName: 'Ext.CompositeElement',
23
24    extend: 'Ext.dom.CompositeElementLite',
25
26    // private
27    getElement: function(el) {
28        // In this case just return it, since we already have a reference to it
29        return el;
30    },
31
32    // private
33    transformElement: function(el) {
34        return Ext.get(el);
35    }
36
37}, function() {
38    /**
39     * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
40     * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
41     * {@link Ext.CompositeElementLite CompositeElementLite} object.
42     * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
43     * @param {Boolean} [unique] true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
44     * @param {HTMLElement/String} [root] The root element of the query or id of the root
45     * @return {Ext.CompositeElementLite/Ext.CompositeElement}
46     * @member Ext.dom.Element
47     * @method select
48     * @static
49     */
50
51    Ext.dom.Element.select = function(selector, unique, root) {
52        var elements;
53
54        if (typeof selector == "string") {
55            elements = Ext.dom.Element.selectorFunction(selector, root);
56        }
57        else if (selector.length !== undefined) {
58            elements = selector;
59        }
60        else {
61            //<debug>
62            throw new Error("[Ext.select] Invalid selector specified: " + selector);
63            //</debug>
64        }
65        return (unique === true) ? new Ext.CompositeElement(elements) : new Ext.CompositeElementLite(elements);
66    };
67});
68
69/**
70 * Shorthand of {@link Ext.Element#method-select}.
71 * @member Ext
72 * @method select
73 * @inheritdoc Ext.Element#select
74 */
75Ext.select = Ext.Element.select;