diff --git a/src/sortable.js b/src/sortable.js index 85f1f74..14c2679 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -19,9 +19,9 @@ angular.module('ui.sortable', []) function combineCallbacks(first,second){ if(second && (typeof second === 'function')) { - return function(e, ui) { - first(e, ui); - second(e, ui); + return function() { + first.apply(this, arguments); + second.apply(this, arguments); }; } return first; @@ -286,7 +286,7 @@ angular.module('ui.sortable', []) wrappers.helper = function (inner) { if (inner && typeof inner === 'function') { return function (e, item) { - var innerResult = inner(e, item); + var innerResult = inner.apply(this, arguments); item.sortable._isCustomHelperUsed = item !== innerResult; return innerResult; }; diff --git a/test/sortable.e2e.callbacks.spec.js b/test/sortable.e2e.callbacks.spec.js index ae4ceb5..37825b9 100644 --- a/test/sortable.e2e.callbacks.spec.js +++ b/test/sortable.e2e.callbacks.spec.js @@ -270,6 +270,81 @@ describe('uiSortable', function() { }); }); + it('should call all callbacks with the proper context', function() { + inject(function($compile, $rootScope) { + var element, callbackContexts = {}; + $rootScope.$apply(function() { + $rootScope.opts = { + helper: function(e, item) { + callbackContexts.helper = this; + return item; + }, + create: function() { + callbackContexts.create = this; + }, + start: function() { + callbackContexts.start = this; + }, + activate: function() { + callbackContexts.activate = this; + }, + beforeStop: function() { + callbackContexts.beforeStop = this; + }, + update: function() { + callbackContexts.update = this; + }, + deactivate: function() { + callbackContexts.deactivate = this; + }, + stop: function() { + callbackContexts.stop = this; + } + }; + spyOn($rootScope.opts, 'helper').andCallThrough(); + spyOn($rootScope.opts, 'create').andCallThrough(); + spyOn($rootScope.opts, 'start').andCallThrough(); + spyOn($rootScope.opts, 'activate').andCallThrough(); + spyOn($rootScope.opts, 'beforeStop').andCallThrough(); + spyOn($rootScope.opts, 'update').andCallThrough(); + spyOn($rootScope.opts, 'deactivate').andCallThrough(); + spyOn($rootScope.opts, 'stop').andCallThrough(); + $rootScope.items = ['One', 'Two', 'Three']; + element = $compile('