I’m looking for some advice on a project I am working on and would be appreciative of any assistance.
To make a drag and drop CMS which allows a user to d
Is it possible to devise a set of rules to convert an absolute layout to a floated one?
Not impossible but extremely difficult to implement.
If so are there any existing CMS that do it?
Not that I am aware of.
Any suggestions on other ways to tackle this issue?
I find it easier to think of layouts as a bunch of rows and columns, floated appropriately. So, for this layout:
I would generate HTML markup similar to this (simplified for understanding):
Content 1
Content 2
Content 3
Content 4
Content 5
Content 6
You will need to provide a UI where a user can:
You can then name the rows, columns and/or content elements and use CSS to adjust their widths. Here is a proof-of-concept:
$(function() {
$(".insertable").draggable({ revert: "invalid" });
$(".insertzone").droppable({ activeClass: "acceptable", drop: handleInsert, accept: ".insertable-box, .insertable-row" });
$(".removezone").droppable({ activeClass: "acceptable", drop: handleRemove, accept: ".removable" });
function handleInsert(event, ui) {
ui.draggable.css({ left: 0, top: 0 });
var $div = $("").appendTo(this).draggable({ revert: "invalid" });
if (ui.draggable.hasClass("insertable-box")) {
$div.addClass("box").text("Lorem ipsum dolor sit amet.");
}
if (ui.draggable.hasClass("insertable-row")) {
$div.addClass("row").droppable({ activeClass: "acceptable", drop: handleInsert, greedy: true, accept: ".insertable-col" }); ;
}
if (ui.draggable.hasClass("insertable-col")) {
$div.addClass("col").addClass(ui.draggable.find("select").val()).droppable({ activeClass: "acceptable", drop: handleInsert, greedy: true, accept: ".insertable-box, .insertable-row" });
}
}
function handleRemove(event, ui) {
ui.draggable.remove();
}
});
/* INTERFACE */
body { font: medium/1 monospace; }
select { font: inherit; margin: -1em 0; border: 0; padding: 0; }
.insertzone { margin: 1em 0; box-shadow: 0 0 .25em #CCC; }
.removezone { margin: 1em 0; box-shadow: 0 0 .25em #CCC; }
.insertable { cursor: move; display: inline-block; padding: 1em 4em; background-color: #CCC; }
.removable { cursor: move; }
.acceptable { background-color: #FEA !important; }
.insertzone .box { background-color: #EFD; }
.insertzone .row { background-color: #FEE; }
.insertzone .col { background-color: #FFD; }
.insertzone .box:after { display: block; padding: 1em; text-align: center; content: "box"; color: #CCC; margin-bottom: -1em; }
.insertzone .row:after { display: block; padding: 1em; text-align: center; content: "row"; color: #CCC; }
.insertzone .col:after { display: block; padding: 1em; text-align: center; content: "col"; color: #CCC; min-width: 8em; }
.insertzone:after { display: block; padding: 1em; text-align: center; content: "Drag here to insert"; }
.removezone:after { display: block; padding: 1em; text-align: center; content: "Drag here to remove"; }
/* LAYOUT */
.box { margin: 1em 0; padding: 1em; }
.row { margin: 1em 0; }
.row:after { display: block; clear: both; content: ""; }
.col { float: left; }
.col > * { margin-left: .5em; margin-right: .5em; }
.col:first-child > * { margin-left: 0; }
.col:last-child > * { margin-right: 0; }
.col > *:first-child { margin-top: 0; }
.col > *:last-child { margin-bottom: 0; }
.col-10 { width: 10%; }
.col-20 { width: 20%; }
.col-30 { width: 30%; }
.col-40 { width: 40%; }
.col-50 { width: 50%; }
.col-60 { width: 60%; }
.col-70 { width: 70%; }
.col-80 { width: 80%; }
.col-90 { width: 90%; }
box
row
col
And here is your layout, designed using this tool: