Skip to content

Commit

Permalink
fix(listView): position dragged list item properly when list view's p…
Browse files Browse the repository at this point in the history
…arent is offset. Closes #1583
  • Loading branch information
perrygovier committed Jun 6, 2014
1 parent 40392c0 commit afdf0ad
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions js/views/listView.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,24 @@
this.el = opts.el;
this.scrollEl = opts.scrollEl;
this.scrollView = opts.scrollView;
// Get the True Top of the list el http://www.quirksmode.org/js/findpos.html
this.listEl.trueTop = 0;
if (this.listEl.offsetParent) {
var obj = this.listEl;
do {
this.listEl.trueTop += obj.offsetTop;
obj = obj.offsetParent;
} while (obj);
}
};

ReorderDrag.prototype = new DragOp();

ReorderDrag.prototype._moveElement = function(e) {
var y = e.gesture.center.pageY +
this.scrollView.getValues().top -
this.scrollView.__container.offsetTop -
(this._currentDrag.elementHeight / 2) -
this.listEl.offsetTop;
this.listEl.trueTop;
this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, '+y+'px, 0)';
};

Expand Down Expand Up @@ -231,7 +239,7 @@

var scrollY = 0;
var pageY = e.gesture.center.pageY;
var offset = this.listEl.offsetTop + this.scrollView.__container.offsetTop;
var offset = this.listEl.trueTop;

//If we have a scrollView, check scroll boundaries for dragged element and scroll if necessary
if (this.scrollView) {
Expand Down

2 comments on commit afdf0ad

@ajoslin
Copy link
Contributor

@ajoslin ajoslin commented on afdf0ad Jun 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful with putting new properties directly on elements. It has been known to cause memory leaks.

Instead just put true top somewhere else on this.

Looks fine otherwise! 👍

@perrygovier
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed that d779346

Please sign in to comment.