64c745b170f61b9b2ae9283f0da3953e4bb615d1.svn-base 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /**
  7. * @class Ext.layout.ContainerLayout Every layout is composed of one or more
  8. * {@link Ext.Container} elements internally, and ContainerLayout
  9. * provides the basic foundation for all other layout classes in Ext. It
  10. * is a non-visual class that simply provides the base logic required for
  11. * a Container to function as a layout. This class is intended to be
  12. * extended and should generally not need to be created directly via the
  13. * new keyword.
  14. */
  15. Ext.layout.ContainerLayout = function(config) {
  16. Ext.apply(this, config);
  17. };
  18. Ext.layout.ContainerLayout.prototype = {
  19. /**
  20. * @cfg {String} extraCls An optional extra CSS class that will be added to
  21. * the container (defaults to ''). This can be useful for adding
  22. * customized styles to the container or any of its children using
  23. * standard CSS rules.
  24. */
  25. /**
  26. * @cfg {Boolean} renderHidden True to hide each contained item on render
  27. * (defaults to false).
  28. */
  29. /**
  30. * A reference to the {@link Ext.Component} that is active. For example,
  31. * if(myPanel.layout.activeItem.id == 'item-1') { ... }. activeItem only
  32. * applies to layout styles that can display items one at a time (like
  33. * {@link Ext.layout.Accordion}, {@link Ext.layout.CardLayout} and
  34. * {@link Ext.layout.FitLayout}). Read-only. Related to
  35. * {@link Ext.Container#activeItem}.
  36. *
  37. * @type {Ext.Component}
  38. * @property activeItem
  39. */
  40. // private
  41. monitorResize : false,
  42. // private
  43. activeItem : null,
  44. // private
  45. layout : function() {
  46. var target = this.container.getLayoutTarget();
  47. this.onLayout(this.container, target);
  48. this.container.fireEvent('afterlayout', this.container, this);
  49. },
  50. // private
  51. onLayout : function(ct, target) {
  52. this.renderAll(ct, target);
  53. },
  54. // private
  55. isValidParent : function(c, target) {
  56. var el = c.getPositionEl ? c.getPositionEl() : c.getEl();
  57. return el.dom.parentNode == target.dom;
  58. },
  59. // private
  60. renderAll : function(ct, target) {
  61. var items = ct.items.items;
  62. for (var i = 0, len = items.length; i < len; i++) {
  63. var c = items[i];
  64. if (c && (!c.rendered || !this.isValidParent(c, target))) {
  65. this.renderItem(c, i, target);
  66. }
  67. }
  68. },
  69. // private
  70. renderItem : function(c, position, target) {
  71. if (c && !c.rendered) {
  72. if (this.extraCls) {
  73. c.addClass(this.extraCls);
  74. }
  75. c.render(target, position);
  76. if (this.renderHidden && c != this.activeItem) {
  77. c.hide();
  78. }
  79. } else if (c && !this.isValidParent(c, target)) {
  80. if (this.extraCls) {
  81. c.addClass(this.extraCls);
  82. }
  83. if (typeof position == 'number') {
  84. position = target.dom.childNodes[position];
  85. }
  86. target.dom.insertBefore(c.getEl().dom, position || null);
  87. if (this.renderHidden && c != this.activeItem) {
  88. c.hide();
  89. }
  90. }
  91. },
  92. // private
  93. onResize : function() {
  94. if (this.container.collapsed) {
  95. return;
  96. }
  97. var b = this.container.bufferResize;
  98. if (b) {
  99. if (!this.resizeTask) {
  100. this.resizeTask = new Ext.util.DelayedTask(this.layout, this);
  101. this.resizeBuffer = typeof b == 'number' ? b : 100;
  102. }
  103. this.resizeTask.delay(this.resizeBuffer);
  104. } else {
  105. this.layout();
  106. }
  107. },
  108. // private
  109. setContainer : function(ct) {
  110. if (this.monitorResize && ct != this.container) {
  111. if (this.container) {
  112. this.container.un('resize', this.onResize, this);
  113. }
  114. if (ct) {
  115. ct.on('resize', this.onResize, this);
  116. }
  117. }
  118. this.container = ct;
  119. },
  120. // private
  121. parseMargins : function(v) {
  122. var ms = v.split(' ');
  123. var len = ms.length;
  124. if (len == 1) {
  125. ms[1] = ms[0];
  126. ms[2] = ms[0];
  127. ms[3] = ms[0];
  128. }
  129. if (len == 2) {
  130. ms[2] = ms[0];
  131. ms[3] = ms[1];
  132. }
  133. return {
  134. top : parseInt(ms[0], 10) || 0,
  135. right : parseInt(ms[1], 10) || 0,
  136. bottom : parseInt(ms[2], 10) || 0,
  137. left : parseInt(ms[3], 10) || 0
  138. };
  139. }
  140. };
  141. Ext.Container.LAYOUTS['auto'] = Ext.layout.ContainerLayout;