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

Commit 6cfe4e1

Browse files
authored
Merge pull request #501 from thgreasi/fix1.6AlternativeDirectiveDeclarations
fix(sortable): restore support for data-ui-sortable declaration
2 parents 90d2672 + e4112a6 commit 6cfe4e1

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.16.0",
3+
"version": "0.16.1",
44
"description": "This directive allows you to jQueryUI Sortable.",
55
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
66
"license": "MIT",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.16.0",
3+
"version": "0.16.1",
44
"description": "This directive allows you to jQueryUI Sortable.",
55
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
66
"license": "MIT",

src/sortable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ angular.module('ui.sortable', [])
324324
// the value will be overwritten with the old value
325325
if(!ui.item.sortable.received) {
326326
ui.item.sortable.dropindex = getItemIndex(ui.item);
327-
var droptarget = ui.item.closest('[ui-sortable]');
327+
var droptarget = ui.item.closest('[ui-sortable], [data-ui-sortable], [x-ui-sortable]');
328328
ui.item.sortable.droptarget = droptarget;
329329
ui.item.sortable.droptargetList = ui.item.parent();
330330

test/sortable.e2e.multi.spec.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,92 @@ describe('uiSortable', function() {
947947
});
948948
});
949949

950+
it('should properly set ui.item.sortable.droptargetModel when using data-ui-sortable', function() {
951+
inject(function($compile, $rootScope) {
952+
var elementTop, elementBottom, updateCallbackExpectations;
953+
elementTop = $compile(''.concat(
954+
'<ul data-ui-sortable="opts" class="cross-sortable" data-ng-model="itemsTop">',
955+
beforeLiElement,
956+
'<li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li>',
957+
afterLiElement,
958+
'</ul>'))($rootScope);
959+
elementBottom = $compile(''.concat(
960+
'<ul data-ui-sortable="opts" class="cross-sortable" data-ng-model="itemsBottom">',
961+
beforeLiElement,
962+
'<li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li>',
963+
afterLiElement,
964+
'</ul>'))($rootScope);
965+
$rootScope.$apply(function() {
966+
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
967+
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
968+
$rootScope.opts = {
969+
connectWith: '.cross-sortable',
970+
update: function(e, ui) {
971+
if (ui.item.sortable.model &&
972+
(typeof ui.item.sortable.model === 'string') &&
973+
ui.item.sortable.model.indexOf('Two') >= 0) {
974+
ui.item.sortable.cancel();
975+
}
976+
updateCallbackExpectations(ui.item.sortable);
977+
}
978+
};
979+
});
980+
981+
host.append(elementTop).append(elementBottom).append('<div class="clear"></div>');
982+
983+
var li1 = elementTop.find('[ng-repeat]:eq(1)');
984+
var li2 = elementBottom.find('[ng-repeat]:eq(0)');
985+
updateCallbackExpectations = function(uiItemSortable) {
986+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsBottom);
987+
};
988+
simulateElementDrag(li1, li2, { place: 'below', extradx: -20, extrady: -11 });
989+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
990+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
991+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
992+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
993+
updateCallbackExpectations = undefined;
994+
995+
li1 = elementBottom.find('[ng-repeat]:eq(1)');
996+
li2 = elementTop.find('[ng-repeat]:eq(1)');
997+
updateCallbackExpectations = function(uiItemSortable) {
998+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsTop);
999+
};
1000+
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -11 });
1001+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
1002+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
1003+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
1004+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
1005+
updateCallbackExpectations = undefined;
1006+
1007+
li1 = elementTop.find('[ng-repeat]:eq(0)');
1008+
li2 = elementBottom.find('[ng-repeat]:eq(0)');
1009+
updateCallbackExpectations = function(uiItemSortable) {
1010+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsBottom);
1011+
};
1012+
simulateElementDrag(li1, li2, 'below');
1013+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
1014+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
1015+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
1016+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
1017+
updateCallbackExpectations = undefined;
1018+
1019+
li1 = elementBottom.find('[ng-repeat]:eq(1)');
1020+
li2 = elementTop.find('[ng-repeat]:eq(1)');
1021+
updateCallbackExpectations = function(uiItemSortable) {
1022+
expect(uiItemSortable.droptargetModel).toBe($rootScope.itemsTop);
1023+
};
1024+
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -11 });
1025+
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
1026+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
1027+
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
1028+
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
1029+
updateCallbackExpectations = undefined;
1030+
1031+
$(elementTop).remove();
1032+
$(elementBottom).remove();
1033+
});
1034+
});
1035+
9501036
it('should properly set ui.item.sortable.droptargetModel when sorting between different scopes', function() {
9511037
inject(function($compile, $rootScope) {
9521038
var elementTop, elementBottom,

0 commit comments

Comments
 (0)