-
Notifications
You must be signed in to change notification settings - Fork 19
/
angular-dnd.min.js
2 lines (2 loc) · 2.72 KB
/
angular-dnd.min.js
1
2
angular.module("dragAndDrop",[]).directive("drag",["dndApi",function(a){var b=[],c=function(a,b){if(b>5)return!1;var d=a.parent();return d.hasClass("drop")?d[0]:(b++,c(d,b))},d=[],e=["start","end","ngModel"];return{restrict:"A",link:function(f,g,h){d.push(g);var i={};if(angular.forEach(e,function(a){h[a]&&(i[a]=f.$eval(h[a]))}),!angular.isUndefined(i.ngModel)){var j=g[0];j.addEventListener("dragstart",function(d){0===b.length&&(b=document.querySelectorAll(".drop")),angular.forEach(a.areas(),function(a){a[0]!==c(g,0)&&a.addClass("dropable")}),g.addClass("dragging"),a.setData(i.ngModel,g),(d.originalEvent||d).dataTransfer.effectAllowed="move",(d.originalEvent||d).dataTransfer.setData("text","test"),angular.isFunction(i.start)&&f.$apply(function(){i.start(a.getData(),g)})}),j.addEventListener("dragend",function(){g.removeClass("dragging"),angular.forEach(a.areas(),function(a){a.removeClass("dropable")}),angular.forEach(d,function(a){a.removeClass("hover")}),angular.isFunction(i.end)&&f.$apply(function(){i.end(a.getData(),g)}),a.clear()});var k=!1;j.addEventListener("dragover",function(a){return a.preventDefault&&a.preventDefault(),k||(g.addClass("hover"),k=!0),!1}),j.addEventListener("dragleave",function(a){return a.preventDefault&&a.preventDefault(),k&&(g.removeClass("hover"),k=!1),!1}),j.draggable=!0,g.addClass("drag")}}}}]).directive("drop",["dndApi",function(a){var b=["drop","enter","leave"];return{link:function(c,d,e){var f={},g=d[0],h=g.offsetLeft,i=h+g.offsetWidth,j=g.offsetTop,k=j+g.offsetHeight,l=c.$eval(e.ngModel);angular.forEach(b,function(a){e[a]&&(f[a]=c.$eval(e[a]))}),a.addArea(d),g.addEventListener("drop",function(b){b.preventDefault&&b.preventDefault();var e=a.getData();d.hasClass("dropable")&&(angular.isFunction(f.drop)&&c.$apply(function(){l?f.drop(e.data,l,e.element):f.drop(e.data,e.element)}),angular.forEach(a.areas(),function(a){a.addClass("dropable"),a.removeClass("hover")}),d.removeClass("hover"),a.clear())});var m=!1;g.addEventListener("dragenter",function(b){m||(d.addClass("hover"),m=!0),g===b.target&&angular.isFunction(f.enter)&&c.$apply(function(){var b=a.getData();f.enter(b.data,b.element)})}),g.addEventListener("dragleave",function(b){m&&(d.removeClass("hover"),m=!1),(b.x<h||b.x>i||b.y<j||b.y>k)&&angular.isFunction(f.leave)&&c.$apply(function(){var b=a.getData();f.leave(b.data,b.element)})}),g.addEventListener("dragover",function(a){return m||(d.addClass("hover"),m=!0),a.preventDefault&&a.preventDefault(),!1}),d.addClass("drop")}}}]).factory("dndApi",function(){var a={dragObject:{}},b=[];return{addArea:function(a){b.push(a)},areas:function(){return b},setData:function(b,c){a.drag={data:b,element:c}},clear:function(){delete a.drag},getData:function(){return a.drag}}});
//# sourceMappingURL=angular-dnd.min.js.map