Delete the draggable when the "X" is clicked upon
Also apply syntax highlighting, draggabilty, and signals to the last added draggable in the iteration, not to all.
This commit is contained in:
parent
f987f79581
commit
569052a06e
1 changed files with 21 additions and 8 deletions
|
@ -11,15 +11,20 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// Populate the canvas with the draggables.
|
// Populate the canvas with the draggables.
|
||||||
$.get("draggables", function(data) {
|
$.get("draggables", function(data) {
|
||||||
|
var last_drag;
|
||||||
$.each(data, function(key, val) {
|
$.each(data, function(key, val) {
|
||||||
$.get("draggables/" + key, function(data) {
|
$.get("draggables/" + key, function(data) {
|
||||||
$("#draggables").append(data);
|
$("#draggables").append(data);
|
||||||
$(".draggable").draggable({ stack: ".draggable",
|
// Assume we have appended one draggable here:
|
||||||
|
last_drag = $(".draggable").last();
|
||||||
|
last_drag.draggable({ stack: ".draggable",
|
||||||
containment: "window",
|
containment: "window",
|
||||||
stop: update_drag_info });
|
stop: update_drag_info });
|
||||||
// FIXME: highlight text for now, until we can determine and
|
last_drag.find(".delete").click({ id: last_drag[0].id,
|
||||||
// store what everything exactly is.
|
element: last_drag },
|
||||||
$("pre code").each(function(idx, elem) {
|
delete_draggable);
|
||||||
|
// Highlight contained code.
|
||||||
|
last_drag.find("pre code").each(function(idx, elem) {
|
||||||
hljs.highlightBlock(elem, ' ');
|
hljs.highlightBlock(elem, ' ');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -30,13 +35,21 @@ $(document).ready(function() {
|
||||||
// Callback functions.
|
// Callback functions.
|
||||||
function show_add_dialog() {
|
function show_add_dialog() {
|
||||||
$('#add_dialog').fadeIn('slow');
|
$('#add_dialog').fadeIn('slow');
|
||||||
};
|
}
|
||||||
|
|
||||||
function hide_add_dialog() {
|
function hide_add_dialog() {
|
||||||
$("#add_dialog").fadeOut('fast', function() {
|
$("#add_dialog").fadeOut('fast', function() {
|
||||||
$("#add_form")[0].reset();
|
$("#add_form")[0].reset();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
function delete_draggable(event) {
|
||||||
|
drag_id = event.data.id
|
||||||
|
$.post("draggables/" + drag_id, {"_method": "delete"}, function(data) {
|
||||||
|
if (data)
|
||||||
|
event.data.element.remove();
|
||||||
|
}, "json");
|
||||||
|
}
|
||||||
|
|
||||||
function update_drag_info(event, ui) {
|
function update_drag_info(event, ui) {
|
||||||
$.post("draggables/" + ui.helper.context.id, ui.position, "json");
|
$.post("draggables/" + ui.helper.context.id, ui.position, "json");
|
||||||
|
|
Reference in a new issue