2009-08-26 02:35:21 +00:00
|
|
|
var FloatedDivConstructor = Class.create({
|
2009-08-30 15:00:58 +00:00
|
|
|
'areas': ["header", "comic", "body", "footer"],
|
2009-08-26 02:35:21 +00:00
|
|
|
'generate_html': function(layout) {
|
|
|
|
var output = [];
|
|
|
|
output.push('<div id="container">');
|
|
|
|
|
|
|
|
var i, il;
|
|
|
|
|
|
|
|
var indent = 1;
|
2009-08-27 22:15:34 +00:00
|
|
|
var gi = function() { return " ".times(indent); }
|
|
|
|
var has_whole_sidebar = null;
|
2009-08-26 02:35:21 +00:00
|
|
|
|
2009-08-30 15:00:58 +00:00
|
|
|
var has_layout = {};
|
|
|
|
$w('left right').each(function(which) {
|
|
|
|
if (layout[which].active) {
|
|
|
|
has_layout[which] = [layout[which].start, layout[which].end];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-08-26 02:35:21 +00:00
|
|
|
var range = null;
|
2009-08-30 15:00:58 +00:00
|
|
|
if (has_layout.left) {
|
|
|
|
if (has_layout.right) {
|
2009-08-27 22:15:34 +00:00
|
|
|
range = [];
|
|
|
|
|
|
|
|
var all_same = true;
|
2009-08-30 15:00:58 +00:00
|
|
|
for (i = 0; i <= 1; ++i) {
|
|
|
|
if (has_layout.left[i] != has_layout.right[i]) { all_same = false; break; }
|
2009-08-27 22:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!all_same) {
|
|
|
|
$w('left right').each(function(field) {
|
|
|
|
if (!has_whole_sidebar) {
|
2009-08-30 15:00:58 +00:00
|
|
|
if ((has_layout[field][0] == 0) && (has_layout[field][1] == 3)) {
|
2009-08-27 22:15:34 +00:00
|
|
|
has_whole_sidebar = field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_whole_sidebar) {
|
2009-08-30 15:00:58 +00:00
|
|
|
range[0] = Math.min(has_layout.left[0], has_layout.right[0]);
|
|
|
|
range[1] = Math.max(has_layout.left[1], has_layout.right[1]);
|
2009-08-27 22:15:34 +00:00
|
|
|
} else {
|
|
|
|
switch (has_whole_sidebar) {
|
2009-08-30 15:00:58 +00:00
|
|
|
case 'left': range = has_layout.right; break;
|
|
|
|
case 'right': range = has_layout.left; break;
|
2009-08-27 22:15:34 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-26 02:35:21 +00:00
|
|
|
} else {
|
2009-08-30 15:00:58 +00:00
|
|
|
range = has_layout.left;
|
2009-08-26 02:35:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-08-30 15:00:58 +00:00
|
|
|
if (has_layout.right) {
|
|
|
|
range = has_layout.right;
|
2009-08-26 02:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-30 15:00:58 +00:00
|
|
|
for (i = 0, il = this.areas.length; i < il; ++i) {
|
2009-08-27 22:15:34 +00:00
|
|
|
if ((i == 0) && has_whole_sidebar) {
|
|
|
|
output.push(gi() + '<div id="whole-sidebar-container">');
|
|
|
|
indent++;
|
|
|
|
output.push(gi() + '<div id="' + has_whole_sidebar + '-sidebar"><?php echo $' + has_whole_sidebar + '_sidebar ?></div>');
|
|
|
|
}
|
2009-08-26 02:35:21 +00:00
|
|
|
if (range) {
|
|
|
|
if (range[0] == i) {
|
2009-08-27 22:15:34 +00:00
|
|
|
output.push(gi() + '<div id="sidebar-container">');
|
2009-08-26 02:35:21 +00:00
|
|
|
indent++;
|
|
|
|
}
|
|
|
|
$w("left right").each(function(field) {
|
2009-08-27 22:15:34 +00:00
|
|
|
if (field != has_whole_sidebar) {
|
2009-08-30 15:00:58 +00:00
|
|
|
if (has_layout[field]) {
|
|
|
|
if (has_layout[field][0] == i) {
|
2009-08-27 22:15:34 +00:00
|
|
|
output.push(gi() + '<div id="' + field + '-sidebar"><?php echo $' + field + '_sidebar ?></div>');
|
|
|
|
}
|
2009-08-26 02:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-08-30 15:00:58 +00:00
|
|
|
output.push(gi() + '<div id="' + this.areas[i] + '"><?php echo $' + this.areas[i] + ' ?></div>');
|
2009-08-26 02:35:21 +00:00
|
|
|
|
|
|
|
if (range) {
|
|
|
|
if (range[1] == i) {
|
2009-08-27 22:15:34 +00:00
|
|
|
output.push(gi() + '<br class="clear" />');
|
2009-08-26 02:35:21 +00:00
|
|
|
indent--;
|
2009-08-27 22:15:34 +00:00
|
|
|
output.push(gi() + '</div>');
|
2009-08-26 02:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-27 22:15:34 +00:00
|
|
|
if ((i == 3) && has_whole_sidebar) {
|
|
|
|
output.push(gi() + '<br class="clear" />');
|
|
|
|
indent--;
|
|
|
|
output.push(gi() + '</div>');
|
|
|
|
}
|
2009-08-26 02:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
output.push('</div>');
|
|
|
|
|
|
|
|
return output.join("\n");
|
|
|
|
},
|
2009-08-30 15:00:58 +00:00
|
|
|
'generate_css': function(layout) {
|
2009-08-26 02:35:21 +00:00
|
|
|
var output = [];
|
|
|
|
var include_container = false;
|
2009-08-30 15:00:58 +00:00
|
|
|
|
|
|
|
var area_margins = {};
|
|
|
|
var i;
|
|
|
|
var myThis = this;
|
|
|
|
|
2009-08-26 02:35:21 +00:00
|
|
|
$w('left right').each(function(field) {
|
2009-08-30 15:00:58 +00:00
|
|
|
if (layout[field].active) {
|
2009-08-26 02:35:21 +00:00
|
|
|
include_container = true;
|
2009-08-30 15:00:58 +00:00
|
|
|
output.push('#' + field + '-sidebar { float: ' + field + '; display: inline; width: ' + layout[field].width + 'px }');
|
|
|
|
|
|
|
|
for (i = layout[field].start; i <= layout[field].end; ++i) {
|
|
|
|
var area = myThis.areas[i];
|
|
|
|
if (!area_margins[area]) { area_margins[area] = {}; }
|
|
|
|
area_margins[area][field] = layout[field].width;
|
|
|
|
}
|
2009-08-26 02:35:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-08-30 15:00:58 +00:00
|
|
|
for (i = 0; i < this.areas.length; ++i) {
|
|
|
|
var area = this.areas[i];
|
|
|
|
if (area_margins[area]) {
|
|
|
|
var types = [];
|
|
|
|
var type;
|
|
|
|
for (type in area_margins[area]) {
|
|
|
|
types.push("margin-" + type + ": " + area_margins[area][type] + "px");
|
|
|
|
}
|
|
|
|
output.push("#" + area + " { " + types.join("; ") + " }");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-26 02:35:21 +00:00
|
|
|
if (include_container) {
|
2009-08-27 22:15:34 +00:00
|
|
|
output.unshift('#sidebar-container, #whole-sidebar-container { overflow: hidden }');
|
2009-08-26 02:35:21 +00:00
|
|
|
output.push('.clear { clear: both }');
|
|
|
|
}
|
|
|
|
|
2009-08-30 15:00:58 +00:00
|
|
|
if (layout.body) {
|
|
|
|
output.unshift('#container { width: ' + layout.body + 'px }');
|
|
|
|
}
|
|
|
|
|
2009-08-26 02:35:21 +00:00
|
|
|
return output.join("\n");
|
|
|
|
}
|
|
|
|
});
|