|
191 | 191 | ReorderDrag.prototype = new DragOp(); |
192 | 192 |
|
193 | 193 | ReorderDrag.prototype._moveElement = function(e) { |
194 | | - var y = e.gesture.center.pageY - |
195 | | - this._currentDrag.elementHeight + |
| 194 | + var y = e.gesture.center.pageY + |
196 | 195 | this.scrollView.getValues().top - |
| 196 | + this.scrollView.__container.offsetTop - |
| 197 | + (this._currentDrag.elementHeight / 2) - |
197 | 198 | this.listEl.offsetTop; |
198 | 199 | this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, '+y+'px, 0)'; |
199 | 200 | }; |
|
223 | 224 |
|
224 | 225 | ReorderDrag.prototype.drag = ionic.animationFrameThrottle(function(e) { |
225 | 226 | // We really aren't dragging |
| 227 | + var self = this; |
226 | 228 | if(!this._currentDrag) { |
227 | 229 | return; |
228 | 230 | } |
229 | 231 |
|
230 | 232 | var scrollY = 0; |
231 | 233 | var pageY = e.gesture.center.pageY; |
| 234 | + var offset = this.listEl.offsetTop + this.scrollView.__container.offsetTop; |
232 | 235 |
|
233 | 236 | //If we have a scrollView, check scroll boundaries for dragged element and scroll if necessary |
234 | 237 | if (this.scrollView) { |
235 | | - var container = this.scrollEl; |
236 | 238 |
|
| 239 | + var container = this.scrollView.__container; |
237 | 240 | scrollY = this.scrollView.getValues().top; |
238 | 241 |
|
239 | 242 | var containerTop = container.offsetTop; |
|
242 | 245 |
|
243 | 246 | if (e.gesture.deltaY < 0 && pixelsPastTop > 0 && scrollY > 0) { |
244 | 247 | this.scrollView.scrollBy(null, -pixelsPastTop); |
| 248 | + //Trigger another drag so the scrolling keeps going |
| 249 | + setTimeout(function() { |
| 250 | + self.drag(e); |
| 251 | + }.bind(this)); |
245 | 252 | } |
246 | 253 | if (e.gesture.deltaY > 0 && pixelsPastBottom > 0) { |
247 | 254 | if (scrollY < this.scrollView.getScrollMax().top) { |
248 | 255 | this.scrollView.scrollBy(null, pixelsPastBottom); |
| 256 | + //Trigger another drag so the scrolling keeps going |
| 257 | + setTimeout(function() { |
| 258 | + self.drag(e); |
| 259 | + }.bind(this)); |
249 | 260 | } |
250 | 261 | } |
251 | 262 | } |
|
259 | 270 | if(this._isDragging) { |
260 | 271 | this._moveElement(e); |
261 | 272 |
|
262 | | - this._currentDrag.currentY = scrollY + pageY - this._currentDrag.placeholder.parentNode.offsetTop; |
| 273 | + this._currentDrag.currentY = scrollY + pageY - offset; |
263 | 274 |
|
264 | 275 | this._reorderItems(); |
265 | 276 | } |
|
279 | 290 | var bottomSibling = siblings[Math.min(siblings.length, index+1)]; |
280 | 291 | var thisOffsetTop = this._currentDrag.currentY;// + this._currentDrag.startOffsetTop; |
281 | 292 |
|
282 | | - if(topSibling && (thisOffsetTop < topSibling.offsetTop + topSibling.offsetHeight/2)) { |
| 293 | + if(topSibling && (thisOffsetTop < topSibling.offsetTop + topSibling.offsetHeight)) { |
283 | 294 | ionic.DomUtil.swapNodes(this._currentDrag.placeholder, topSibling); |
284 | 295 | return index - 1; |
285 | | - } else if(bottomSibling && thisOffsetTop > (bottomSibling.offsetTop + bottomSibling.offsetHeight/2)) { |
| 296 | + } else if(bottomSibling && thisOffsetTop > (bottomSibling.offsetTop)) { |
286 | 297 | ionic.DomUtil.swapNodes(bottomSibling, this._currentDrag.placeholder); |
287 | 298 | return index + 1; |
288 | 299 | } |
| 300 | + |
289 | 301 | }; |
290 | 302 |
|
291 | 303 | ReorderDrag.prototype.end = function(e, doneCallback) { |
|
0 commit comments