forked from marceljuenemann/angular-drag-and-drop-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-drag-and-drop-lists.min.js
1 lines (1 loc) · 3.2 KB
/
angular-drag-and-drop-lists.min.js
1
angular.module("dndLists",[]).directive("dndDraggable",["$parse","$timeout","dndDropEffectWorkaround","dndDragTypeWorkaround",function(d,b,c,a){return function(g,f,e){f.attr("draggable","true");if(e.dndDisableIf){g.$watch(e.dndDisableIf,function(h){f.attr("draggable",!h)})}f.on("dragstart",function(h){h=h.originalEvent||h;h.dataTransfer.setData("Text",angular.toJson(g.$eval(e.dndDraggable)));h.dataTransfer.effectAllowed=e.dndEffectAllowed||"move";f.addClass("dndDragging");b(function(){f.addClass("dndDraggingSource")},0);c.dropEffect="none";a.isDragging=true;a.dragType=e.dndType?g.$eval(e.dndType):undefined;h.stopPropagation()});f.on("dragend",function(h){h=h.originalEvent||h;var i=h.dataTransfer.dropEffect!=="none"?h.dataTransfer.dropEffect:c.dropEffect;i=c.dropEffect;g.$apply(function(){switch(i){case"move":d(e.dndMoved)(g);break;case"copy":d(e.dndCopied)(g);break}});f.removeClass("dndDragging");f.removeClass("dndDraggingSource");a.isDragging=false;h.stopPropagation()});f.on("click",function(h){h=h.originalEvent||h;g.$apply(function(){d(e.dndSelected)(g)});h.stopPropagation()});f.on("selectstart",function(){if(this.dragDrop){this.dragDrop()}return false})}}]).directive("dndList",["$timeout","dndDropEffectWorkaround","dndDragTypeWorkaround",function(b,c,a){return function(g,f,d){var i=angular.element("<li class='dndPlaceholder'></li>");var j=i[0];var h=f[0];f.on("dragover",function(k){k=k.originalEvent||k;if(!a.isDragging){return true}if(!e(k.dataTransfer.types)){return true}if(d.dndAllowedTypes){var m=g.$eval(d.dndAllowedTypes);if(angular.isArray(m)&&m.indexOf(a.dragType)===-1){return true}}if(d.dndDisableIf&&g.$eval(d.dndDisableIf)){return true}if(j.parentNode!=h){f.append(i)}if(k.target.parentNode===h&&k.target!==j){var l=(k.offsetY||k.layerY)<k.target.offsetHeight/2;h.insertBefore(j,l?k.target:k.target.nextSibling)}else{if(k.target===h){if(k.offsetY<j.offsetTop){while(j.previousElementSibling&&(j.previousElementSibling.offsetHeight===0||k.offsetY<j.previousElementSibling.offsetTop+j.previousElementSibling.offsetHeight/2)){h.insertBefore(j,j.previousElementSibling)}}else{while(j.nextElementSibling&&k.offsetY>j.nextElementSibling.offsetTop+j.nextElementSibling.offsetHeight/2){h.insertBefore(j,j.nextElementSibling.nextElementSibling)}}}}f.addClass("dndDragover");k.preventDefault();k.stopPropagation();return false});f.on("drop",function(l){l=l.originalEvent||l;var n=JSON.parse(l.dataTransfer.getData("Text")||l.dataTransfer.getData("text/plain"));var m=g.$eval(d.dndList);var k=Array.prototype.indexOf.call(h.children,j);g.$apply(function(){m.splice(k,0,n)});if(l.dataTransfer.dropEffect==="none"){c.dropEffect=l.dataTransfer.effectAllowed==="copyMove"?(l.ctrlKey?"copy":"move"):l.dataTransfer.effectAllowed}else{c.dropEffect=l.dataTransfer.dropEffect}i.remove();f.removeClass("dndDragover");l.preventDefault();l.stopPropagation();return false});f.on("dragleave",function(k){k=k.originalEvent||k;f.removeClass("dndDragover");b(function(){if(!f.hasClass("dndDragover")){i.remove()}},100)});function e(l){if(!l){return true}for(var k=0;k<l.length;k++){if(l[k]==="Text"||l[k]==="text/plain"){return true}}return false}}}]).factory("dndDragTypeWorkaround",function(){return{}}).factory("dndDropEffectWorkaround",function(){return{}});