diff --git a/addons/Core/layout_constructors/FloatedDivConstructor.js b/addons/Core/layout_constructors/FloatedDivConstructor.js index 47787ae..01de19e 100644 --- a/addons/Core/layout_constructors/FloatedDivConstructor.js +++ b/addons/Core/layout_constructors/FloatedDivConstructor.js @@ -3,16 +3,43 @@ var FloatedDivConstructor = Class.create({ var output = []; output.push('
'); + var areas = $w("header comic body footer"); var i, il; var indent = 1; + var gi = function() { return " ".times(indent); } + var has_whole_sidebar = null; var range = null; if (layout.left) { if (layout.right) { - range[0] = Math.min(layout.left[0], layout.right[0]); - range[1] = Math.max(layout.left[1], layout.right[1]); + range = []; + + var all_same = true; + for (i = 0; i < 2; ++i) { + if (layout.left[i] != layout.right[i]) { all_same = false; break; } + } + + if (!all_same) { + $w('left right').each(function(field) { + if (!has_whole_sidebar) { + if ((layout[field][0] == 0) && (layout[field][1] == 3)) { + has_whole_sidebar = field; + } + } + }); + } + + if (!has_whole_sidebar) { + range[0] = Math.min(layout.left[0], layout.right[0]); + range[1] = Math.max(layout.left[1], layout.right[1]); + } else { + switch (has_whole_sidebar) { + case 'left': range = layout.right; break; + case 'right': range = layout.left; break; + } + } } else { range = layout.left; } @@ -23,29 +50,41 @@ var FloatedDivConstructor = Class.create({ } for (i = 0, il = areas.length; i < il; ++i) { + if ((i == 0) && has_whole_sidebar) { + output.push(gi() + '
'); + indent++; + output.push(gi() + '
'); + } if (range) { if (range[0] == i) { - output.push(" ".times(indent) + ''); } } + if ((i == 3) && has_whole_sidebar) { + output.push(gi() + '
'); + indent--; + output.push(gi() + '
'); + } } output.push('
'); @@ -64,7 +103,7 @@ var FloatedDivConstructor = Class.create({ }); if (include_container) { - output.unshift('#sidebar-container { overflow: hidden }'); + output.unshift('#sidebar-container, #whole-sidebar-container { overflow: hidden }'); output.push('.clear { clear: both }'); } diff --git a/addons/Core/layout_constructors/LayoutConstructorsTest.html b/addons/Core/layout_constructors/LayoutConstructorsTest.html index 0922e18..153fc6a 100644 --- a/addons/Core/layout_constructors/LayoutConstructorsTest.html +++ b/addons/Core/layout_constructors/LayoutConstructorsTest.html @@ -15,20 +15,69 @@ [ { 'input': {}, - 'expected_result': '
\n \n
\n
\n \n
' + 'expected_result': '
\n' + + ' \n' + + '
\n' + + '
\n' + + ' \n' + + '
' }, { 'input': {'left': [0, 0]}, - 'expected_result': '
\n \n
\n
\n \n
' + 'expected_result': '
\n' + + ' \n' + + '
\n' + + '
\n' + + ' \n' + + '
' }, { 'input': {'left': [0, 1]}, - 'expected_result': '
\n \n
\n \n
' + 'expected_result': '
\n' + + ' \n' + + '
\n' + + ' \n' + + '
' }, { 'input': {'right': [0, 1]}, - 'expected_result': '
\n \n
\n \n
' - } + 'expected_result': '
\n' + + ' \n' + + '
\n' + + ' \n' + + '
' + }, + { + 'input': {'left': [0, 3], 'right': [0, 1]}, + 'expected_result': '
\n' + + '
\n' + + ' \n' + + ' \n' + + '
\n' + + ' \n' + + '
\n' + + '
\n' + + '
' + }, ].each(function(info) { var f = new FloatedDivConstructor(); myThis.assertEqual(info.expected_result, f.generate_html(info.input)); @@ -44,11 +93,16 @@ }, { 'input': {'left': {'width': '200'}}, - 'expected_result': '#sidebar-container { overflow: hidden }\n#left-sidebar { float: left; display: inline; width: 200px }\n.clear { clear: both }' + 'expected_result': '#sidebar-container, #whole-sidebar-container { overflow: hidden }\n' + + '#left-sidebar { float: left; display: inline; width: 200px }\n' + + '.clear { clear: both }' }, { 'input': {'left': {'width': '200'}, 'right': {'width': '100'}}, - 'expected_result': '#sidebar-container { overflow: hidden }\n#left-sidebar { float: left; display: inline; width: 200px }\n#right-sidebar { float: right; display: inline; width: 100px }\n.clear { clear: both }' + 'expected_result': '#sidebar-container, #whole-sidebar-container { overflow: hidden }\n' + + '#left-sidebar { float: left; display: inline; width: 200px }\n' + + '#right-sidebar { float: right; display: inline; width: 100px }\n' + + '.clear { clear: both }' } ].each(function(info) { var f = new FloatedDivConstructor();