|
1 | 1 | // |
2 | 2 | // Copyright Kamil Pękala http://github.com/kamilkp |
3 | | -// angular-sortable-view v0.0.10 2014/09/19 |
| 3 | +// angular-sortable-view v0.0.11 2014/11/28 |
4 | 4 | // |
5 | 5 |
|
6 | 6 | ;(function(window, angular){ |
|
37 | 37 | var $helper; // helper element - the one thats being dragged around with the mouse pointer |
38 | 38 | var $original; // original element |
39 | 39 | var $target; // last best candidate |
40 | | - var svOriginalNextSibling; // original element's original next sibling node |
41 | 40 | var isGrid = false; |
42 | 41 | var onSort = $parse($attrs.svOnSort); |
43 | 42 |
|
|
120 | 119 | }); |
121 | 120 | } |
122 | 121 |
|
123 | | - svOriginalNextSibling = svOriginal[0].nextSibling; |
124 | 122 | svOriginal.after($placeholder); |
125 | | - |
126 | | - svOriginal[0].parentNode.removeChild(svOriginal[0]); |
127 | | - svOriginal.removeClass('sv-visibility-hidden'); |
| 123 | + svOriginal.addClass('ng-hide'); |
128 | 124 |
|
129 | 125 | // cache options, helper and original element reference |
130 | 126 | $original = svOriginal; |
|
137 | 133 | $index: originatingIndex, |
138 | 134 | $item: originatingPart.model(originatingPart.scope)[originatingIndex] |
139 | 135 | }); |
140 | | - if($scope.$root) |
141 | | - $scope.$root.$$phase || $scope.$apply(); |
| 136 | + $scope.$root && $scope.$root.$$phase || $scope.$apply(); |
142 | 137 | } |
143 | 138 |
|
144 | 139 | // ----- move the element |
|
244 | 239 | sortingInProgress = false; |
245 | 240 | $placeholder.remove(); |
246 | 241 | $helper.remove(); |
247 | | - svOriginalNextSibling.parentNode.insertBefore($original[0], svOriginalNextSibling); |
| 242 | + $original.removeClass('ng-hide'); |
248 | 243 |
|
249 | 244 | candidates = void 0; |
250 | 245 | $placeholder = void 0; |
|
364 | 359 | }); |
365 | 360 |
|
366 | 361 | var handle = $element; |
367 | | - handle.on('mousedown', onMousedown); |
| 362 | + handle.on('mousedown touchstart', onMousedown); |
368 | 363 | $scope.$watch('$ctrl.handle', function(customHandle){ |
369 | 364 | if(customHandle){ |
370 | | - handle.off('mousedown', onMousedown); |
| 365 | + handle.off('mousedown touchstart', onMousedown); |
371 | 366 | handle = customHandle; |
372 | | - handle.on('mousedown', onMousedown); |
| 367 | + handle.on('mousedown touchstart', onMousedown); |
373 | 368 | } |
374 | 369 | }); |
375 | 370 |
|
|
393 | 388 | var moveExecuted; |
394 | 389 |
|
395 | 390 | function onMousedown(e){ |
| 391 | + touchFix(e); |
| 392 | + |
396 | 393 | if($controllers[1].sortingInProgress()) return; |
397 | | - if(e.button != 0) return; |
| 394 | + if(e.button != 0 && e.type === 'mousedown') return; |
398 | 395 |
|
399 | 396 | moveExecuted = false; |
400 | 397 | var opts = $parse($attrs.svElement)($scope); |
|
435 | 432 | var targetLeft = coords.x; |
436 | 433 | var targetTop = coords.y; |
437 | 434 | var helperRect = clone[0].getBoundingClientRect(); |
| 435 | + |
438 | 436 | var body = document.body; |
439 | 437 |
|
440 | 438 | if(containmentRect){ |
|
456 | 454 | y: (e.clientY - clientRect.top)/clientRect.height |
457 | 455 | }; |
458 | 456 | html.addClass('sv-sorting-in-progress'); |
459 | | - html.on('mousemove', onMousemove).on('mouseup', function mouseup(e){ |
460 | | - html.off('mousemove', onMousemove); |
461 | | - html.off('mouseup', mouseup); |
| 457 | + html.on('mousemove touchmove', onMousemove).on('mouseup touchend touchcancel', function mouseup(e){ |
| 458 | + html.off('mousemove touchmove', onMousemove); |
| 459 | + html.off('mouseup touchend', mouseup); |
462 | 460 | html.removeClass('sv-sorting-in-progress'); |
463 | 461 | if(moveExecuted) |
464 | 462 | $controllers[0].$drop($scope.$index, opts); |
|
468 | 466 |
|
469 | 467 | // onMousemove(e); |
470 | 468 | function onMousemove(e){ |
| 469 | + touchFix(e); |
471 | 470 | if(!moveExecuted){ |
472 | 471 | $element.parent().prepend(clone); |
473 | 472 | moveExecuted = true; |
|
544 | 543 | '</style>' |
545 | 544 | ].join('')); |
546 | 545 |
|
| 546 | + function touchFix(e){ |
| 547 | + if(!('clientX' in e) && !('clientY' in e)){ |
| 548 | + e.clientX = e.touches[0].clientX; |
| 549 | + e.clientY = e.touches[0].clientY; |
| 550 | + e.preventDefault(); |
| 551 | + } |
| 552 | + } |
| 553 | + |
547 | 554 | function getPreviousSibling(element){ |
548 | 555 | element = element[0]; |
549 | 556 | if(element.previousElementSibling) |
|
0 commit comments