/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. els.setWidth(100); // all elements become 100 width
  15. els.hide(true); // all elements fade out and hide
  16. // or
  17. els.setWidth(100).hide(true);
  18. </code></pre>
  19. */
  20. Ext.define('Ext.dom.CompositeElement', {
  21. alternateClassName: 'Ext.CompositeElement',
  22. extend: 'Ext.dom.CompositeElementLite',
  23. // private
  24. getElement: function(el) {
  25. // In this case just return it, since we already have a reference to it
  26. return el;
  27. },
  28. // private
  29. transformElement: function(el) {
  30. return Ext.get(el);
  31. }
  32. }, function() {
  33. /**
  34. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  35. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  36. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  37. * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
  38. * @param {Boolean} [unique] true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
  39. * @param {HTMLElement/String} [root] The root element of the query or id of the root
  40. * @return {Ext.CompositeElementLite/Ext.CompositeElement}
  41. * @member Ext.dom.Element
  42. * @method select
  43. * @static
  44. */
  45. Ext.dom.Element.select = function(selector, unique, root) {
  46. var elements;
  47. if (typeof selector == "string") {
  48. elements = Ext.dom.Element.selectorFunction(selector, root);
  49. }
  50. else if (selector.length !== undefined) {
  51. elements = selector;
  52. }
  53. else {
  54. //<debug>
  55. throw new Error("[Ext.select] Invalid selector specified: " + selector);
  56. //</debug>
  57. }
  58. return (unique === true) ? new Ext.CompositeElement(elements) : new Ext.CompositeElementLite(elements);
  59. };
  60. });
  61. /**
  62. * Shorthand of {@link Ext.Element#method-select}.
  63. * @member Ext
  64. * @method select
  65. * @inheritdoc Ext.Element#select
  66. */
  67. Ext.select = Ext.Element.select;