/hippo/src/main/webapp/ext/src/core/CompositeElementLite-more.js

http://hdbc.googlecode.com/ · JavaScript · 102 lines · 57 code · 6 blank · 39 comment · 9 complexity · 8b9f14ee6daec68a85afb1df9fea0aeb MD5 · raw file

  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /**
  8. * @class Ext.CompositeElementLite
  9. */
  10. Ext.apply(Ext.CompositeElementLite.prototype, {
  11. addElements : function(els, root){
  12. if(!els){
  13. return this;
  14. }
  15. if(typeof els == "string"){
  16. els = Ext.Element.selectorFunction(els, root);
  17. }
  18. var yels = this.elements;
  19. Ext.each(els, function(e) {
  20. yels.push(Ext.get(e));
  21. });
  22. return this;
  23. },
  24. /**
  25. * Clears this composite and adds the elements returned by the passed selector.
  26. * @param {String/Array} els A string CSS selector, an array of elements or an element
  27. * @return {CompositeElement} this
  28. */
  29. fill : function(els){
  30. this.elements = [];
  31. this.add(els);
  32. return this;
  33. },
  34. /**
  35. * Returns the first Element
  36. * @return {Ext.Element}
  37. */
  38. first : function(){
  39. return this.item(0);
  40. },
  41. /**
  42. * Returns the last Element
  43. * @return {Ext.Element}
  44. */
  45. last : function(){
  46. return this.item(this.getCount()-1);
  47. },
  48. /**
  49. * Returns true if this composite contains the passed element
  50. * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
  51. * @return Boolean
  52. */
  53. contains : function(el){
  54. return this.indexOf(el) != -1;
  55. },
  56. /**
  57. * Filters this composite to only elements that match the passed selector.
  58. * @param {String} selector A string CSS selector
  59. * @return {CompositeElement} this
  60. */
  61. filter : function(selector){
  62. var els = [];
  63. this.each(function(el){
  64. if(el.is(selector)){
  65. els[els.length] = el.dom;
  66. }
  67. });
  68. this.fill(els);
  69. return this;
  70. },
  71. /**
  72. * Removes the specified element(s).
  73. * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
  74. * or an array of any of those.
  75. * @param {Boolean} removeDom (optional) True to also remove the element from the document
  76. * @return {CompositeElement} this
  77. */
  78. removeElement : function(keys, removeDom){
  79. var me = this,
  80. els = this.elements,
  81. el;
  82. Ext.each(keys, function(val){
  83. if ((el = (els[val] || els[val = me.indexOf(val)]))) {
  84. if(removeDom){
  85. if(el.dom){
  86. el.remove();
  87. }else{
  88. Ext.removeNode(el);
  89. }
  90. }
  91. els.splice(val, 1);
  92. }
  93. });
  94. return this;
  95. }
  96. });