not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.3 KiB

  1. /**
  2. _enyo.CarouselArranger_ is an <a href="#enyo.Arranger">enyo.Arranger</a>
  3. that displays the active control, along with some number of inactive
  4. controls to fill the available space. The active control is positioned on
  5. the left side of the container, and the rest of the views are laid out to
  6. the right.
  7. One of the controls may have _fit: true_ set, in which case it will take up
  8. any remaining space after all of the other controls have been sized.
  9. For best results with CarouselArranger, you should set a minimum width for
  10. each control via a CSS style, e.g., _min-width: 25%_ or _min-width: 250px_.
  11. Transitions between arrangements are handled by sliding the new controls in
  12. from the right and sliding the old controls off to the left.
  13. */
  14. enyo.kind({
  15. name: "enyo.CarouselArranger",
  16. kind: "Arranger",
  17. size: function() {
  18. var c$ = this.container.getPanels();
  19. var padding = this.containerPadding = this.container.hasNode() ? enyo.FittableLayout.calcPaddingExtents(this.container.node) : {};
  20. var pb = this.containerBounds;
  21. pb.height -= padding.top + padding.bottom;
  22. pb.width -= padding.left + padding.right;
  23. // used space
  24. var fit;
  25. for (var i=0, s=0, m, c; c=c$[i]; i++) {
  26. m = enyo.FittableLayout.calcMarginExtents(c.hasNode());
  27. c.width = c.getBounds().width;
  28. c.marginWidth = m.right + m.left;
  29. s += (c.fit ? 0 : c.width) + c.marginWidth;
  30. if (c.fit) {
  31. fit = c;
  32. }
  33. }
  34. if (fit) {
  35. var w = pb.width - s;
  36. fit.width = w >= 0 ? w : fit.width;
  37. }
  38. for (var i=0, e=padding.left, m, c; c=c$[i]; i++) {
  39. c.setBounds({top: padding.top, bottom: padding.bottom, width: c.fit ? c.width : null});
  40. }
  41. },
  42. arrange: function(inC, inName) {
  43. if (this.container.wrap) {
  44. this.arrangeWrap(inC, inName);
  45. } else {
  46. this.arrangeNoWrap(inC, inName);
  47. }
  48. },
  49. arrangeNoWrap: function(inC, inName) {
  50. var c$ = this.container.getPanels();
  51. var s = this.container.clamp(inName);
  52. var nw = this.containerBounds.width;
  53. // do we have enough content to fill the width?
  54. for (var i=s, cw=0, c; c=c$[i]; i++) {
  55. cw += c.width + c.marginWidth;
  56. if (cw > nw) {
  57. break;
  58. }
  59. }
  60. // if content width is less than needed, adjust starting point index and offset
  61. var n = nw - cw;
  62. var o = 0;
  63. if (n > 0) {
  64. var s1 = s;
  65. for (var i=s-1, aw=0, c; c=c$[i]; i--) {
  66. aw += c.width + c.marginWidth;
  67. if (n - aw <= 0) {
  68. o = (n - aw);
  69. s = i;
  70. break;
  71. }
  72. }
  73. }
  74. // arrange starting from needed index with detected offset so we fill space
  75. for (var i=0, e=this.containerPadding.left + o, w, c; c=c$[i]; i++) {
  76. w = c.width + c.marginWidth;
  77. if (i < s) {
  78. this.arrangeControl(c, {left: -w});
  79. } else {
  80. this.arrangeControl(c, {left: Math.floor(e)});
  81. e += w;
  82. }
  83. }
  84. },
  85. arrangeWrap: function(inC, inName) {
  86. for (var i=0, e=this.containerPadding.left, m, c; c=inC[i]; i++) {
  87. this.arrangeControl(c, {left: e});
  88. e += c.width + c.marginWidth;
  89. }
  90. },
  91. calcArrangementDifference: function(inI0, inA0, inI1, inA1) {
  92. var i = Math.abs(inI0 % this.c$.length);
  93. return inA0[i].left - inA1[i].left;
  94. },
  95. destroy: function() {
  96. var c$ = this.container.getPanels();
  97. for (var i=0, c; c=c$[i]; i++) {
  98. enyo.Arranger.positionControl(c, {left: null, top: null});
  99. c.applyStyle("top", null);
  100. c.applyStyle("bottom", null);
  101. c.applyStyle("left", null);
  102. c.applyStyle("width", null);
  103. }
  104. this.inherited(arguments);
  105. }
  106. });