Skip to content

Instantly share code, notes, and snippets.

@vogon
Created July 6, 2013 21:39
Show Gist options
  • Save vogon/5941393 to your computer and use it in GitHub Desktop.
Save vogon/5941393 to your computer and use it in GitHub Desktop.
function handleMagnetDragOver(e) {
// alert("dragover");
if ($(e.target).hasClass("poem-row-words") ||
$(e.target).parents().hasClass("poem-row-words")) {
if (e.preventDefault) {
e.preventDefault();
}
e.originalEvent.dataTransfer.dropEffect = 'move';
return false;
} else {
return true;
}
}
function handleMagnetDrop(e) {
// alert("drop");
// run through all the words in this line of the poem, drop in order
var dropX, dropY;
dropX = e.originalEvent.x;
dropY = e.originalEvent.y;
var realDropTarget = $(e.target).closest(".poem-row-words");
for (var childIndex = 0; childIndex < realDropTarget.children().length; childIndex++) {
var child = $(realDropTarget.children()[childIndex]);
if (dropX < $(child).position().left) {
console.log("drop X (" + dropX + ") before child " + childIndex + " X (" + $(child).position().left + ")");
$(child).before(draggingMagnet);
return false;
} else {
console.log("drop X (" + dropX + ") after child " + childIndex + " X (" + $(child).position().left + ")");
}
}
console.log("drop X (" + dropX + ") after all children, appending");
$(realDropTarget).append(draggingMagnet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment