diff --git a/bower.json b/bower.json index 87e6edd..7640d7a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-ui-sortable", - "version": "0.14.0", + "version": "0.14.1", "description": "This directive allows you to jQueryUI Sortable.", "author": "https://github.com/angular-ui/ui-sortable/graphs/contributors", "license": "MIT", diff --git a/package.json b/package.json index 3ae2478..f2d8b50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-ui-sortable", - "version": "0.14.0", + "version": "0.14.1", "description": "This directive allows you to jQueryUI Sortable.", "author": "https://github.com/angular-ui/ui-sortable/graphs/contributors", "license": "MIT", diff --git a/src/sortable.js b/src/sortable.js index 179e5a1..19f3770 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -209,10 +209,10 @@ angular.module('ui.sortable', []) // return the index of ui.item among the items // we can't just do ui.item.index() because there it might have siblings // which are not items - function getItemIndex(ui) { - return ui.item.parent() + function getItemIndex(item) { + return item.parent() .find(opts['ui-model-items']) - .index(ui.item); + .index(item); } var opts = {}; @@ -266,7 +266,7 @@ angular.module('ui.sortable', []) } // Save the starting position of dragged item - var index = getItemIndex(ui); + var index = getItemIndex(ui.item); ui.item.sortable = { model: ngModel.$modelValue[index], index: index, @@ -322,7 +322,7 @@ angular.module('ui.sortable', []) // update that happens when moving between lists because then // the value will be overwritten with the old value if(!ui.item.sortable.received) { - ui.item.sortable.dropindex = getItemIndex(ui); + ui.item.sortable.dropindex = getItemIndex(ui.item); var droptarget = ui.item.parent(); ui.item.sortable.droptarget = droptarget; @@ -431,7 +431,24 @@ angular.module('ui.sortable', []) wrappers.helper = function (inner) { if (inner && typeof inner === 'function') { return function (e, item) { + var oldItemSortable = item.sortable; + var index = getItemIndex(item); + item.sortable = { + model: ngModel.$modelValue[index], + index: index, + source: item.parent(), + sourceModel: ngModel.$modelValue, + _restore: function () { + angular.forEach(item.sortable, function(value, key) { + item.sortable[key] = undefined; + }); + + item.sortable = oldItemSortable; + } + }; + var innerResult = inner.apply(this, arguments); + item.sortable._restore(); item.sortable._isCustomHelperUsed = item !== innerResult; return innerResult; }; diff --git a/test/sortable.e2e.callbacks.spec.js b/test/sortable.e2e.callbacks.spec.js index a762106..9057388 100644 --- a/test/sortable.e2e.callbacks.spec.js +++ b/test/sortable.e2e.callbacks.spec.js @@ -457,6 +457,64 @@ describe('uiSortable', function() { }); }); + it('should provide the item.sortable properties on helper callback', function() { + inject(function($compile, $rootScope) { + var element, helperItem, itemSortable_Restore, sortableAfterRestore, helperCallbackExpectations; + element = $compile(''.concat( + '