Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
filipkis committed Mar 15, 2019
1 parent 36efdec commit 9eb1771
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
2 changes: 2 additions & 0 deletions angular-legacy-sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
watchers = null;
sortable = null;
nextSibling = null;
removed = null;
}


Expand All @@ -171,6 +172,7 @@
onEnd: function (/**Event*/evt) {
_emitEvent(evt, removed);
scope.$apply();
removed = null;
},
onAdd: function (/**Event*/evt) {
_sync(evt);
Expand Down
2 changes: 1 addition & 1 deletion e2e/conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['./basic-drag-drop.e2e.js'],
specs: ['./basic-drag-drop.e2e.js', './nested-drag-drop.e2e.js'],
}
21 changes: 21 additions & 0 deletions e2e/nested-drag-drop.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
describe('nested drag and drop', () => {
it('should have correct model after moving between lists', () => {
browser.get('http://localhost:8080/nested.html')
browser.executeScript('$("#item2").simulate("drag-n-drop", { dragTarget: $("#item3"), interpolation: {stepWidth: 2, stepDelay: 30}});')
browser.sleep(1000)
element(by.id('main-list')).evaluate('$ctrl.lastDragged.name').then(function(value){
expect(value).toBe('item2');
})
browser.executeScript('$("#item3").simulate("drag-n-drop", { dragTarget: $("#subitem1"), interpolation: {stepWidth: 2, stepDelay: 30}});')
browser.sleep(1000)
element(by.id('main-list')).evaluate('$ctrl.lastDragged.name').then(function(value){
expect(value).toBe('item3');
})
browser.executeScript('$("#item1").simulate("drag-n-drop", { dragTarget: $("#item2"), interpolation: {stepWidth: 2, stepDelay: 30}});')
browser.sleep(1000)
element(by.id('main-list')).evaluate('$ctrl.lastDragged.name').then(function(value){
expect(value).toBe('item1');
})
})
})

18 changes: 18 additions & 0 deletions example/nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<head>
<script src="vendor/jquery.min.js"></script>
<script src="vendor/jquery.simulate.js"></script>
<script src="vendor/jquery.simulate.ext.js"></script>
<script src="vendor/jquery.simulate.drag-n-drop.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Sortable/1.6.0/Sortable.min.js"></script>
<script src="./angular-legacy-sortable.js"></script>

<script src="nestedApp.js"></script>
</head>

<body ng-app="nestedApp">
<nested-drag-and-drop-example></nested-drag-and-drop-example>
</body>
</html>
48 changes: 48 additions & 0 deletions example/nestedApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
angular.module('nestedApp', ['ng-sortable'])
.component('nestedDragAndDropExample', {
template: `<ul id='main-list' ng-sortable="$ctrl.sortableConf">
<li ng-repeat="item in $ctrl.items" >
<span id={{item.name}}> {{ item.name }} </span>
<div ng-if="item.items">
<ul class='nested-list' ng-sortable="$ctrl.nestedSortableConf">
<li ng-repeat="subitem in item.items" >
<span id={{subitem.name}}> {{ subitem.name }} </span>
</li>
</ul>
</div>
</li>
</ul>`,
controller: class ExampleAppController {
constructor() {
var _this = this;
this.items = [{
name: 'item1',
items: [
{
name: 'subitem1',
}
]
},
{
name: 'item2',
},
{
name: 'item3'
}]
this.onEnd = function(event) {
_this.lastDragged = event.model;
}

this.sortableConf = {
group: 'all',
forceFallback: true,
onEnd: this.onEnd
}
this.nestedSortableConf = {
group: 'all',
forceFallback: true,
onEnd: this.onEnd
}
}
},
})

0 comments on commit 9eb1771

Please sign in to comment.