|
16 | 16 | drag: function(e) {
|
17 | 17 | },
|
18 | 18 | end: function(e) {
|
| 19 | + }, |
| 20 | + isSameItem: function(item) { |
| 21 | + return false; |
19 | 22 | }
|
20 | 23 | };
|
21 | 24 |
|
|
27 | 30 | };
|
28 | 31 |
|
29 | 32 | SlideDrag.prototype = new DragOp();
|
| 33 | + |
30 | 34 | SlideDrag.prototype.start = function(e) {
|
31 | 35 | var content, buttons, offsetX, buttonsWidth;
|
32 | 36 |
|
|
64 | 68 | };
|
65 | 69 | };
|
66 | 70 |
|
| 71 | + /** |
| 72 | + * Check if this is the same item that was previously dragged. |
| 73 | + */ |
| 74 | + SlideDrag.prototype.isSameItem = function(op) { |
| 75 | + if(op._lastDrag && this._currentDrag) { |
| 76 | + return this._currentDrag.content == op._lastDrag.content; |
| 77 | + } |
| 78 | + return false; |
| 79 | + }; |
| 80 | + |
| 81 | + SlideDrag.prototype.clean = function(e) { |
| 82 | + var lastDrag = this._lastDrag; |
| 83 | + |
| 84 | + if(!lastDrag) return; |
| 85 | + |
| 86 | + ionic.requestAnimationFrame(function() { |
| 87 | + lastDrag.content.style[ionic.CSS.TRANSITION] = ''; |
| 88 | + lastDrag.content.style[ionic.CSS.TRANSFORM] = 'translate3d(0, 0, 0)'; |
| 89 | + }); |
| 90 | + }; |
| 91 | + |
67 | 92 | SlideDrag.prototype.drag = ionic.animationFrameThrottle(function(e) {
|
68 | 93 | var buttonsWidth;
|
69 | 94 |
|
|
124 | 149 |
|
125 | 150 | }
|
126 | 151 |
|
127 |
| - // var content = this._currentDrag.content; |
128 |
| - |
129 |
| - // var onRestingAnimationEnd = function(e) { |
130 |
| - // if(e.propertyName == '-webkit-transform') { |
131 |
| - // if(content) content.classList.remove(ITEM_SLIDING_CLASS); |
132 |
| - // } |
133 |
| - // e.target.removeEventListener('webkitTransitionEnd', onRestingAnimationEnd); |
134 |
| - // }; |
135 |
| - |
136 | 152 | ionic.requestAnimationFrame(function() {
|
137 |
| - // var currentX = parseFloat(_this._currentDrag.content.style[ionic.CSS.TRANSFORM].replace('translate3d(', '').split(',')[0]) || 0; |
138 |
| - // if(currentX !== restingPoint) { |
139 |
| - // _this._currentDrag.content.classList.add(ITEM_SLIDING_CLASS); |
140 |
| - // _this._currentDrag.content.addEventListener('webkitTransitionEnd', onRestingAnimationEnd); |
141 |
| - // } |
142 | 153 | if(restingPoint === 0) {
|
143 | 154 | _this._currentDrag.content.style[ionic.CSS.TRANSFORM] = '';
|
144 | 155 | } else {
|
|
148 | 159 |
|
149 | 160 |
|
150 | 161 | // Kill the current drag
|
| 162 | + _this._lastDrag = _this._currentDrag; |
151 | 163 | _this._currentDrag = null;
|
152 | 164 |
|
153 |
| - |
154 | 165 | // We are done, notify caller
|
155 | 166 | doneCallback && doneCallback();
|
156 | 167 | });
|
|
396 | 407 | }
|
397 | 408 | },
|
398 | 409 |
|
| 410 | + /** |
| 411 | + * Clear any active drag effects on the list. |
| 412 | + */ |
| 413 | + clearDragEffects: function() { |
| 414 | + if(this._lastDragOp) { |
| 415 | + this._lastDragOp.clean && this._lastDragOp.clean(); |
| 416 | + this._lastDragOp = null; |
| 417 | + } |
| 418 | + }, |
| 419 | + |
399 | 420 | _initDrag: function() {
|
400 | 421 | //ionic.views.ListView.__super__._initDrag.call(this);
|
401 | 422 |
|
402 |
| - //this._isDragging = false; |
| 423 | + // Store the last one |
| 424 | + this._lastDragOp = this._dragOp; |
| 425 | + |
403 | 426 | this._dragOp = null;
|
404 | 427 | },
|
405 | 428 |
|
|
418 | 441 | _startDrag: function(e) {
|
419 | 442 | var _this = this;
|
420 | 443 |
|
| 444 | + var didStart = false; |
| 445 | + |
421 | 446 | this._isDragging = false;
|
422 | 447 |
|
| 448 | + var lastDragOp = this._lastDragOp; |
| 449 | + |
423 | 450 | // Check if this is a reorder drag
|
424 | 451 | if(ionic.DomUtil.getParentOrSelfWithClass(e.target, ITEM_DRAG_CLASS) && (e.gesture.direction == 'up' || e.gesture.direction == 'down')) {
|
425 | 452 | var item = this._getItem(e.target);
|
|
435 | 462 | });
|
436 | 463 | this._dragOp.start(e);
|
437 | 464 | e.preventDefault();
|
438 |
| - return; |
439 | 465 | }
|
440 | 466 | }
|
441 | 467 |
|
|
448 | 474 | this._dragOp = new SlideDrag({ el: this.el });
|
449 | 475 | this._dragOp.start(e);
|
450 | 476 | e.preventDefault();
|
451 |
| - return; |
452 | 477 | }
|
453 | 478 | }
|
454 | 479 |
|
455 |
| - // We aren't handling it, so pass it up the chain |
456 |
| - //ionic.views.ListView.__super__._startDrag.call(this, e); |
| 480 | + // If we had a last drag operation and this is a new one on a different item, clean that last one |
| 481 | + if(lastDragOp && this._dragOp && !this._dragOp.isSameItem(lastDragOp) && e.defaultPrevented) { |
| 482 | + lastDragOp.clean && lastDragOp.clean(); |
| 483 | + } |
457 | 484 | },
|
458 | 485 |
|
459 | 486 |
|
|
0 commit comments