2 * jLayout Border Layout - JavaScript Layout Algorithms v0.4
4 * Licensed under the new BSD License.
5 * Copyright 2008-2009, Bram Stein
10 jLayout = typeof jLayout === 'undefined' ? {} : jLayout;
12 jLayout.border = function (spec) {
21 my.hgap = spec.hgap || 0;
22 my.vgap = spec.vgap || 0;
24 that.items = function () {
48 that.layout = function (container) {
49 var size = container.bounds(),
50 insets = container.insets(),
52 bottom = size.height - insets.bottom,
54 right = size.width - insets.right,
57 if (north && north.isVisible()) {
58 tmp = north.preferredSize();
59 north.bounds({'x': left, 'y': top, 'width': right - left, 'height': tmp.height});
62 top += tmp.height + my.vgap;
64 if (south && south.isVisible()) {
65 tmp = south.preferredSize();
66 south.bounds({'x': left, 'y': bottom - tmp.height, 'width': right - left, 'height': tmp.height});
69 bottom -= tmp.height + my.vgap;
71 if (east && east.isVisible()) {
72 tmp = east.preferredSize();
73 east.bounds({'x': right - tmp.width, 'y': top, 'width': tmp.width, 'height': bottom - top});
76 right -= tmp.width + my.hgap;
78 if (west && west.isVisible()) {
79 tmp = west.preferredSize();
80 west.bounds({'x': left, 'y': top, 'width': tmp.width, 'height': bottom - top});
83 left += tmp.width + my.hgap;
85 if (center && center.isVisible()) {
86 center.bounds({'x': left, 'y': top, 'width': right - left, 'height': bottom - top});
92 function typeLayout(type) {
93 return function (container) {
94 var insets = container.insets(),
99 if (east && east.isVisible()) {
100 type_size = east[type + 'Size']();
101 width += type_size.width + my.hgap;
102 height = type_size.height;
104 if (west && west.isVisible()) {
105 type_size = west[type + 'Size']();
106 width += type_size.width + my.hgap;
107 height = Math.max(type_size.height, height);
109 if (center && center.isVisible()) {
110 type_size = center[type + 'Size']();
111 width += type_size.width;
112 height = Math.max(type_size.height, height);
114 if (north && north.isVisible()) {
115 type_size = north[type + 'Size']();
116 width = Math.max(type_size.width, width);
117 height += type_size.height + my.vgap;
119 if (south && south.isVisible()) {
120 type_size = south[type + 'Size']();
121 width = Math.max(type_size.width, width);
122 height += type_size.height + my.vgap;
126 'width': width + insets.left + insets.right,
127 'height': height + insets.top + insets.bottom
131 that.preferred = typeLayout('preferred');
132 that.minimum = typeLayout('minimum');
133 that.maximum = typeLayout('maximum');