Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #501 from thgreasi/fix1.6AlternativeDirectiveDecla…
Browse files Browse the repository at this point in the history
…rations

fix(sortable): restore support for data-ui-sortable declaration
  • Loading branch information
thgreasi authored Dec 16, 2016
2 parents 90d2672 + e4112a6 commit 6cfe4e1
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-ui-sortable",
"version": "0.16.0",
"version": "0.16.1",
"description": "This directive allows you to jQueryUI Sortable.",
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-ui-sortable",
"version": "0.16.0",
"version": "0.16.1",
"description": "This directive allows you to jQueryUI Sortable.",
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ angular.module('ui.sortable', [])
// the value will be overwritten with the old value
if(!ui.item.sortable.received) {
ui.item.sortable.dropindex = getItemIndex(ui.item);
var droptarget = ui.item.closest('[ui-sortable]');
var droptarget = ui.item.closest('[ui-sortable], [data-ui-sortable], [x-ui-sortable]');
ui.item.sortable.droptarget = droptarget;
ui.item.sortable.droptargetList = ui.item.parent();

Expand Down
86 changes: 86 additions & 0 deletions test/sortable.e2e.multi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,92 @@ describe('uiSortable', function() {
});
});

it('should properly set ui.item.sortable.droptargetModel when using data-ui-sortable', function() {
inject(function($compile, $rootScope) {
var elementTop, elementBottom, updateCallbackExpectations;
elementTop = $compile(''.concat(
'<ul data-ui-sortable="opts" class="cross-sortable" data-ng-model="itemsTop">',
beforeLiElement,
'<li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li>',
afterLiElement,
'</ul>'))($rootScope);
elementBottom = $compile(''.concat(
'<ul data-ui-sortable="opts" class="cross-sortable" data-ng-model="itemsBottom">',
beforeLiElement,
'<li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li>',
afterLiElement,
'</ul>'))($rootScope);
$rootScope.$apply(function() {
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
$rootScope.opts = {
connectWith: '.cross-sortable',
update: function(e, ui) {
if (ui.item.sortable.model &&
(typeof ui.item.sortable.model === 'string') &&
ui.item.sortable.model.indexOf('Two') >= 0) {
ui.item.sortable.cancel();
}
updateCallbackExpectations(ui.item.sortable);
}
};
});

host.append(elementTop).append(elementBottom).append('<div class="clear"></div>');

var li1 = elementTop.find('[ng-repeat]:eq(1)');
var li2 = elementBottom.find('[ng-repeat]:eq(0)');
updateCallbackExpectations = function(uiItemSortable) {
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsBottom);
};
simulateElementDrag(li1, li2, { place: 'below', extradx: -20, extrady: -11 });
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
updateCallbackExpectations = undefined;

li1 = elementBottom.find('[ng-repeat]:eq(1)');
li2 = elementTop.find('[ng-repeat]:eq(1)');
updateCallbackExpectations = function(uiItemSortable) {
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsTop);
};
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -11 });
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
updateCallbackExpectations = undefined;

li1 = elementTop.find('[ng-repeat]:eq(0)');
li2 = elementBottom.find('[ng-repeat]:eq(0)');
updateCallbackExpectations = function(uiItemSortable) {
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsBottom);
};
simulateElementDrag(li1, li2, 'below');
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
updateCallbackExpectations = undefined;

li1 = elementBottom.find('[ng-repeat]:eq(1)');
li2 = elementTop.find('[ng-repeat]:eq(1)');
updateCallbackExpectations = function(uiItemSortable) {
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsTop);
};
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -11 });
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
updateCallbackExpectations = undefined;

$(elementTop).remove();
$(elementBottom).remove();
});
});

it('should properly set ui.item.sortable.droptargetModel when sorting between different scopes', function() {
inject(function($compile, $rootScope) {
var elementTop, elementBottom,
Expand Down

0 comments on commit 6cfe4e1

Please sign in to comment.