Created
July 6, 2013 21:39
-
-
Save vogon/5941393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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