Last active
December 10, 2015 09:39
-
-
Save martin-wintz/4416122 to your computer and use it in GitHub Desktop.
Changes to ui-sortable for compatibility with ConnectWith option.
This file contains hidden or 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
onStart = (e, ui) -> | |
# Save position of dragged item, original model, and original element parent | |
ui.item.data('ui-sortable-start', ui.item.index()) | |
ui.item.data('ui-sortable-start-model', ngModel) | |
ui.item.data('ui-sortable-start-parent', ui.item.context.parentElement) | |
onUpdate = (e, ui) -> | |
# Fetch saved and current position of dropped element | |
start = ui.item.data('ui-sortable-start') | |
end = ui.item.index() | |
# Only sort if the original and target parent elements are the same | |
startParent = ui.item.data('ui-sortable-start-parent') | |
if startParent is ui.item.context.parentElement | |
# Reorder array and apply change to scope | |
ngModel.$modelValue.splice(end, 0, ngModel.$modelValue.splice(start, 1)[0]) | |
onReceive = (e, ui) -> | |
start = ui.item.data('ui-sortable-start') | |
end = ui.item.index() | |
startModel = ui.item.data('ui-sortable-start-model') | |
# Remove the element from the start array and insert it in this one in the correct order | |
ngModel.$modelValue.splice(end, 0, startModel.$modelValue.splice(start, 1)[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment