Skip to content

Commit

Permalink
fix(anchorScroll): find offset of nested elements correctly
Browse files Browse the repository at this point in the history
Closes #618
  • Loading branch information
ajoslin committed Feb 17, 2014
1 parent 9bc928f commit 17cc040
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 49 deletions.
12 changes: 3 additions & 9 deletions js/utils/dom.js
Expand Up @@ -17,16 +17,10 @@
* until we are at the direct child of parentEl
* use-case: find scroll offset of any element within a scroll container
*/
getPositionInParent: function(el, parentEl) {
var left = 0, top = 0;
while (el && el !== parentEl) {
left += el.offsetLeft;
top += el.offsetTop;
el = el.parentNode;
}
getPositionInParent: function(el) {
return {
left: left,
top: top
left: el.offsetLeft,
top: el.offsetTop
};
},

Expand Down
40 changes: 0 additions & 40 deletions test/js/utils/dom.js

This file was deleted.

10 changes: 10 additions & 0 deletions test/js/utils/dom.unit.js
@@ -0,0 +1,10 @@

describe('js/utils/dom', function() {

describe('getPositionInParent', function() {
it('should return el.{offsetLeft,offsetTop}', function() {
var el = { offsetLeft: 3, offsetTop: 4 };
expect(ionic.DomUtil.getPositionInParent(el)).toEqual({ left: 3, top: 4 });
});
});
});

0 comments on commit 17cc040

Please sign in to comment.