2013-09-11 12:37:09 +02:00
|
|
|
$(function() {
|
2013-09-12 15:21:54 +02:00
|
|
|
|
|
|
|
$(".content-container-header").each(function() {
|
|
|
|
$(this).css("background-color", "hsla(" + Math.round(Math.random() * 360) + ", 100%, 50%, 1);");
|
|
|
|
});
|
|
|
|
|
2013-09-11 13:36:03 +02:00
|
|
|
//setup the draggable content containers
|
2013-09-11 16:25:43 +02:00
|
|
|
$(".content-container-bounding-box").draggable({
|
2013-09-11 13:36:03 +02:00
|
|
|
"distance": 10,
|
|
|
|
"handle": "h1",
|
|
|
|
"helper": "clone",
|
|
|
|
"revert": "invalid",
|
|
|
|
"revertDuration": 50,
|
|
|
|
"scope": "widget",
|
|
|
|
"scroll": false,
|
2013-09-12 15:23:02 +02:00
|
|
|
"snap": false,
|
2013-09-11 13:36:03 +02:00
|
|
|
"start": function(event, ui) {
|
|
|
|
//set width and height of dragged clone to originals dimensions
|
|
|
|
$(ui.helper[0]).width(event.target.clientWidth).height(event.target.clientHeight);
|
|
|
|
//change opacity of original to indicate it is being dragged
|
2013-09-12 15:23:02 +02:00
|
|
|
$(event.target).css("opacity", "0.25");
|
2013-09-11 13:36:03 +02:00
|
|
|
//also change opacity of dragged clone to help the user see
|
2013-09-12 15:23:02 +02:00
|
|
|
$(ui.helper[0]).css("opacity", "0.5");
|
2013-09-11 13:36:03 +02:00
|
|
|
},
|
|
|
|
"stop": function(event, ui) {
|
|
|
|
//reset opacity of original
|
|
|
|
$(event.target).css("opacity", "");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//setup the dropzones
|
2013-09-12 15:23:02 +02:00
|
|
|
//put the dragged object into first position of a column
|
2013-09-11 13:36:03 +02:00
|
|
|
$(".content-column").droppable({
|
2013-09-11 15:42:39 +02:00
|
|
|
"greedy": false,
|
2013-09-11 13:36:03 +02:00
|
|
|
"scope": "widget",
|
|
|
|
"tolerance": "pointer",
|
|
|
|
"drop": function(event, ui) {
|
2013-09-11 16:25:43 +02:00
|
|
|
$("#draggable-temporary-clone").remove();
|
2013-09-12 15:23:02 +02:00
|
|
|
$(ui.draggable[0]).prependTo($(event.target));
|
2013-09-11 13:36:03 +02:00
|
|
|
},
|
|
|
|
"over": function(event, ui) {
|
2013-09-11 16:25:43 +02:00
|
|
|
$("#draggable-temporary-clone").remove();
|
2013-09-12 15:23:02 +02:00
|
|
|
//create a placeholder and mark it with an id (so we can remove it later)
|
|
|
|
$(".droppable-container-placeholder")
|
|
|
|
.clone(true)
|
|
|
|
.width(ui.draggable[0].clientWidth)
|
|
|
|
.height(ui.draggable[0].clientHeight)
|
|
|
|
.attr("id", "draggable-temporary-clone")
|
|
|
|
.prependTo(event.target);
|
2013-09-11 15:42:39 +02:00
|
|
|
},
|
|
|
|
"out": function(event, ui) {
|
2013-09-11 16:25:43 +02:00
|
|
|
$("#draggable-temporary-clone").remove();
|
2013-09-11 15:42:39 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-12 15:23:02 +02:00
|
|
|
//put the dragged object into a slot after the object it was dropped on
|
2013-09-11 15:42:39 +02:00
|
|
|
$(".content-container-bounding-box").droppable({
|
|
|
|
"greedy": true,
|
|
|
|
"scope": "widget",
|
|
|
|
"tolerance": "pointer",
|
|
|
|
"drop": function(event, ui) {
|
2013-09-11 16:25:43 +02:00
|
|
|
$("#draggable-temporary-clone").remove();
|
|
|
|
$(ui.draggable[0]).insertAfter(event.target);
|
2013-09-11 15:42:39 +02:00
|
|
|
},
|
|
|
|
"over": function(event, ui) {
|
2013-09-11 16:25:43 +02:00
|
|
|
$("#draggable-temporary-clone").remove();
|
2013-09-12 15:23:02 +02:00
|
|
|
//create a placeholder and mark it with an id (so we can remove it later)
|
|
|
|
$(".droppable-container-placeholder")
|
|
|
|
.clone(true)
|
|
|
|
.width(ui.draggable[0].clientWidth)
|
|
|
|
.height(ui.draggable[0].clientHeight)
|
|
|
|
.attr("id", "draggable-temporary-clone")
|
|
|
|
.insertAfter(event.target);
|
2013-09-11 13:36:03 +02:00
|
|
|
},
|
|
|
|
"out": function(event, ui) {
|
2013-09-11 16:25:43 +02:00
|
|
|
$("#draggable-temporary-clone").remove();
|
2013-09-11 13:36:03 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-11 12:37:09 +02:00
|
|
|
});
|