From 8a27535980a09d17ead53c087afb40166b087882 Mon Sep 17 00:00:00 2001 From: Peter Orolin Date: Mon, 27 Feb 2017 15:20:59 +0100 Subject: [PATCH] revert item to the origin place if it is outside of drop objects --- src/angular-dragdrop.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/angular-dragdrop.js b/src/angular-dragdrop.js index 5522936..99c3361 100644 --- a/src/angular-dragdrop.js +++ b/src/angular-dragdrop.js @@ -356,6 +356,8 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti if (newValue) { dropSettings = scope.$eval($(element).attr('jqyoui-droppable') || $(element).attr('data-jqyoui-droppable')) || {}; jqyouiOptions = scope.$eval(attrs.jqyouiOptions) || {}; + + var wasDropped = false element .droppable({disabled: false}) .droppable(jqyouiOptions) @@ -366,7 +368,14 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti out: function(event, ui) { ngDragDropService.callEventCallback(scope, dropSettings.onOut, event, ui); }, + deactivate: function(event, ui) { + if (!wasDropped && dropSettings.revertFromOutside) { + ui.draggable.animate({left: '', top: ''}, jqyouiOptions.revertDuration || 0); + } + wasDropped = false + }, drop: function(event, ui) { + wasDropped = true var beforeDropPromise = null; if (dropSettings.beforeDrop) { @@ -417,3 +426,4 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti return element.getAttribute(name) || element.getAttribute('data-' + name); }; })(window, window.angular, window.jQuery); +