Skip to content

Instantly share code, notes, and snippets.

@arunsivasankaran
Created November 19, 2014 16:30
Show Gist options
  • Save arunsivasankaran/2044d998e7f4e65a39da to your computer and use it in GitHub Desktop.
Save arunsivasankaran/2044d998e7f4e65a39da to your computer and use it in GitHub Desktop.
Simple Drag and Drop
var Module = angular.module('simple-drag-drop', []);
Module.directive('draggable', function(draggingStudent) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.draggable({
revert: "invalid",
helper:"clone",
start: function() {
// <foo draggable on-drag='thingsThatsdragging=student'>
scope.$eval(attrs.onDragstart);
draggingStudent.student = scope.student;
draggingStudent.cohort = scope.cohort;
$(this).addClass("dragging")
},
stop: function() {
scope.$eval(attrs.onStop);
// $(this).removeClass("dragging")
},
drag: function() {
scope.$eval(attrs.onDrag);
$(this).addClass("dragging")
}
});
}
}
});
Module.directive('droppable', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.droppable({
hoverClass: "draghover",
drop: function() {
scope.$eval(attrs.onDrop);
$(".dragging").removeClass("dragging");
}
})
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment